info stringlengths 120 50k | question stringlengths 504 10.4k | avg@8_qwen3_4b_instruct_2507 float64 0 0.88 |
|---|---|---|
{"tests": "{\"inputs\": [\"5\\n1 2 3 2 1\\n\", \"3\\n10 6 8\\n\", \"7\\n1 2 1 2 1 2 1\\n\", \"7\\n1 2 1 2 1 3 1\\n\", \"5\\n1 1 4 2 2\\n\", \"6\\n1 3 4 3 5 4\\n\", \"1\\n1\\n\", \"7\\n6 2 2 6 5 7 7\\n\", \"7\\n2 4 1 2 3 1 2\\n\", \"7\\n2 1 2 1 2 2 1\\n\", \"7\\n5 2 4 2 4 1 1\\n\", \"6\\n3 2 1 7 3 7\\n\", \"100\\n82 51 ... | This is a harder version of the problem. In this version $n \le 500\,000$
The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the c... | 0 |
{"tests": "{\"inputs\": [\"3 5 1 3\\n1 1 2\\n2 2 3\\n3 3 3\\n4 1 1\\n10 1 3\\n\", \"2 3 2 1\\n1 1 2\\n2 1 2\\n4 1 2\\n\", \"5 11 1 5\\n1 1 5\\n2 2 2\\n3 1 1\\n4 3 3\\n5 3 3\\n6 1 1\\n7 4 4\\n8 4 5\\n10 1 3\\n11 5 5\\n13 1 5\\n\", \"4 6 4 2\\n2 2 2\\n3 3 3\\n4 1 1\\n10 1 4\\n11 2 3\\n12 2 4\\n\", \"7 5 7 6\\n1 4 5\\n2 7... | Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right.
Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ... | 0 |
{"tests": "{\"inputs\": [\"7 7 3\\n1 2\\n2 1\\n5 5\\n\", \"10 5 1\\n3 3\\n\", \"4 5 19\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n2 1\\n2 2\\n2 3\\n2 5\\n3 1\\n3 2\\n3 3\\n3 4\\n3 5\\n4 1\\n4 2\\n4 3\\n4 4\\n4 5\\n\", \"5 5 24\\n1 2\\n1 3\\n1 4\\n1 5\\n2 1\\n2 2\\n2 3\\n2 4\\n2 5\\n3 1\\n3 2\\n3 3\\n3 4\\n3 5\\n4 1\\n4 2\\n4 3\\n... | The capital of Berland looks like a rectangle of size n × m of the square blocks of same size.
Fire!
It is known that k + 1 blocks got caught on fire (k + 1 ≤ n·m). Those blocks are centers of ignition. Moreover positions of k of these centers are known and one of these stays unknown. All k + 1 positions are distinct... | 0 |
{"tests": "{\"inputs\": [\"1 7\\n0000000\\n\", \"2 5\\n0010010\\n0010010\\n\", \"3 5\\n0100001\\n1001001\\n1010011\\n\", \"10 0\\n0111010\\n1101111\\n1111011\\n0111010\\n1101011\\n1101011\\n1110111\\n1010010\\n1111111\\n0010010\\n\", \"10 10\\n0101111\\n0000000\\n1111011\\n1011011\\n1011011\\n1111011\\n0010010\\n101001... | Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer.
The poor boy was very upset because of that. He w... | 0 |
{"tests": "{\"inputs\": [\"abac\\n\", \"acccc\\n\", \"hannah\\n\", \"vux\\n\", \"evmo\\n\", \"nxccb\\n\", \"vyppyq\\n\", \"eaebyud\\n\", \"mcrpwaao\\n\", \"vdgcwgxbh\\n\", \"ittmcsvmoa\\n\", \"dasca\\n\", \"tifui\\n\"], \"outputs\": [\"3\\nL 2\\nR 2\\nR 7\\n\", \"3\\nL 2\\nR 2\\nR 9\\n\", \"3\\nL 2\\nR 2\\nR 11\\n\", \... | Ringo found a string $s$ of length $n$ in his yellow submarine. The string contains only lowercase letters from the English alphabet. As Ringo and his friends love palindromes, he would like to turn the string $s$ into a palindrome by applying two types of operations to the string.
The first operation allows him to c... | 0 |
{"tests": "{\"inputs\": [\"3\\n2 5 -3\\n\", \"2\\n3 6\\n\", \"2\\n0 1\\n\", \"3\\n0 1000000000 -1000000000\\n\", \"10\\n-35 77 72 -62 76 90 58 97 -74 94\\n\", \"20\\n14 8 6 -16 5 -9 0 11 -7 10 20 -6 -17 -13 -11 7 -2 9 -19 19\\n\", \"20\\n55 -14 -28 13 -67 -23 58 2 -87 92 -80 62 -44 86 18 97 -47 63 32 94\\n\", \"50\\n29... | The legend of the foundation of Vectorland talks of two integers $x$ and $y$. Centuries ago, the array king placed two markers at points $|x|$ and $|y|$ on the number line and conquered all the land in between (including the endpoints), which he declared to be Arrayland. Many years later, the vector king placed markers... | 0.5 |
{"tests": "{\"inputs\": [\"1 1\\n1\\n\", \"4 2\\n6 3 8 1\\n\", \"94 58\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 58 1 1 1 29 58 58 1 1 29 1 1 1 1 2 1 58 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 29 1 1 1 1 1 58 1 29 1 1 1 1 1 1 1 1 1 1 1 1 58 1 1 1 1 1 2 1 1 1\\n\", \"6 76\\n1 38 1 1 1 1\\n\", \"16 53\\n53 1... | Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $\frac{p}{s} = k$, where p is the product of all integers on the given array, s is their sum, and k is a given c... | 0.875 |
{"tests": "{\"inputs\": [\"3 4\\n\", \"3 5\\n\", \"42 1337\\n\", \"100000 200000\\n\", \"150000 200000\\n\", \"2 2\\n\", \"3 3\\n\", \"3 200000\\n\", \"200000 200000\\n\", \"20 20\\n\", \"2 3\\n\", \"1000 200000\\n\", \"2 10\\n\"], \"outputs\": [\"6\\n\", \"10\\n\", \"806066790\\n\", \"707899035\\n\", \"270223789\\n\",... | Your task is to calculate the number of arrays such that: each array contains $n$ elements; each element is an integer from $1$ to $m$; for each array, there is exactly one pair of equal elements; for each array $a$, there exists an index $i$ such that the array is strictly ascending before the $i$-th element and s... | 0 |
{"tests": "{\"inputs\": [\"4 3 2\\n1\\n2\\n3\\n4\\n\", \"2 1 1\\n1\\n2\\n\", \"7 5 20\\n26\\n27\\n28\\n29\\n30\\n31\\n32\\n\", \"10 10 1\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n\", \"10 1 10\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n\", \"1 999999 1000000\\n1000000000\\n\", \"5 5 6\\n999999999\\n999999998\\n9999999... | Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to... | 0 |
{"tests": "{\"inputs\": [\"1 0\\n\", \"2 1\\n\", \"4 0\\n\", \"2 0\\n\", \"3 0\\n\", \"4 1\\n\", \"4 2\\n\", \"6 3\\n\", \"34 17\\n\", \"50 1\\n\", \"55 0\\n\", \"3 1\\n\", \"6 0\\n\"], \"outputs\": [\"1 2\", \"3 2 1 4\\n\", \"2 7 4 6 1 3 5 8\\n\", \"1 2 3 4\", \"1 2 3 4 5 6\", \"2 1 3 4 5 6 7 8\", \"2 1 4 3 5 6 7 8\",... | A permutation p is an ordered group of numbers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p_1, p_2, ..., p_{n}.
Simon has a positive integer n and a non-negative integer k, such that 2k ≤ n. Help him find perm... | 0 |
{"tests": "{\"inputs\": [\"3\\n\", \"10\\n\", \"2\\n\", \"20\\n\", \"21\\n\", \"23\\n\", \"24\\n\", \"28\\n\", \"29\\n\", \"30\\n\", \"4\\n\", \"5\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"13\\n\", \"14\\n\", \"19\\n\"], \"outputs\": [\"7\\n\", \"39916801\\n\", \"3\\n\", \"232792561\\n\", \"232792561\\n\", \"5354228881\\n\... | We have an integer N.
Print an integer x between N and 10^{13} (inclusive) such that, for every integer y between 2 and N (inclusive), the remainder when x is divided by y is 1.
Under the constraints of this problem, there is always at least one such integer x.
-----Constraints-----
- All values in input are integers... | 0 |
{"tests": "{\"inputs\": [\"2\\n\", \"8\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"11\\n\", \"13\\n\", \"21\\n\", \"31\\n\", \"43\\n\"], \"outputs\": [\"-1\\n1 2\\n\", \"1 2\\n1 3\\n1 4\\n2 5\\n2 6\\n1 7\\n1 8\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n\", \"-1\\n1 2\\n1 3\\n\", \"-1\\n1 2\\n1 3\\n1 4\\n... | Mahmoud was trying to solve the vertex cover problem on trees. The problem statement is:
Given an undirected tree consisting of n nodes, find the minimum number of vertices that cover all the edges. Formally, we need to find a set of vertices such that for each edge (u, v) that belongs to the tree, either u is in the ... | 0 |
{"tests": "{\"inputs\": [\"5\\n1 2\\n2 1\\n5 10\\n10 9\\n19 1\\n\", \"5\\n1 2\\n2 1\\n5 10\\n10 9\\n20 1\\n\", \"4\\n10 4\\n15 1\\n19 3\\n20 1\\n\", \"35\\n1 7\\n3 11\\n6 12\\n7 6\\n8 5\\n9 11\\n15 3\\n16 10\\n22 2\\n23 3\\n25 7\\n27 3\\n34 5\\n35 10\\n37 3\\n39 4\\n40 5\\n41 1\\n44 1\\n47 7\\n48 11\\n50 6\\n52 5\\n57 ... | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x_1, x_2, ..., x_{n}. ... | 0 |
{"tests": "{\"inputs\": [\"6\\n1 2 2 1 5\\n2 1 1 1 1 1\\n\", \"7\\n1 1 2 3 1 4\\n3 3 1 1 1 2 3\\n\", \"2\\n1\\n2 2\\n\", \"3\\n1 1\\n2 2 2\\n\", \"4\\n1 2 1\\n1 2 3 4\\n\", \"4\\n1 2 3\\n4 1 2 4\\n\", \"5\\n1 2 1 4\\n1 1 1 2 2\\n\", \"3\\n1 2\\n2 1 1\\n\", \"4\\n1 1 1\\n3 1 3 1\\n\", \"4\\n1 1 2\\n4 1 4 1\\n\", \"4\\n1... | You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex v by c_{v}. Initially c_{v} = 0.
You have to color the tree into the given colors using the smallest possible number of steps. On each step you... | 0.5 |
{"tests": "{\"inputs\": [\"3 3 2\\n1 2\\n2 3\\n3 1\\n\", \"4 6 3\\n4 3\\n1 2\\n1 3\\n1 4\\n2 3\\n2 4\\n\", \"9 9 2\\n5 6\\n6 7\\n7 8\\n8 9\\n9 5\\n1 2\\n2 3\\n3 4\\n4 1\\n\", \"5 10 4\\n1 2\\n2 3\\n1 3\\n1 5\\n4 1\\n2 5\\n2 4\\n5 3\\n5 4\\n3 4\\n\", \"10 15 3\\n9 4\\n4 8\\n4 2\\n2 9\\n9 6\\n6 2\\n6 5\\n1 10\\n1 7\\n10 ... | You've got a undirected graph G, consisting of n nodes. We will consider the nodes of the graph indexed by integers from 1 to n. We know that each node of graph G is connected by edges with at least k other nodes of this graph. Your task is to find in the given graph a simple cycle of length of at least k + 1.
A simpl... | 0 |
{"tests": "{\"inputs\": [\"3\\n123456789\\n100000000\\n100123456\\n\", \"4\\n123456789\\n193456789\\n134567819\\n934567891\\n\", \"1\\n167038488\\n\", \"5\\n115830748\\n403459907\\n556271610\\n430358099\\n413961410\\n\", \"5\\n139127034\\n452751056\\n193432721\\n894001929\\n426470953\\n\", \"5\\n343216531\\n914073407\\... | There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.
There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for whi... | 0 |
{"tests": "{\"inputs\": [\"4\\na 3\\n2\\nb 1\\nc 1\\n\\nb 2\\n0\\n\\nb 1\\n1\\nb 2\\n\\nc 1\\n1\\nb 2\\n\", \"9\\ncodehorses 5\\n3\\nwebfrmk 6\\nmashadb 1\\nmashadb 2\\n\\ncommons 2\\n0\\n\\nmashadb 3\\n0\\n\\nwebfrmk 6\\n2\\nmashadb 3\\ncommons 2\\n\\nextra 4\\n1\\nextra 3\\n\\nextra 3\\n0\\n\\nextra 1\\n0\\n\\nmashad... | Polycarp is currently developing a project in Vaja language and using a popular dependency management system called Vamen. From Vamen's point of view both Vaja project and libraries are treated projects for simplicity.
A project in Vaja has its own uniqie non-empty name consisting of lowercase latin letters with lengt... | 0 |
{"tests": "{\"inputs\": [\"5\\n1 4\\n2 5\\n3 1\\n4 5\\n\", \"2\\n1 2\\n\", \"2\\n2 1\\n\", \"3\\n1 2\\n2 3\\n\", \"3\\n3 1\\n2 3\\n\", \"3\\n3 1\\n2 1\\n\", \"8\\n5 7\\n1 6\\n4 3\\n8 2\\n5 6\\n4 2\\n7 8\\n\", \"64\\n2 20\\n37 55\\n42 29\\n36 54\\n35 50\\n60 41\\n25 61\\n31 51\\n9 43\\n26 28\\n48 56\\n13 64\\n17 19\\n8 ... | Asya loves animals very much. Recently, she purchased $n$ kittens, enumerated them from $1$ and $n$ and then put them into the cage. The cage consists of one row of $n$ cells, enumerated with integers from $1$ to $n$ from left to right. Adjacent cells had a partially transparent partition wall between them, hence there... | 0 |
{"tests": "{\"inputs\": [\"1\\n0 1\\n\", \"3\\n0 1\\n0 2\\n0 -3\\n\", \"2\\n0 1\\n1 1\\n\", \"4\\n-10000000 1\\n10000000 1\\n-10000000 10000000\\n10000000 10000000\\n\", \"20\\n7571542 9868879\\n3634934 5986987\\n2297651 5538795\\n9701582 8250721\\n-2913168 4968483\\n8838674 5771883\\n-3348778 8326335\\n-577797 750161\... | There is a forest that we model as a plane and live $n$ rare animals. Animal number $i$ has its lair in the point $(x_{i}, y_{i})$. In order to protect them, a decision to build a nature reserve has been made.
The reserve must have a form of a circle containing all lairs. There is also a straight river flowing through... | 0 |
{"tests": "{\"inputs\": [\"2 1\\n1 2\\n1 2\\n\", \"3 3\\n3 1 2\\n1 2\\n3 1\\n3 2\\n\", \"5 2\\n3 1 5 4 2\\n5 2\\n5 4\\n\", \"5 11\\n5 1 3 4 2\\n5 1\\n5 2\\n1 5\\n2 1\\n1 2\\n1 4\\n2 5\\n1 3\\n5 4\\n5 3\\n3 1\\n\", \"10 23\\n6 9 8 10 4 3 7 1 5 2\\n7 2\\n3 2\\n2 4\\n2 3\\n7 5\\n6 4\\n10 7\\n7 1\\n6 8\\n6 2\\n8 10\\n3 5\\... | At the big break Nastya came to the school dining room. There are $n$ pupils in the school, numbered from $1$ to $n$. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue. Of course, it's a little bit sad for Nastya, but she is not going... | 0 |
{"tests": "{\"inputs\": [\"3 3\\n...\\n..#\\n...\\n\", \"4 2\\n..\\n..\\n..\\n..\\n\", \"4 5\\n#...#\\n#...#\\n###.#\\n###.#\\n\", \"6 4\\n####\\n####\\n....\\n####\\n####\\n####\\n\", \"4 6\\n######\\n######\\n......\\n######\\n\", \"6 4\\n##.#\\n##.#\\n##.#\\n##.#\\n##.#\\n##.#\\n\", \"4 6\\n##.###\\n##.###\\n##.###\... | On a certain meeting of a ruling party "A" minister Pavel suggested to improve the sewer system and to create a new pipe in the city.
The city is an n × m rectangular squared field. Each square of the field is either empty (then the pipe can go in it), or occupied (the pipe cannot go in such square). Empty squares are... | 0 |
{"tests": "{\"inputs\": [\"4\\n1\\n1\\n1\\n\", \"7\\n1\\n1\\n1\\n2\\n2\\n2\\n\", \"8\\n1\\n1\\n1\\n1\\n3\\n3\\n3\\n\", \"3\\n1\\n1\\n\", \"13\\n1\\n2\\n2\\n2\\n1\\n6\\n6\\n6\\n1\\n10\\n10\\n10\\n\", \"7\\n1\\n2\\n2\\n1\\n1\\n1\\n\", \"7\\n1\\n1\\n1\\n1\\n2\\n2\\n\", \"8\\n1\\n1\\n1\\n1\\n5\\n5\\n5\\n\", \"9\\n1\\n1\\n1... | Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.
Let... | 0.75 |
{"tests": "{\"inputs\": [\"3 2\\n1 2\\n2 3\\n\", \"3 3\\n1 2\\n2 3\\n3 1\\n\", \"3 1\\n1 3\\n\", \"1 0\\n\", \"4 5\\n1 3\\n4 3\\n2 3\\n2 4\\n1 4\\n\", \"4 6\\n3 4\\n2 3\\n2 1\\n1 3\\n1 4\\n4 2\\n\", \"7 4\\n3 4\\n3 5\\n5 7\\n2 5\\n\", \"5 3\\n1 2\\n2 3\\n1 3\\n\", \"3 1\\n1 2\\n\", \"4 1\\n3 2\\n\", \"2 1\\n1 2\\n\", \... | Ivan is a novice painter. He has $n$ dyes of different colors. He also knows exactly $m$ pairs of colors which harmonize with each other.
Ivan also enjoy playing chess. He has $5000$ rooks. He wants to take $k$ rooks, paint each of them in one of $n$ colors and then place this $k$ rooks on a chessboard of size $10^{9}... | 0 |
{"tests": "{\"inputs\": [\"7 2\\n1 2 1 1 3 5 1\\n3 5\\n\", \"3 3\\n1 3 2\\n1 2 3\\n\", \"5 0\\n4 3 1 2 3\\n\", \"10 3\\n1 3 5 6 12 9 8 10 13 15\\n2 4 9\\n\", \"20 5\\n19 4 11 10 7 18 7 10 12 13 14 15 16 17 22 26 29 23 30 22\\n2 9 11 12 14\\n\", \"50 15\\n1 2 3 5 9 10 14 15 17 16 18 19 21 23 22 27 27 36 26 23 23 32 27 3... | You are given an array of $n$ integers $a_1$, $a_2$, ..., $a_n$, and a set $b$ of $k$ distinct integers from $1$ to $n$.
In one operation, you may choose two integers $i$ and $x$ ($1 \le i \le n$, $x$ can be any integer) and assign $a_i := x$. This operation can be done only if $i$ does not belong to the set $b$.
Cal... | 0 |
{"tests": "{\"inputs\": [\"3 2\\n1 3 1\\n\", \"3 6\\n3 3 3\\n\", \"5 6\\n4 2 3 1 3\\n\", \"6 1\\n1 1 1 300 1 1\\n\", \"3 10\\n5 8 1\\n\", \"1 1\\n1\\n\", \"4 14\\n4 9 2 7\\n\", \"8 20\\n3 2 1 1 6 2 6 1\\n\", \"10 6\\n6 4 8 9 9 10 5 2 8 1\\n\", \"48 14\\n1 1 1 1 1 6 1 1 1 1 1 1 3 3 1 1 1 1 1 2 2 2 1 1 1 1 1 1 2 1 4 1 1 ... | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of... | 0.125 |
{"tests": "{\"inputs\": [\"6\\n010000\\n000001\\n\", \"10\\n1111100000\\n0000011111\\n\", \"8\\n10101010\\n01010101\\n\", \"10\\n1111100000\\n1111100001\\n\", \"12\\n011001010101\\n111001010101\\n\", \"9\\n111110000\\n111100000\\n\", \"5\\n10100\\n01010\\n\", \"10\\n1010111110\\n1011101101\\n\", \"3\\n000\\n000\\n\", \... | Naman has two binary strings $s$ and $t$ of length $n$ (a binary string is a string which only consists of the characters "0" and "1"). He wants to convert $s$ into $t$ using the following operation as few times as possible.
In one operation, he can choose any subsequence of $s$ and rotate it clockwise once.
For exam... | 0 |
{"tests": "{\"inputs\": [\"3 1 100 100\\n1 3 8\\n\", \"3 100 1 100\\n1 3 8\\n\", \"3 100 100 1\\n1 3 8\\n\", \"5 1 2 4\\n5 5 3 6 5\\n\", \"5 1 2 2\\n5 5 3 6 5\\n\", \"10 7 8 3\\n3 10 4 9 2 7 6 10 4 8\\n\", \"10 7122 8827 3205\\n452685204 144160553 743427456 403576146 888744473 313727757 22025193 886601085 576370788 787... | You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights.
You are allowed the following operations: put a brick on top of one p... | 0 |
{"tests": "{\"inputs\": [\"5\\n1 2 1 2 1\\n\", \"4\\n1 1 1 1\\n\", \"4\\n1 2 1 2\\n\", \"8\\n2 1 2 1 1 1 1 1\\n\", \"14\\n2 1 2 1 1 1 1 2 1 1 2 1 2 1\\n\", \"10\\n1 1 2 2 1 1 2 2 1 1\\n\", \"20\\n1 1 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 2 1\\n\", \"186\\n2 1 2 1 1 1 1 1 2 1 1 2 2 2 1 1 2 2 1 1 1 2 1 1 2 2 1 1 1 2 2 1 1 1 1 ... | Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the ne... | 0 |
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 5\\n\", \"3\\n1 2 4\\n\", \"3\\n1 20 22\\n\", \"10\\n109070199 215498062 361633800 406156967 452258663 530571268 670482660 704334662 841023955 967424642\\n\", \"30\\n61 65 67 71 73 75 77 79 129 131 135 137 139 141 267 520 521 522 524 526 1044 1053 6924600 32125372 105667932 109158... | Vasily the bear has got a sequence of positive integers a_1, a_2, ..., a_{n}. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum.
The beauty of the written out numbers b_1, b_2, ..., b_{k} is such maximum non-negative integer v, that numbe... | 0 |
{"tests": "{\"inputs\": [\"0\\n1\\n\", \"2\\n1\\n\", \"0\\n3\\n\", \"1\\n1\\n\", \"3\\n7\\n\", \"37\\n29\\n\", \"1\\n0\\n\", \"0\\n1\\n\", \"0\\n0\\n\", \"2\\n0\\n\", \"5\\n0\\n\", \"100\\n4\\n\"], \"outputs\": [\"2 1 \\n\", \"2 3 4 1 \\n\", \"4 3 2 1 \\n\", \"2 3 1 \\n\", \"8 9 10 11 7 6 5 4 3 2 1 \\n\", \"30 31 32 33... | Hiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through.
It is known that there were N stops, all on different integer heights between 1 and N kilometers (inclusive) above the sea level. On the first day they've traveled from the first stop to the se... | 0 |
{"tests": "{\"inputs\": [\"5 1 2\\n-2 1\\n2 1\\n3 -1\\n5 -1\\n7 -1\\n\", \"4 10 1\\n-20 1\\n-10 -1\\n0 1\\n10 -1\\n\", \"1 100000000 98765432\\n73740702 1\\n\", \"10 2 3\\n-1 -1\\n-4 1\\n-6 -1\\n1 1\\n10 -1\\n-8 -1\\n6 1\\n8 1\\n4 -1\\n-10 -1\\n\", \"3 100000000 100000000\\n-100000000 1\\n100000000 1\\n0 -1\\n\", \"9 2... | Gathering darkness shrouds the woods and the world. The moon sheds its light on the boat and the river.
"To curtain off the moonlight should be hardly possible; the shades present its mellow beauty and restful nature." Intonates Mino.
"See? The clouds are coming." Kanno gazes into the distance.
"That can't be better... | 0 |
{"tests": "{\"inputs\": [\"HHHH\\n\", \"HQHQH\\n\", \"HHQHHQH\\n\", \"HHQQHHQQHH\\n\", \"Q\\n\", \"HHHHHHHHHHQHHH\\n\", \"HHQHQQQHHH\\n\", \"QQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQHQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQ\\n\", \"QHQHHQQQQQQQQQQQHQQHQHQQQQQQHQHQQQQQQQQQQQHQQQQQQQHQQHQQHQQ... | The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ...
-----Input-----
The only line of the input is a string between 1 and 10^6 characters long.
-----Output-----
Output "Yes" or "No".
-----Examples-----
Input
HHHH
Output
Yes
Input
H... | 0 |
{"tests": "{\"inputs\": [\"(1?1)\\n1 0\\n\", \"(2?(1?2))\\n1 1\\n\", \"((1?(5?7))?((6?2)?7))\\n3 2\\n\", \"((1?(5?7))?((6?2)?7))\\n2 3\\n\", \"((4?3)?(((2?(4?((4?((2?(3?(7?3)))?(((((3?(6?2))?3)?(((((6?6)?(1?5))?((8?8)?1))?(5?((7?((6?((((3?8)?8)?(8?5))?7))?8))?((8?(2?8))?3))))?6))?(8?(7?5)))?8)))?((((7?(4?3))?4)?5)?((1?... | Ancient Egyptians are known to have understood difficult concepts in mathematics. The ancient Egyptian mathematician Ahmes liked to write a kind of arithmetic expressions on papyrus paper which he called as Ahmes arithmetic expression.
An Ahmes arithmetic expression can be defined as: "d" is an Ahmes arithmetic expr... | 0 |
{"tests": "{\"inputs\": [\"1 2\\nSP.-SS.S-S.S\\n\", \"4 9\\nPP.-PPPS-S.S\\nPSP-PPSP-.S.\\n.S.-S..P-SS.\\nP.S-P.PP-PSP\\n\", \"3 7\\n.S.-SSSP-..S\\nS..-.SPP-S.P\\n.S.-PPPP-PSP\\n\", \"5 6\\nPP.-PS.P-P..\\nPPS-SP..-P.P\\nP.P-....-S..\\nSPP-.P.S-.S.\\nSP.-S.PS-PPP\\n\", \"1 1\\n..S-PS..-.PP\\n\", \"2 2\\nPP.-S.SS-.S.\\nSS... | В самолёте есть n рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.
Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, ко... | 0 |
{"tests": "{\"inputs\": [\"11 3\\n\", \"5 2\\n\", \"2 2\\n\", \"3 2\\n\", \"6 2\\n\", \"999999 333334\\n\", \"9 3\\n\", \"365561 143151\\n\", \"950059 419028\\n\", \"20354 8642\\n\", \"18 6\\n\", \"10 2\\n\"], \"outputs\": [\"3 1 2 1 1 2 3 2 2 3 1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"1 1 2 2 1 2\\n\", \"-1\\n\", \"... | The Greatest Secret Ever consists of n words, indexed by positive integers from 1 to n. The secret needs dividing between k Keepers (let's index them by positive integers from 1 to k), the i-th Keeper gets a non-empty set of words with numbers from the set U_{i} = (u_{i}, 1, u_{i}, 2, ..., u_{i}, |U_{i}|). Here and bel... | 0 |
{"tests": "{\"inputs\": [\"4 4\\n1 2 3 4\\n\", \"5 2\\n3 2 4 1 3\\n\", \"5 4\\n3 2 4 3 5\\n\", \"4 3\\n5 6 7 8\\n\", \"5 6\\n3 7 2 1 2\\n\", \"9 5\\n5 8 7 3 10 1 4 6 3\\n\", \"2 1\\n7 2\\n\", \"56 97\\n96 81 39 97 2 75 85 17 9 90 2 31 32 10 42 87 71 100 39 81 2 38 90 81 96 7 57 23 2 25 5 62 22 61 47 94 63 83 91 51 8 93... | There are n piles of pebbles on the table, the i-th pile contains a_{i} pebbles. Your task is to paint each pebble using one of the k given colors so that for each color c and any two piles i and j the difference between the number of pebbles of color c in pile i and number of pebbles of color c in pile j is at most on... | 0 |
{"tests": "{\"inputs\": [\"4 3 4\\nH 2\\nV 2\\nV 3\\nV 1\\n\", \"7 6 5\\nH 4\\nV 3\\nV 5\\nH 2\\nV 1\\n\", \"2 2 1\\nV 1\\n\", \"2 2 1\\nH 1\\n\", \"2 2 2\\nV 1\\nH 1\\n\", \"2 2 2\\nH 1\\nV 1\\n\", \"10 10 10\\nV 6\\nH 8\\nV 4\\nV 8\\nH 2\\nH 5\\nV 9\\nH 7\\nH 3\\nV 7\\n\", \"5 15 10\\nH 8\\nH 9\\nV 1\\nH 2\\nH 6\\nH ... | Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm × h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.
In order not to waste time, he decided to practice t... | 0.375 |
{"tests": "{\"inputs\": [\"2 1 1 5\\n\", \"1 2 100 1\\n\", \"1 100 1 100\\n\", \"18 18 40 79\\n\", \"18 18 40 81\\n\", \"1 100 100 100\\n\", \"1 100 33 65\\n\", \"1 100 33 67\\n\", \"1 100 50 100\\n\", \"1 100 99 99\\n\", \"77 7 25 49\\n\", \"77 7 25 51\\n\"], \"outputs\": [\"1\\n\", \"101\\n\", \"199\\n\", \"40\\n\", ... | There are two 100-story buildings, called A and B. (In this problem, the ground floor is called the first floor.)
For each i = 1,\dots, 100, the i-th floor of A and that of B are connected by a corridor.
Also, for each i = 1,\dots, 99, there is a corridor that connects the (i+1)-th floor of A and the i-th floor of B.
Y... | 0 |
{"tests": "{\"inputs\": [\"ABRACADABRA\\n\", \"ABBBCBDB\\n\", \"AB\\n\", \"ABBCDEFB\\n\", \"THISISATEST\\n\", \"Z\\n\", \"ZZ\\n\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\\n\", \"ABACBCABACACB\\n\", \"LEHLLLLLLHAFGEGLLHAFDLHHLLLLLDGGEHGGHLLLLLLLLDFLCBLLEFLLCBLLCGLEDLGGLECLDGLEHLLLGELLLEGLLLLGDLLLDALD\\n\", \"THISISTHELASTTEST\\n\... | You will receive 5 points for solving this problem.
Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running in the opposite direction and aligned to the position of the fold. Using t... | 0 |
{"tests": "{\"inputs\": [\"6 7\\n1 2\\n2 3\\n3 4\\n4 6\\n6 5\\n4 4\\n3 6\\n4 2 7 3\\n1 10 2\\n3 8 2\\n5 1 0\\n6 5 4\\n3 7\\n5 2\\n\", \"1 1\\n1 1\\n1 2 498328473 730315543\\n1 267535146 337021959\\n1 340728578\\n1 82073826\\n\", \"1 1\\n1 1\\n2 1 709189476 658667824\\n1 511405192 843598992\\n1 638564514 680433292\\n1 5... | Thanks to the Doctor's help, the rebels managed to steal enough gold to launch a full-scale attack on the Empire! However, Darth Vader is looking for revenge and wants to take back his gold.
The rebels have hidden the gold in various bases throughout the galaxy. Darth Vader and the Empire are looking to send out their... | 0 |
{"tests": "{\"inputs\": [\"3 1 3\\n1 2 3\\n1 1\\n\", \"3 3 6\\n1 2 3\\n1 1\\n\", \"1 1 10000\\n10001\\n\", \"3 2 3\\n1 2 3\\n1 1\\n\", \"6 3 100\\n1 100 1 1 1 1\\n1 1 2 3 3\\n\", \"2 1 1\\n1 1\\n1\\n\", \"2 100000 1000000000000000000\\n1000000000 1000000000\\n1\\n\", \"3 3 2200000000\\n1000000000 1000000000 1000000000\... | You are given a rooted tree on $n$ vertices, its root is the vertex number $1$. The $i$-th vertex contains a number $w_i$. Split it into the minimum possible number of vertical paths in such a way that each path contains no more than $L$ vertices and the sum of integers $w_i$ on each path does not exceed $S$. Each vert... | 0 |
{"tests": "{\"inputs\": [\"4\\n4 4 4\\n\", \"5\\n2 3 5 5\\n\", \"2\\n2\\n\", \"10\\n2 10 8 7 8 8 10 9 10\\n\", \"3\\n3 3\\n\", \"4\\n3 3 4\\n\", \"5\\n4 4 4 5\\n\", \"6\\n3 3 6 6 6\\n\", \"7\\n7 3 4 6 6 7\\n\", \"8\\n3 7 7 8 8 7 8\\n\", \"9\\n2 9 7 6 9 7 8 9\\n\"], \"outputs\": [\"6\\n\", \"17\\n\", \"1\\n\", \"63\\n\"... | Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to a_{i} inclusive. No tickets are sold at the last station.
Let ρ_{i}, j be the minimum number of tickets one needs to buy in order to get from stations i to stat... | 0 |
{"tests": "{\"inputs\": [\"8\\n20 1000\\n32 37\\n40 1000\\n45 50\\n16 16\\n16 16\\n14 1000\\n2 1000\\n\", \"7\\n4 4\\n4 4\\n4 4\\n4 4\\n4 4\\n4 4\\n5 5\\n\", \"7\\n14000000003 1000000000000000000\\n81000000000 88000000000\\n5000000000 7000000000\\n15000000000 39000000000\\n46000000000 51000000000\\n0 1000000000\\n0 0\\... | One tradition of ACM-ICPC contests is that a team gets a balloon for every solved problem. We assume that the submission time doesn't matter and teams are sorted only by the number of balloons they have. It means that one's place is equal to the number of teams with more balloons, increased by 1. For example, if there ... | 0 |
{"tests": "{\"inputs\": [\"1\\n1\\n2\\n7\\n\", \"2\\n1 2\\n2 3\\n11\\n\", \"100\\n1 8 10 6 5 3 2 3 4 2 3 7 1 1 5 1 4 1 8 1 5 5 6 5 3 7 4 5 5 3 8 7 8 6 8 9 10 7 8 5 8 9 1 3 7 2 6 1 7 7 2 8 1 5 4 2 10 4 9 8 1 10 1 5 9 8 1 9 5 1 5 7 1 6 7 8 8 2 2 3 3 7 2 10 6 3 6 3 5 3 10 4 4 6 9 9 3 2 6 6\\n4 3 8 4 4 2 4 6 6 3 3 5 8 4 1 ... | Little Dima has two sequences of points with integer coordinates: sequence (a_1, 1), (a_2, 2), ..., (a_{n}, n) and sequence (b_1, 1), (b_2, 2), ..., (b_{n}, n).
Now Dima wants to count the number of distinct sequences of points of length 2·n that can be assembled from these sequences, such that the x-coordinates of po... | 0 |
{"tests": "{\"inputs\": [\"5\\n-3 -4 -2 -3 3\\n\", \"5\\n2 -3 -1 -4 3\\n\", \"6\\n94 65 -33 -43 60 -24\\n\", \"3\\n-10000 10000 -10000\\n\", \"2\\n0 0\\n\", \"7\\n-1 -2 -4 -10 6 6 5\\n\", \"10\\n-10 3 -16 -15 14 -16 13 -6 -8 18\\n\", \"50\\n-67 -84 -89 80 40 42 -38 30 74 -12 -66 27 1 11 -45 -44 2 -70 -59 -70 -59 -59 62... | The Physical education teacher at SESC is a sort of mathematician too. His most favorite topic in mathematics is progressions. That is why the teacher wants the students lined up in non-decreasing height form an arithmetic progression.
To achieve the goal, the gym teacher ordered a lot of magical buns from the dining ... | 0 |
{"tests": "{\"inputs\": [\"3 5\\n1 2 3\\n1 3 2 3 1\\n\", \"3 3\\n10 20 30\\n1 2 3\\n\", \"2 2\\n10 12\\n2 1\\n\", \"10 10\\n61 59 97 16 2 94 57 48 91 93\\n2 8 6 5 3 1 3 4 9 10\\n\", \"50 50\\n75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 ... | New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is w_{i}.
As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to rea... | 0 |
{"tests": "{\"inputs\": [\"5 6 1 1 3\\n2\\n5\\n3\\n1 1 5 6\\n1 3 5 4\\n3 3 5 3\\n\", \"2 2 0 1 1\\n\\n1\\n1\\n1 2 2 2\\n\", \"4 4 1 0 1\\n4\\n\\n5\\n1 1 2 2\\n1 3 2 2\\n3 3 4 3\\n3 2 2 2\\n1 2 2 3\\n\", \"10 10 1 8 4\\n10\\n2 3 4 5 6 7 8 9\\n10\\n1 1 3 1\\n2 1 7 1\\n1 1 9 1\\n7 1 4 1\\n10 1 7 1\\n2 1 7 1\\n3 1 2 1\\n5 ... | In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different fl... | 0 |
{"tests": "{\"inputs\": [\"3\\n7\\n4 6 11 11 15 18 20\\n4\\n10 10 10 11\\n3\\n1 1 1000000000\\n\", \"1\\n3\\n78788 78788 100000\\n\", \"1\\n3\\n78788 78788 157577\\n\", \"1\\n10\\n1 7 7 7 7 9 9 9 9 9\\n\", \"1\\n6\\n1 1 1 2 2 3\\n\", \"1\\n3\\n5623 5624 10000000\\n\", \"1\\n3\\n5739271 5739272 20000000\\n\", \"1\\n14\\... | You are given an array $a_1, a_2, \dots , a_n$, which is sorted in non-decreasing order ($a_i \le a_{i + 1})$.
Find three indices $i$, $j$, $k$ such that $1 \le i < j < k \le n$ and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to $a_i$, $a_j$ and $a_k$ (for... | 0 |
{"tests": "{\"inputs\": [\"4\\n1 2 4 5\\n\", \"6\\n62 22 60 61 48 49\\n\", \"2\\n1 4\\n\", \"2\\n5 4\\n\", \"10\\n9 6 8 5 5 2 8 9 2 2\\n\", \"10\\n7776 32915 1030 71664 7542 72359 65387 75222 95899 40333\\n\", \"10\\n1 1 1 1 1 1 1 1 1 1\\n\", \"4\\n15 11 28 17\\n\", \"3\\n1 36 6\\n\", \"6\\n3 12 4 12 5 6\\n\", \"6\\n7 ... | Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time!
Alice has a sheet with n notes written on it. She wants to take two such non-empty non-intersecting subsequences that both of them form a melody and sum of their lengths is maximal.
... | 0.25 |
{"tests": "{\"inputs\": [\"6 1\\n2 0 4 0 6 0\\n\", \"6 2\\n2 3 0 5 6 0\\n\", \"4 1\\n0 0 0 0\\n\", \"6 2\\n0 0 1 0 4 5\\n\", \"10 7\\n10 8 6 5 0 0 0 4 3 9\\n\", \"10 1\\n8 7 0 2 0 10 0 0 3 5\\n\", \"10 4\\n0 1 4 2 7 0 10 0 5 8\\n\", \"10 2\\n0 7 0 10 8 0 4 2 3 0\\n\", \"10 2\\n10 0 9 0 0 4 2 6 8 0\\n\", \"10 7\\n7 9 2 ... | In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native ... | 0 |
{"tests": "{\"inputs\": [\"5\\n1 5 8 123 7\\n123 7 5 1\\n5 1 7\\n\", \"6\\n1 4 3 3 5 7\\n3 7 5 4 3\\n4 3 7 5\\n\", \"3\\n1 2 3\\n3 2\\n2\\n\", \"10\\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784... | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix s... | 0 |
{"tests": "{\"inputs\": [\"4\\n4\\n1 2 4 2\\n2\\n5 3\\n3\\n1 3 1\\n3\\n0 0 0\\n\", \"5\\n4\\n5 3 1 5\\n1\\n3\\n3\\n5 5 1\\n3\\n2 3 0\\n1\\n5\\n\", \"5\\n9\\n2 0 2 3 1 3 1 4 5\\n5\\n5 4 7 9 7\\n5\\n8 1 3 3 7\\n3\\n9 6 1\\n3\\n6 8 2\\n\", \"5\\n4\\n3 5 2 4\\n9\\n5 4 5 6 4 2 0 1 0\\n3\\n1 1 2\\n7\\n4 6 0 5 5 5 6\\n1\\n1\\... | The length of the longest common prefix of two strings $s = s_1 s_2 \ldots s_n$ and $t = t_1 t_2 \ldots t_m$ is defined as the maximum integer $k$ ($0 \le k \le min(n,m)$) such that $s_1 s_2 \ldots s_k$ equals $t_1 t_2 \ldots t_k$.
Koa the Koala initially has $n+1$ strings $s_1, s_2, \dots, s_{n+1}$.
For each $i$ ($1... | 0 |
{"tests": "{\"inputs\": [\"4\\n1 2 2 1\\n\", \"5\\n1 3 2 2 5\\n\", \"1\\n1\\n\", \"10\\n1 1 1 1 1 1 1 1 1 1\\n\", \"10\\n1 9 7 6 2 4 7 8 1 3\\n\", \"100\\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54... | A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold:
a_{i} ≥ a_{i} - 1 for all even i, a_{i} ≤ a_{i} - 1 for all odd i > 1.
For example the arrays [1,2,1,2] and [1,1,1,1] are z-sorted while the array [1,2,3,4] isn’t z-sorted.
Can you make t... | 0 |
{"tests": "{\"inputs\": [\"3\\n10 6 15\\n\", \"3\\n2 4 6\\n\", \"7\\n30 60 21 42 70 15 30\\n\", \"10\\n91630 147840 12600 52206 270270 48510 16170 33495 25080 60060\\n\", \"30\\n13469 121221 107752 94283 107752 296318 67345 296318 161628 215504 121221 215504 296318 134690 282849 161628 148159 202035 242442 107752 80814... | Janusz is a businessman. He owns a company "Januszex", which produces games for teenagers. Last hit of Januszex was a cool one-person game "Make it one". The player is given a sequence of $n$ integers $a_i$.
It is allowed to select any subset of them, and the score is equal to the greatest common divisor of selected e... | 0 |
{"tests": "{\"inputs\": [\"4\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n3 13\\n3 14\\n4 7\\n4 8\\n5 9\\n5 10\\n6 11\\n6 12\\n\", \"2\\n1 2\\n\", \"3\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n\", \"4\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n3 7\\n4 8\\n4 9\\n5 12\\n5 13\\n7 10\\n7 11\\n1 14\\n\", \"4\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n3 7\\n4 8\\n4 9\\... | You have an integer $n$. Let's define following tree generation as McDic's generation: Make a complete and full binary tree of $2^{n} - 1$ vertices. Complete and full binary tree means a tree that exactly one vertex is a root, all leaves have the same depth (distance from the root), and all non-leaf nodes have exactly... | 0 |
{"tests": "{\"inputs\": [\"1 0\\n\", \"3 1\\n1 2\\n\", \"4 3\\n1 2\\n1 3\\n2 4\\n\", \"2 0\\n\", \"2 1\\n2 1\\n\", \"3 0\\n\", \"10 45\\n6 8\\n5 8\\n6 10\\n2 9\\n1 3\\n7 6\\n10 2\\n9 7\\n9 3\\n10 1\\n1 4\\n10 7\\n8 3\\n6 2\\n2 7\\n9 6\\n1 5\\n8 10\\n10 9\\n4 2\\n7 4\\n5 7\\n7 1\\n10 4\\n10 5\\n8 9\\n5 3\\n7 8\\n3 4\\n1... | Vasya had an array of $n$ integers, each element of the array was from $1$ to $n$. He chose $m$ pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote eithe... | 0 |
{"tests": "{\"inputs\": [\"3\\n2 2 2\\n\", \"5\\n1 4 1 1 1\\n\", \"3\\n1 1 1\\n\", \"3\\n1 1 2\\n\", \"4\\n2 1 2 1\\n\", \"5\\n1 2 1 1 2\\n\", \"5\\n1 1 1 3 1\\n\", \"100\\n1 5 1 1 1 2 3 2 1 4 2 2 1 2 1 2 2 2 2 1 1 2 2 2 2 2 2 1 2 2 2 1 1 1 2 2 1 1 2 3 2 2 3 1 2 4 2 1 2 1 2 4 2 1 2 3 1 3 1 2 2 1 2 2 3 1 1 1 5 2 2 2 3 3... | Graph constructive problems are back! This time the graph you are asked to build should match the following properties.
The graph is connected if and only if there exists a path between every pair of vertices.
The diameter (aka "longest shortest path") of a connected undirected graph is the maximum number of edges in... | 0 |
{"tests": "{\"inputs\": [\"1\\n\", \"3\\n\", \"10\\n\", \"9\\n\", \"13\\n\", \"20\\n\", \"2\\n\", \"4\\n\", \"37\\n\", \"22\\n\"], \"outputs\": [\"No\", \"Yes\\n1 2\\n2 1 3 \\n\", \"Yes\\n1 5\\n9 1 2 3 4 6 7 8 9 10 \\n\", \"Yes\\n1 5\\n8 1 2 3 4 6 7 8 9 \\n\", \"Yes\\n1 7\\n12 1 2 3 4 5 6 8 9 10 11 12 13 \\n\", \"Yes\\... | Find out if it is possible to partition the first $n$ positive integers into two non-empty disjoint sets $S_1$ and $S_2$ such that:$\mathrm{gcd}(\mathrm{sum}(S_1), \mathrm{sum}(S_2)) > 1$
Here $\mathrm{sum}(S)$ denotes the sum of all elements present in set $S$ and $\mathrm{gcd}$ means thegreatest common divisor.
Ev... | 0 |
{"tests": "{\"inputs\": [\"2\\n1 999\\n999 1\\n\", \"3\\n400 600\\n400 600\\n400 600\\n\", \"2\\n500 500\\n500 500\\n\", \"1\\n1 999\\n\", \"10\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n\", \"2\\n499 501\\n501 499\\n\", \"3\\n500 500\\n1 999\\n400 600\\n\", \"1\\n0 1000\\n\", \"1... | The Bitlandians are quite weird people. They have very peculiar customs.
As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work.
The kids are excited because just as is customary, they're going to be paid for the job!
Overall uncle J. h... | 0 |
{"tests": "{\"inputs\": [\"5\\n5 2 5 1 4\\n\", \"6\\n10 20 20 40 60 60\\n\", \"2\\n101 100\\n\", \"1\\n1000\\n\", \"2\\n1000000000 -1000000000\\n\", \"8\\n5 2 6 8 3 1 6 8\\n\", \"2\\n200000000 199999999\\n\", \"3\\n100000000 100000002 100000001\\n\", \"5\\n1000000000 -10000000 0 8888888 7777777\\n\", \"5\\n10 30 20 50 ... | In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.
Note that in this problem you do not have to minimize the number of sw... | 0 |
{"tests": "{\"inputs\": [\"3\\n\", \"4\\n\", \"1\\n\", \"2\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\"], \"outputs\": [\"2\\n1 2\\n2 3\\n\", \"8\\n1 2\\n3 4\\n1 3\\n2 4\\n1 2\\n3 4\\n1 3\\n2 4\\n\", \"0\\n\", \"2\\n1 2\\n1 2\\n\", \"8\\n1 2\\n3 4\\n1 3\\n2 4\\n2 3\\n4 5\\n2 4\\n3 5\\n\", \"8\\n1 2... | You are given an integer $n$.
You should find a list of pairs $(x_1, y_1)$, $(x_2, y_2)$, ..., $(x_q, y_q)$ ($1 \leq x_i, y_i \leq n$) satisfying the following condition.
Let's consider some function $f: \mathbb{N} \times \mathbb{N} \to \mathbb{N}$ (we define $\mathbb{N}$ as the set of positive integers). In other wo... | 0 |
{"tests": "{\"inputs\": [\"3 1 2\\n1\\n\", \"9 2 26\\n2 3\\n\", \"12 3 1\\n2 5 6\\n\", \"2 1 1\\n1\\n\", \"2 1 234\\n1\\n\", \"6 2 5\\n1 3\\n\", \"2 1 1000000000\\n1\\n\", \"1000000000 1 1\\n1\\n\", \"1000000000 2 2\\n1 500000000\\n\", \"8 1 8\\n2\\n\"], \"outputs\": [\"6\\n\", \"150352234\\n\", \"1\\n\", \"1\\n\", \"2... | Consider some set of distinct characters $A$ and some string $S$, consisting of exactly $n$ characters, where each character is present in $A$.
You are given an array of $m$ integers $b$ ($b_1 < b_2 < \dots < b_m$).
You are allowed to perform the following move on the string $S$:
Choose some valid $i$ and set $k ... | 0 |
{"tests": "{\"inputs\": [\"4\\n1 4 1 1\\n\", \"5\\n1 0 1 0 1\\n\", \"1\\n1000000000\\n\", \"4\\n3 3 3 3\\n\", \"4\\n3 3 2 3\\n\", \"16\\n1 1 2 3 3 4 5 6 6 6 4 3 2 1 1 1\\n\", \"1\\n1\\n\", \"20\\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2\\n\", \"1\\n0\\n\", \"2\\n0 1\\n\"], \"outputs\": [\"2\\n\", \"3\\n\", \"1\\n\", \"3... | You have a multiset containing several integers. Initially, it contains $a_1$ elements equal to $1$, $a_2$ elements equal to $2$, ..., $a_n$ elements equal to $n$.
You may apply two types of operations: choose two integers $l$ and $r$ ($l \le r$), then remove one occurrence of $l$, one occurrence of $l + 1$, ..., one... | 0 |
{"tests": "{\"inputs\": [\"7 10\\n\", \"5 1\\n\", \"7 1000\\n\", \"11 1000000000\\n\", \"999999937 1\\n\", \"999999929 2\\n\", \"999999929 1000000000\\n\", \"603530531 585244\\n\", \"7369339 31415926\\n\", \"2341 5001\\n\"], \"outputs\": [\"108.395919545675\", \"1.122569941449\", \"1083959.195456745256\", \"10616899777... | It was decided in IT City to distinguish successes of local IT companies by awards in the form of stars covered with gold from one side. To order the stars it is necessary to estimate order cost that depends on the area of gold-plating. Write a program that can calculate the area of a star.
A "star" figure having n ≥ ... | 0 |
{"tests": "{\"inputs\": [\"4 4\\n1 2 1\\n2 3 1\\n3 4 1\\n\", \"4 6\\n1 2 0\\n1 3 0\\n1 4 0\\n\", \"3 5\\n1 2 1\\n2 3 0\\n\", \"13 3\\n9 13 1\\n8 3 1\\n11 9 0\\n8 13 0\\n10 9 0\\n2 7 0\\n4 8 1\\n11 5 0\\n10 12 0\\n12 1 1\\n5 7 0\\n6 8 1\\n\", \"4 19\\n2 4 1\\n2 3 0\\n1 4 0\\n\", \"7 12\\n4 5 0\\n2 7 1\\n7 6 1\\n2 5 0\\n... | You are given a tree (a connected undirected graph without cycles) of $n$ vertices. Each of the $n - 1$ edges of the tree is colored in either black or red.
You are also given an integer $k$. Consider sequences of $k$ vertices. Let's call a sequence $[a_1, a_2, \ldots, a_k]$ good if it satisfies the following criterio... | 0.875 |
{"tests": "{\"inputs\": [\"4 3\\n2 14 3 4\\n\", \"5 2\\n0 2 1 255 254\\n\", \"10 3\\n112 184 161 156 118 231 191 128 91 229\\n\", \"9 3\\n174 149 118 124 166 146 219 233 107\\n\", \"8 4\\n180 195 13 195 61 24 132 160\\n\", \"1 4\\n51\\n\", \"2 4\\n218 213\\n\", \"3 3\\n212 167 3\\n\", \"100 7\\n39 242 238 155 95 30 129... | Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.
Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref... | 0 |
{"tests": "{\"inputs\": [\"5\\n0 0 0 0 1\\n0 1 2 3 4\\n\", \"5\\n0 0 1 0 1\\n0 1 2 2 4\\n\", \"4\\n1 0 0 0\\n2 3 4 2\\n\", \"10\\n0 0 0 0 0 0 0 0 0 1\\n4 0 8 4 7 8 5 5 7 2\\n\", \"50\\n0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0\\n28 4 33 22 4 35 36 31 42 25 50 33... | Valera's finally decided to go on holiday! He packed up and headed for a ski resort.
Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has n objects (we will consider the objects indexed in some way by integers from 1 to n), each obje... | 0 |
{"tests": "{\"inputs\": [\"6 8 16\\n3 5 2 9 8 7\\n\", \"4 20 32\\n21 11 11 12\\n\", \"4 11 32\\n5 5 16 16\\n\", \"5 12 20\\n7 8 4 11 9\\n\", \"2 1 1\\n1 1\\n\", \"2 1 1\\n1 1000000\\n\", \"2 1 1\\n1000000000 1000000000\\n\", \"2 1 2\\n1 1\\n\", \"15 250 200\\n71 2 77 69 100 53 54 40 73 32 82 58 24 82 41\\n\", \"4 12 11... | 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 ... | 0 |
{"tests": "{\"inputs\": [\"5\\n9 3 5 7 3\\n5 8 1 4 5\\n\", \"3\\n1 2 9\\n10 1 1\\n\", \"1\\n7\\n4\\n\", \"5\\n3 10 9 10 6\\n4 3 3 6 9\\n\", \"1\\n5\\n8\\n\", \"1\\n5\\n1\\n\", \"5\\n1 7 6 9 1\\n6 1 1 7 10\\n\", \"5\\n7 3 3 1 8\\n7 2 1 1 2\\n\", \"100\\n4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1... | Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in... | 0.375 |
{"tests": "{\"inputs\": [\"1000 1000000\\n\", \"1000 0\\n\", \"1000 1\\n\", \"1000 2\\n\", \"10000 3\\n\", \"10000 2000000000\\n\", \"4907 244618708\\n\", \"9030 982505993\\n\", \"4054 287739817\\n\", \"1587 1941728048\\n\"], \"outputs\": [\"1011.060722383550382782399454922040\\n\", \"1000\\n\", \"1000.000011000\\n\", ... | The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time.
Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately ev... | 0 |
{"tests": "{\"inputs\": [\"3 5\\n..+.#\\n#+..+\\n+.#+.\\n\", \"4 10\\n...+.##+.+\\n+#++..+++#\\n++.#++++..\\n.+##.++#.+\\n\", \"2 2\\n..\\n++\\n\", \"5 1\\n.\\n.\\n.\\n.\\n.\\n\", \"20 20\\n..+#+.+++.+++#+..#++\\n..####+++#..++#+.+.+\\n+.+..+++..#.++++++++\\n+##++..+.##..#+++.++\\n++.+.+.+.++++.+++.++\\n.+++++.+#+++++.... | Joe has been hurt on the Internet. Now he is storming around the house, destroying everything in his path.
Joe's house has n floors, each floor is a segment of m cells. Each cell either contains nothing (it is an empty cell), or has a brick or a concrete wall (always something one of three). It is believed that each f... | 0 |
{"tests": "{\"inputs\": [\"4 2 5\\n1 2 3 1\\n\", \"1 9 10\\n1\\n\", \"3 2 10\\n1 2 1\\n\", \"1 10 10\\n1\\n\", \"1 1000000000 1000000000\\n100000\\n\", \"2 4 1\\n1 1\\n\", \"5 3 2\\n1 1 2 1 1\\n\", \"5 3 3\\n1 2 2 1 1\\n\", \"10 5 1000000000\\n1 1 1 2 2 1 2 2 2 2\\n\", \"5 2 4\\n1 2 3 2 1\\n\"], \"outputs\": [\"12\\n\"... | This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city a_{i}.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned ... | 0 |
{"tests": "{\"inputs\": [\"snow affects sports such as skiing, snowboarding, and snowmachine travel.\\nsnowboarding is a recreational activity and olympic and paralympic sport.\\n\", \"'co-co-co, codeforces?!'\\n\", \"thun-thun-thunder, thunder, thunder\\nthunder, thun-, thunder\\nthun-thun-thunder, thunder\\nthunder, ... | 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... | 0 |
{"tests": "{\"inputs\": [\"5\\n2 1 6\\n0 4 1\\n2 -1 3\\n1 -2 1\\n4 -1 1\\n\", \"8\\n0 0 1\\n0 0 2\\n0 0 3\\n0 0 4\\n0 0 5\\n0 0 6\\n0 0 7\\n0 0 8\\n\", \"4\\n1000000 -1000000 2\\n1000000 -1000000 3\\n-1000000 1000000 2\\n-1000000 1000000 1000000\\n\", \"15\\n-848 0 848\\n-758 0 758\\n-442 0 442\\n-372 0 372\\n-358 0 35... | The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it?
The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which i... | 0 |
{"tests": "{\"inputs\": [\"3 3\\n1 2 1\\n1 2\\n2 3\\n1 3\\n\", \"3 2\\n1 1 0\\n1 2\\n1 3\\n\", \"4 4\\n1 2 0 1\\n1 3\\n1 2\\n2 3\\n2 4\\n\", \"5 5\\n1 1 1 2 1\\n3 4\\n1 2\\n2 3\\n4 5\\n4 5\\n\", \"4 10\\n2 4 1 4\\n3 2\\n4 2\\n4 1\\n3 1\\n4 1\\n1 3\\n3 2\\n2 1\\n3 1\\n2 4\\n\", \"6 27\\n4 2 10 1 3 10\\n1 2\\n5 2\\n6 3\\... | Lee bought some food for dinner time, but Lee's friends eat dinner in a deadly way. Lee is so scared, he doesn't want to die, at least not before seeing Online IOI 2020...
There are $n$ different types of food and $m$ Lee's best friends. Lee has $w_i$ plates of the $i$-th type of food and each friend has two different... | 0 |
{"tests": "{\"inputs\": [\"10 32\\n1 2 3 4 5 5 5 5 5 5\\n\", \"5 8\\n4 4 8 2 1\\n\", \"5 353\\n191 148 145 73 150\\n\", \"100 12436\\n827 238 69 955 468 828 762 562 285 690 406 39 814 447 871 560 224 677 65 764 864 827 659 43 512 547 619 313 206 605 446 471 980 115 561 746 150 787 963 426 239 984 752 212 732 977 831 52... | Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)
You have completed many programming projects. In fact, there are exactly $n$ types of programming projects, and you ... | 0 |
{"tests": "{\"inputs\": [\"5 3\\n1 1 5 5\\n1 2\\n4 1\\n3 3\\n\", \"84 5\\n67 59 41 2\\n39 56\\n7 2\\n15 3\\n74 18\\n22 7\\n\", \"88294752 4\\n35290308 52335089 69408342 32650662\\n53981397 84728746\\n56670292 81664574\\n16110353 77620219\\n45476005 495904\\n\", \"41323044 1\\n28208465 38217978 31290636 25974675\\n39500... | Yura has been walking for some time already and is planning to return home. He needs to get home as fast as possible. To do this, Yura can use the instant-movement locations around the city.
Let's represent the city as an area of $n \times n$ square blocks. Yura needs to move from the block with coordinates $(s_x,s_y)... | 0 |
{"tests": "{\"inputs\": [\"5\\n1 5 4 3 2\\n\", \"6\\n2 2 2 2 2 2\\n\", \"2\\n0 0\\n\", \"2\\n1 2\\n\", \"2\\n10 -1\\n\", \"5\\n934 235 171 111 197\\n\", \"100\\n0 1 1 1 0 0 0 2 1 2 2 1 2 2 2 0 0 2 1 2 0 1 1 0 2 0 1 2 2 0 2 0 1 0 1 2 0 2 1 1 0 1 0 1 0 0 1 2 2 2 2 1 1 1 0 2 1 0 0 0 0 0 1 0 2 0 1 0 0 2 0 2 2 1 0 2 2 0 2 0... | Andrew skipped lessons on the subject 'Algorithms and Data Structures' for the entire term. When he came to the final test, the teacher decided to give him a difficult task as a punishment.
The teacher gave Andrew an array of n numbers a_1, ..., a_{n}. After that he asked Andrew for each k from 1 to n - 1 to build a k... | 0.375 |
{"tests": "{\"inputs\": [\"5 4\\n3 5 1 4\\n\", \"4 3\\n1 2 4\\n\", \"5 1\\n1\\n\", \"5 5\\n1 1 4 2 2\\n\", \"10 20\\n10 1 5 7 1 2 5 3 6 3 9 4 3 4 9 6 8 4 9 6\\n\", \"1 1\\n1\\n\", \"1 2\\n1 1\\n\", \"2 1\\n2\\n\", \"2 1\\n1\\n\"], \"outputs\": [\"1 3\\n2 5\\n1 4\\n1 5\\n1 5\\n\", \"1 3\\n1 2\\n3 4\\n1 4\\n\", \"1 1\\n2... | Polycarp is a frequent user of the very popular messenger. He's chatting with his friends all the time. He has $n$ friends, numbered from $1$ to $n$.
Recall that a permutation of size $n$ is an array of size $n$ such that each integer from $1$ to $n$ occurs exactly once in this array.
So his recent chat list can be r... | 0 |
{"tests": "{\"inputs\": [\"4 4 4\\n\", \"1 1 1\\n\", \"50 50 1\\n\", \"4 4 9\\n\", \"10 10 10\\n\", \"50 50 1\\n\", \"50 50 10\\n\", \"2 2 3\\n\", \"1 2 1\\n\"], \"outputs\": [\"8\\n(1,1) (2,1) (2,2)\\n(1,1) (1,2)\\n(1,1) (2,1)\\n(1,1)\\n\", \"1\\n(1,1)\\n\", \"1\\n(1,1)\\n\", \"26\\n(1,1) (1,2) (1,3) (2,3)\\n(1,1) (1,... | Inna loves sweets very much. That's why she decided to play a game called "Sweet Matrix".
Inna sees an n × m matrix and k candies. We'll index the matrix rows from 1 to n and the matrix columns from 1 to m. We'll represent the cell in the i-th row and j-th column as (i, j). Two cells (i, j) and (p, q) of the matrix ar... | 0 |
{"tests": "{\"inputs\": [\"15 5\\n0 3 7 14 15\\n11 11\\n\", \"13 4\\n0 3 7 13\\n9 9\\n\", \"4 5\\n0 3 1 2 4\\n1 1\\n\", \"4 5\\n0 3 1 2 4\\n2 1\\n\", \"15 5\\n15 3 7 0 14\\n11 11\\n\", \"15 5\\n15 14 7 3 0\\n11 11\\n\", \"4 3\\n0 4 2\\n2 2\\n\", \"100 5\\n3 100 7 13 0\\n99 5\\n\", \"30 8\\n0 1 9 10 23 24 26 30\\n40 7\\... | If the girl doesn't go to Denis, then Denis will go to the girl. Using this rule, the young man left home, bought flowers and went to Nastya.
On the way from Denis's house to the girl's house is a road of $n$ lines. This road can't be always crossed in one green light. Foreseeing this, the good mayor decided to place... | 0 |
{"tests": "{\"inputs\": [\"3\\n2 1 3\\n3 3 6\\n99995 9998900031 9998900031\\n\", \"1\\n4 13 13\\n\", \"10\\n2 1 3\\n2 1 3\\n2 1 3\\n2 1 3\\n2 1 3\\n2 1 3\\n2 1 3\\n2 1 3\\n2 1 3\\n2 1 3\\n\", \"1\\n4 12 13\\n\", \"5\\n3 7 7\\n4 13 13\\n5 21 21\\n6 31 31\\n7 42 43\\n\", \"1\\n5 4 4\\n\", \"1\\n3 1 1\\n\", \"1\\n3 7 7\\n... | You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops.
You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such c... | 0 |
{"tests": "{\"inputs\": [\"2\\n0 40 100 100\\n60 0 40 40\\n0 60 0 45\\n0 60 55 0\\n\", \"3\\n0 0 100 0 100 0 0 0\\n100 0 100 0 0 0 100 100\\n0 0 0 100 100 0 0 0\\n100 100 0 0 0 0 100 100\\n0 100 0 100 0 0 100 0\\n100 100 100 100 100 0 0 0\\n100 0 100 0 0 100 0 0\\n100 0 100 0 100 100 100 0\\n\", \"2\\n0 21 41 26\\n79 0... | The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2^{N} teams participating in the tournament, numbered from 1 to 2^{N}. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of... | 0 |
{"tests": "{\"inputs\": [\"5\\nMisha ILoveCodeforces\\nVasya Petrov\\nPetrov VasyaPetrov123\\nILoveCodeforces MikeMirzayanov\\nPetya Ivanov\\n\", \"1\\nMisha Vasya\\n\", \"10\\na b\\nb c\\nc d\\nd e\\ne f\\nf g\\ng h\\nh i\\ni j\\nj k\\n\", \"5\\n123abc abc123\\nabc123 a1b2c3\\na1b2c3 1A2B3C\\n1 2\\n2 Misha\\n\", \"8\\... | Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the re... | 0 |
{"tests": "{\"inputs\": [\"4\\n+\\n+\\n- 2\\n+\\n- 3\\n+\\n- 1\\n- 4\\n\", \"1\\n- 1\\n+\\n\", \"3\\n+\\n+\\n+\\n- 2\\n- 1\\n- 3\\n\", \"1\\n+\\n- 1\\n\", \"10\\n+\\n- 3\\n+\\n+\\n+\\n+\\n- 1\\n- 7\\n- 9\\n- 10\\n+\\n+\\n+\\n- 4\\n- 5\\n- 8\\n+\\n- 6\\n+\\n- 2\\n\", \"10\\n+\\n- 3\\n+\\n+\\n+\\n+\\n- 1\\n- 7\\n- 9\\n- ... | Tenten runs a weapon shop for ninjas. Today she is willing to sell $n$ shurikens which cost $1$, $2$, ..., $n$ ryo (local currency). During a day, Tenten will place the shurikens onto the showcase, which is empty at the beginning of the day. Her job is fairly simple: sometimes Tenten places another shuriken (from the a... | 0 |
{"tests": "{\"inputs\": [\"4 3\\n1 2 2 3\\n4 1 1\\n\", \"6 10\\n5 8 1 10 8 7\\n6 6 4 4 3 2 2 2 1 1\\n\", \"5 1\\n1 1 1 1 1\\n5\\n\", \"5 1\\n1 1 1 1 1\\n1\\n\", \"1 1\\n1\\n1\\n\", \"1 10\\n10\\n1 1 1 1 1 1 1 1 1 1\\n\", \"10 5\\n2 2 4 4 3 1 1 2 3 2\\n9 6 6 4 1\\n\", \"10 20\\n20 1 15 17 11 2 15 3 16 3\\n10 9 9 9 8 8 8... | So you decided to hold a contest on Codeforces. You prepared the problems: statements, solutions, checkers, validators, tests... Suddenly, your coordinator asks you to change all your tests to multiple testcases in the easiest problem!
Initially, each test in that problem is just an array. The maximum size of an array... | 0 |
{"tests": "{\"inputs\": [\"7 2\\n0 1 0 2 1 0 2\\n2 1\\n\", \"10 3\\n0 0 1 2 3 0 2 0 1 2\\n1 1 4\\n\", \"5 1\\n1 1 1 1 1\\n5\\n\", \"100 10\\n1 1 6 6 6 2 5 7 6 5 3 7 10 10 8 9 7 6 9 2 6 7 8 6 7 5 2 5 10 1 10 1 8 10 2 9 7 1 6 8 3 10 9 4 4 8 8 6 6 1 5 5 6 5 6 6 6 9 4 7 5 4 6 6 1 1 2 1 8 10 6 2 1 7 2 1 8 10 9 2 7 3 1 5 10 ... | Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m.
About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day.
On ... | 0 |
{"tests": "{\"inputs\": [\"3\\n5 8\\n1 4\\n3 10\\n\", \"4\\n1 2\\n2 3\\n3 4\\n4 5\\n\", \"1\\n1 1\\n\", \"2\\n1 9\\n4 5\\n\", \"2\\n1 2\\n2 8\\n\", \"6\\n216986951114298167 235031205335543871\\n148302405431848579 455670351549314242\\n506251128322958430 575521452907339082\\n1 768614336404564650\\n189336074809158272 6221... | Lee is used to finish his stories in a stylish way, this time he barely failed it, but Ice Bear came and helped him. Lee is so grateful for it, so he decided to show Ice Bear his new game called "Critic"...
The game is a one versus one game. It has $t$ rounds, each round has two integers $s_i$ and $e_i$ (which are det... | 0 |
{"tests": "{\"inputs\": [\"6 2\\n5 6 7 9 4 5\\n\", \"8 6\\n7 7 7 7 8 8 8 8\\n\", \"4 1\\n4 2 1 10\\n\", \"10 10\\n12 13 10 20 13 10 19 15 21 11\\n\", \"20 16\\n23 27 17 29 23 21 24 23 19 25 16 24 20 17 18 17 16 17 28 17\\n\", \"30 40\\n26 22 10 20 29 18 38 11 41 8 33 37 37 3 14 4 3 9 21 38 27 27 7 7 33 12 39 37 17 5\\n... | Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written ... | 0 |
{"tests": "{\"inputs\": [\"1\\n4\\n\", \"4\\n1 3 2 5\\n\", \"4\\n1 5 2 3\\n\", \"10\\n2 2 2 17 8 9 10 17 10 5\\n\", \"100\\n102 157 177 149 138 193 19 74 127 156 128 122 6 101 154 92 24 188 51 89 18 77 112 100 65 11 113 173 79 124 102 81 11 171 114 43 60 168 44 86 87 82 177 8 12 181 139 121 140 28 108 17 173 63 18 4 14... | The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the lesson.
Nam created a sequence a consisting of n (1 ≤ n ≤ 10^5) elements a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5). A subseq... | 0 |
{"tests": "{\"inputs\": [\"2 1\\n\", \"2 2\\n\", \"1 1\\n\", \"2 3\\n\", \"4 4\\n\", \"1 12\\n\", \"12 1\\n\", \"24 6\\n\", \"25 5\\n\"], \"outputs\": [\"2\\n1 1\\n2 1\\n\", \"3\\n1 1\\n1 2\\n2 2\\n\", \"1\\n1 1\\n\", \"4\\n1 1\\n1 2\\n1 3\\n2 3\\n\", \"7\\n1 1\\n1 2\\n1 3\\n1 4\\n4 4\\n3 4\\n2 4\\n\", \"12\\n1 1\\n1 2... | Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he... | 0 |
{"tests": "{\"inputs\": [\"4 2\\nabcd\\nbcde\\nbcad\\nbcde\\n\", \"5 3\\nbwwwz\\nhrhdh\\nsepsp\\nsqfaf\\najbvw\\n\", \"7 6\\nypnxnnp\\npnxonpm\\nnxanpou\\nxnnpmud\\nnhtdudu\\nnpmuduh\\npmutsnz\\n\", \"1 0\\ng\\n\", \"1 1\\ng\\n\", \"1 0\\na\\n\", \"1 1\\nz\\n\", \"4 16\\ndfhs\\nvgca\\ndfgd\\nvscd\\n\", \"1 0\\nz\\n\"],... | You are given a matrix of size $n \times n$ filled with lowercase English letters. You can change no more than $k$ letters in this matrix.
Consider all paths from the upper left corner to the lower right corner that move from a cell to its neighboring cell to the right or down. Each path is associated with the string ... | 0 |
{"tests": "{\"inputs\": [\"4\\n0110\\n0010\\n0001\\n1000\\n4\\n1 2 3 4\\n\", \"4\\n0110\\n0010\\n1001\\n1000\\n20\\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\\n\", \"3\\n011\\n101\\n110\\n7\\n1 2 3 1 3 2 1\\n\", \"4\\n0110\\n0001\\n0001\\n1000\\n3\\n1 2 4\\n\", \"2\\n01\\n00\\n2\\n1 2\\n\", \"16\\n0011101010011011\\n1001... | The main characters have been omitted to be short.
You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$.
Define the seq... | 0 |
{"tests": "{\"inputs\": [\"5 10\\n1 15\\n5 3\\n6 11\\n7 2\\n11 22\\n\", \"3 5\\n1 8\\n2 19\\n3 11\\n\", \"10 8\\n1 16\\n23 27\\n26 2\\n32 21\\n38 50\\n51 53\\n62 79\\n77 97\\n94 18\\n100 5\\n\", \"22 936\\n20 743\\n55 46\\n83 282\\n157 3\\n168 979\\n241 338\\n293 113\\n312 292\\n333 509\\n339 632\\n345 149\\n347 109\\n... | Vasya got really tired of these credits (from problem F) and now wants to earn the money himself! He decided to make a contest to gain a profit.
Vasya has $n$ problems to choose from. They are numbered from $1$ to $n$. The difficulty of the $i$-th problem is $d_i$. Moreover, the problems are given in the increasing or... | 0.75 |
{"tests": "{\"inputs\": [\"2\\n3\\n3 2 1\\n6\\n3 1 4 1 5 9\\n\", \"4\\n7\\n6 6 8 8 6 6 6\\n1\\n2\\n5\\n4 5 9 8 7\\n7\\n1 2 7 1 6 10 2\\n\", \"2\\n5\\n5 5 5 5 5\\n3\\n1 2 5\\n\", \"2\\n5\\n1 2 3 4 5\\n4\\n2 3 4 5\\n\", \"1\\n3\\n1 1 274005660\\n\", \"2\\n2\\n1 1\\n1\\n1\\n\", \"2\\n4\\n1 3 3 3\\n3\\n1 2 3\\n\", \"2\\n3\... | Ehab has an array $a$ of length $n$. He has just enough free time to make a new array consisting of $n$ copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
A sequence $a$ is a subsequence of an array $b$ if $a$ can be obtained from $b$ by deletion o... | 0.625 |
{"tests": "{\"inputs\": [\"2 3 3 2\\nA.A\\n...\\nA.a\\n..C\\nX.Y\\n...\\n\", \"1 1 4 1\\nA\\n.\\nB\\n.\\n\", \"1 3 5 2\\nABA\\nBBB\\nBBA\\nBAB\\nABB\\n\", \"2 2 5 1\\n..\\nBA\\n.A\\nB.\\n..\\nA.\\nAB\\n.B\\n..\\n..\\n\", \"3 3 10 2\\nBA.\\n..A\\n.BB\\nB..\\n..B\\n.AA\\nB..\\nAB.\\n..A\\nBAB\\n.A.\\n.B.\\n..B\\nA..\\n..... | During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n × m checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell ... | 0 |
{"tests": "{\"inputs\": [\"11\\n(RaRbR)L)L(\\n\", \"11\\n(R)R(R)Ra)c\\n\", \"1\\na\\n\", \"3\\n(R)\\n\", \"3\\n(R(\\n\", \"3\\n)R)\\n\", \"3\\n)R(\\n\", \"3\\n(l)\\n\", \"21\\n(RRRRR)LLLL(RRR)LL(R)\\n\"], \"outputs\": [\"-1 -1 -1 -1 -1 -1 1 1 -1 -1 2 \", \"-1 -1 1 1 -1 -1 1 1 1 -1 1 \", \"0 \", \"-1 -1 1 \", \"-1 -1 -1... | The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text.
Your editor consists of a line with infinite length and cursor, which points to the current character. Please note that it points to only one of the characters (and not between a pair of characters)... | 0.5 |
{"tests": "{\"inputs\": [\"5\\n! abc\\n. ad\\n. b\\n! cd\\n? c\\n\", \"8\\n! hello\\n! codeforces\\n? c\\n. o\\n? d\\n? h\\n. l\\n? e\\n\", \"7\\n! ababahalamaha\\n? a\\n? b\\n? a\\n? b\\n? a\\n? h\\n\", \"4\\n! abcd\\n! cdef\\n? d\\n? c\\n\", \"1\\n? q\\n\", \"15\\n. r\\n? e\\n. s\\n. rw\\n? y\\n. fj\\n. zftyd\\n? r\\... | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | 0 |
{"tests": "{\"inputs\": [\"5\\n1 2\\n1 3\\n2 4\\n2 5\\n\", \"6\\n1 2\\n1 3\\n3 4\\n1 5\\n5 6\\n\", \"1\\n\", \"2\\n1 2\\n\", \"3\\n1 2\\n1 3\\n\", \"10\\n1 2\\n1 3\\n3 4\\n3 5\\n4 6\\n1 7\\n3 8\\n2 9\\n6 10\\n\", \"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... | 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 of ... | 0 |
{"tests": "{\"inputs\": [\"7\\n3 4 1 2 2 1 1\\n\", \"5\\n1 1 3 1 1\\n\", \"5\\n10 40 20 50 30\\n\", \"100\\n10 10 15 12 15 13 15 12 10 10 15 11 13 14 13 14 10 13 12 10 14 12 13 11 14 15 12 11 11 15 12 12 11 14 14 14 15 10 10 15 15 13 13 15 10 12 14 10 12 13 11 15 11 13 14 12 10 12 11 14 13 15 13 15 13 14 14 11 12 13 11... | You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first two occurrences of $x$ in this array (the two leftmost occurrences). Remove the left of these two... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.