text stringlengths 424 69.5k |
|---|
### Prompt
In cpp, your task is to solve the following problem:
A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h-1 onto a base. A base consists of h pyramids of height 1, and h-1 cards on top. Fo... |
### Prompt
Create a solution in Cpp for the following problem:
Little Petya loves training spiders. Petya has a board n × m in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, and all of them humbly perform its commands. There are 5 po... |
### Prompt
Construct a cpp code solution to the problem outlined:
This is the story of 20XX. The number of air passengers increased as a result of the stable energy supply by the renewable power network and the invention of liquefied synthetic fuel. However, the threat of terrorism by aircraft still exists, and the i... |
### Prompt
Your task is to create a Cpp solution to the following problem:
You are given a bipartite graph: the first part of this graph contains n_1 vertices, the second part contains n_2 vertices, and there are m edges. The graph can contain multiple edges.
Initially, each edge is colorless. For each edge, you may... |
### Prompt
Construct a CPP code solution to the problem outlined:
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an i... |
### Prompt
In Cpp, your task is to solve the following problem:
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the ch... |
### Prompt
Develop a solution in Cpp to the problem described below:
Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food:
* on Mondays, Thursdays and Sundays he eats fish food;
* on Tuesdays and Saturdays he eats rabbit stew;
* on other days of week h... |
### Prompt
Please formulate a CPP solution to the following problem:
Urpal lives in a big city. He has planned to meet his lover tonight.
The city has n junctions numbered from 1 to n. The junctions are connected by m directed streets, all the roads have equal length. Urpal lives in junction a and the date is plann... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the num... |
### Prompt
Your task is to create a Cpp solution to the following problem:
Fibonacci numbers are the sequence of integers: f0 = 0, f1 = 1, f2 = 1, f3 = 2, f4 = 3, f5 = 5, ..., fn = fn - 2 + fn - 1. So every next number is the sum of the previous two.
Bajtek has developed a nice way to compute Fibonacci numbers on a ... |
### Prompt
Create a solution in cpp for the following problem:
As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertic... |
### Prompt
Please provide a CPP coded solution to the problem described below:
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't ex... |
### Prompt
Develop a solution in Cpp to the problem described below:
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.
Snuke is trying t... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of s... |
### Prompt
Develop a solution in Cpp to the problem described below:
The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
<image>
The event coordinat... |
### Prompt
Please create a solution in cpp to the following problem:
During a New Year special offer the "Sudislavl Bars" offered n promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.
As the "Mosquito Sh... |
### Prompt
Please create a solution in CPP to the following problem:
Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the ... |
### Prompt
Construct a cpp code solution to the problem outlined:
Niwango bought a piece of land that can be represented as a half-open interval [0, X).
Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N, and they are distinguishable. For Sheet i, he can choose an integer j such... |
### Prompt
Create a solution in Cpp for the following problem:
This is the easy version of the problem. The only difference between the easy version and the hard version is the constraints on n. You can only make hacks if both versions are solved.
A permutation of 1, 2, …, n is a sequence of n integers, where each i... |
### Prompt
In CPP, your task is to solve the following problem:
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.
The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set ... |
### Prompt
Please create a solution in cpp to the following problem:
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The di... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
Koa the Koala has a directed graph G with n nodes and m edges. Each edge has a capacity associated with it. Exactly k edges of the graph, numbered from 1 to k, are special, such edges initially have a capacity equal to 0.
Koa asks you q q... |
### Prompt
Develop a solution in cpp to the problem described below:
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K ... |
### Prompt
Please create a solution in Cpp to the following problem:
KM country has N kinds of coins and each coin has its value a_i.
The king of the country, Kita_masa, thought that the current currency system is poor, and he decided to make it beautiful by changing the values of some (possibly no) coins.
A curren... |
### Prompt
Please create a solution in cpp to the following problem:
A penguin Rocher has n sticks. He has exactly one stick with length i for all 1 ≤ i ≤ n.
He can connect some sticks. If he connects two sticks that have lengths a and b, he gets one stick with length a + b. Two sticks, that were used in the operati... |
### Prompt
In CPP, your task is to solve the following problem:
Makoto has a big blackboard with a positive integer n written on it. He will perform the following action exactly k times:
Suppose the number currently written on the blackboard is v. He will randomly pick one of the divisors of v (possibly 1 and v) and... |
### Prompt
Generate a cpp solution to the following problem:
Prime numbers are widely applied for cryptographic and communication technology. A twin prime is a prime number that differs from another prime number by 2. For example, (5, 7) and (11, 13) are twin prime pairs.
In this problem, we call the greater number ... |
### Prompt
In Cpp, your task is to solve the following problem:
Filya just learned new geometry object — rectangle. He is given a field consisting of n × n unit cells. Rows are numbered from bottom to top with integer from 1 to n. Columns are numbered from left to right with integers from 1 to n. Cell, located at the... |
### Prompt
Your task is to create a Cpp solution to the following problem:
Example
Input
1
Output
)(
### Response
```cpp
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int A;
int c[200010];
int n,now;
int main()
{
scanf("%d",&A);
n=1;
while ((ll)n*(n+1)/2<(ll)A) n++;
int p=A-(ll)n*(n... |
### Prompt
Develop a solution in CPP to the problem described below:
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».
The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered f... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC ru... |
### Prompt
Your challenge is to write a CPP solution to the following problem:
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its lengt... |
### Prompt
In cpp, your task is to solve the following problem:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with... |
### Prompt
Your challenge is to write a cpp solution to the following problem:
Ostap is preparing to play chess again and this time he is about to prepare. Thus, he was closely monitoring one recent chess tournament. There were m players participating and each pair of players played exactly one game. The victory give... |
### Prompt
Please formulate a Cpp solution to the following problem:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has... |
### Prompt
Construct a CPP code solution to the problem outlined:
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, b2... |
### Prompt
Develop a solution in CPP to the problem described below:
The cows have just learned what a primitive root is! Given a prime p, a primitive root <image> is an integer x (1 ≤ x < p) such that none of integers x - 1, x2 - 1, ..., xp - 2 - 1 are divisible by p, but xp - 1 - 1 is.
Unfortunately, computing pr... |
### Prompt
Develop a solution in CPP to the problem described below:
I have n tickets for a train with a rabbit. Each ticket is numbered from 0 to n − 1, and you can use the k ticket to go to p⋅ak + q⋅bk station.
Rabbit wants to go to the all-you-can-eat carrot shop at the station m station ahead of the current stat... |
### Prompt
Please formulate a CPP solution to the following problem:
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the gr... |
### Prompt
Please provide a cpp coded solution to the problem described below:
Alyona has built n towers by putting small cubes some on the top of others. Each cube has size 1 × 1 × 1. A tower is a non-zero amount of cubes standing on the top of each other. The towers are next to each other, forming a row.
Sometimes... |
### Prompt
Develop a solution in Cpp to the problem described below:
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. ... |
### Prompt
Your task is to create a CPP solution to the following problem:
You are given two sequences a_1, a_2, ..., a_n and b_1, b_2, ..., b_n. Each element of both sequences is either 0, 1 or 2. The number of elements 0, 1, 2 in the sequence a is x_1, y_1, z_1 respectively, and the number of elements 0, 1, 2 in th... |
### Prompt
Your task is to create a CPP solution to the following problem:
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 childre... |
### Prompt
Please provide a CPP coded solution to the problem described below:
In ABBYY a wonderful Smart Beaver lives. This time, he began to study history. When he read about the Roman Empire, he became interested in the life of merchants.
The Roman Empire consisted of n cities numbered from 1 to n. It also had m ... |
### Prompt
Develop a solution in cpp to the problem described below:
There are N rabbits, numbered 1 through N.
The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i.
For a pair of rabbits i and j (i<j), we call the pair (i,j) a friendly pair if the following condition is met... |
### Prompt
Generate a cpp solution to the following problem:
You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language.
Input
This program has only one tes... |
### Prompt
Construct a Cpp code solution to the problem outlined:
Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was written on it. In case you forget, a tree is a connected non-directed graph without cycles. After the present was granted, m... |
### Prompt
In Cpp, your task is to solve the following problem:
Takahashi the Jumbo will practice golf.
His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).
If he can achieve the objective, print `OK`; if he cannot, print `NG`.
Co... |
### Prompt
In Cpp, your task is to solve the following problem:
Does the card fit in a snack? (Are Cards Snacks?)
square1001 You have $ N $ cards.
Each of these cards has an integer written on it, and the integer on the $ i $ th card is $ A_i $.
square1001 Your random number today is $ K $. square1001 You want to ... |
### Prompt
Create a solution in CPP for the following problem:
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell... |
### Prompt
Develop a solution in CPP to the problem described below:
Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table M with n rows and n columns such that M_{ij}=a_i ⋅ a_j where a_1, ..., a_n is some sequence of positive integers.
Of course, the girl decide... |
### Prompt
Your task is to create a CPP solution to the following problem:
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 len... |
### Prompt
Develop a solution in cpp to the problem described below:
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to m... |
### Prompt
Please formulate a cpp solution to the following problem:
During a voyage of the starship Hakodate-maru (see Problem A), researchers found strange synchronized movements of stars. Having heard these observations, Dr. Extreme proposed a theory of "super stars". Do not take this term as a description of acto... |
### Prompt
Generate a CPP solution to the following problem:
Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.
Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common... |
### Prompt
Please provide a Cpp coded solution to the problem described below:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He star... |
### Prompt
Construct a CPP code solution to the problem outlined:
There are n parrots standing in a circle. Each parrot has a certain level of respect among other parrots, namely r_i. When a parrot with respect level x starts chattering, x neighbours to the right and to the left of it start repeating the same words i... |
### Prompt
Generate a Cpp solution to the following problem:
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started wai... |
### Prompt
Develop a solution in cpp to the problem described below:
"Search" is an operation to obtain the desired information from a large amount of information. Familiar examples include "finding your own exam number from a large number of exam numbers" when announcing your success, or "finding Taro Aizu's phone n... |
### Prompt
In cpp, your task is to solve the following problem:
Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up,... |
### Prompt
Please create a solution in Cpp to the following problem:
You are given a permutation p. Calculate the total number of inversions in all permutations that lexicographically do not exceed the given one.
As this number can be very large, print it modulo 1000000007 (109 + 7).
Input
The first line contains ... |
### Prompt
Please formulate a Cpp solution to the following problem:
Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, res... |
### Prompt
Create a solution in Cpp for the following problem:
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this sub... |
### Prompt
In CPP, your task is to solve the following problem:
Peter is a person with erratic sleep habits. He goes to sleep at twelve o'lock every midnight. He gets up just after one hour of sleep on some days; he may even sleep for twenty-three hours on other days. His sleeping duration changes in a cycle, where h... |
### Prompt
Please create a solution in Cpp to the following problem:
Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality:
a + b + c + d = n
For example, for n = 35, we have 4 different combinations of (a, b, c, d)... |
### Prompt
Please provide a cpp coded solution to the problem described below:
Yaroslav has an array p = p1, p2, ..., pn (1 ≤ pi ≤ n), consisting of n distinct integers. Also, he has m queries:
* Query number i is represented as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n).
* The answer to the query li, ri is th... |
### Prompt
Please create a solution in Cpp to the following problem:
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered from... |
### Prompt
Your task is to create a cpp solution to the following problem:
For integers b (b \geq 2) and n (n \geq 1), let the function f(b,n) be defined as follows:
* f(b,n) = n, when n < b
* f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b), when n \geq b
Here, {\rm floor}(n / b) denotes the largest inte... |
### Prompt
Develop a solution in cpp to the problem described below:
Takahashi has many red balls and blue balls. Now, he will place them in a row.
Initially, there is no ball placed.
Takahashi, who is very patient, will do the following operation 10^{100} times:
* Place A blue balls at the end of the row of balls... |
### Prompt
Please provide a cpp coded solution to the problem described below:
Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string conta... |
### Prompt
Your challenge is to write a cpp solution to the following problem:
The only difference between easy and hard versions is constraints.
There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the p_i-th kid (in case of i = p_i the kid will give his... |
### Prompt
Please create a solution in Cpp to the following problem:
Polycarp has 26 tasks. Each task is designated by a capital letter of the Latin alphabet.
The teacher asked Polycarp to solve tasks in the following way: if Polycarp began to solve some task, then he must solve it to the end, without being distract... |
### Prompt
Develop a solution in CPP to the problem described below:
The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle whose side... |
### Prompt
Generate a Cpp solution to the following problem:
Let N be a positive odd number.
There are N coins, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i.
Taro has tossed all the N coins. Find the probabil... |
### Prompt
Your challenge is to write a cpp solution to the following problem:
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from ci... |
### Prompt
Please formulate a cpp solution to the following problem:
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of S meters per minute.
Will he... |
### Prompt
Please formulate a Cpp solution to the following problem:
Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number <image>, in particular that q2 = q + 1, and she thinks it would make a good base for her new unique sys... |
### Prompt
Your challenge is to write a cpp solution to the following problem:
You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concatenation of these strings is string q (formally, s1 + s2 + ... + sk = q) and the first characters of these strings are distinct.
Find any b... |
### Prompt
Create a solution in cpp for the following problem:
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes on... |
### Prompt
Develop a solution in Cpp to the problem described below:
Snuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction.
Let us define a function f(r, c) as follows:
* f(r,c) := (The number of paths from the point (... |
### Prompt
In Cpp, your task is to solve the following problem:
Let’s take a prime P = 200\,003. You are given N integers A_1, A_2, \ldots, A_N. Find the sum of ((A_i \cdot A_j) \bmod P) over all N \cdot (N-1) / 2 unordered pairs of elements (i < j).
Please note that the sum isn't computed modulo P.
Constraints
* ... |
### Prompt
Create a solution in cpp for the following problem:
You've got an n × m table (n rows and m columns), each cell of the table contains a "0" or a "1".
Your task is to calculate the number of rectangles with the sides that are parallel to the sides of the table and go along the cell borders, such that the n... |
### Prompt
Please create a solution in CPP to the following problem:
Petya and Vasya got employed as couriers. During the working day they are to deliver packages to n different points on the line. According to the company's internal rules, the delivery of packages must be carried out strictly in a certain order. Ini... |
### Prompt
Create a solution in cpp for the following problem:
A 3×3 grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top right... |
### Prompt
Construct a CPP code solution to the problem outlined:
Min Element
Given the sequence a_1, a_2, .., a_N.
Find the minimum number in this sequence.
If the minimum value is in more than one place, answer the one with the lowest number.
input
N
a_1 a_2 ... a_N
output
Output the smallest i such that a... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x.
More formally, there is a singly liked list built on an a... |
### Prompt
Create a solution in CPP for the following problem:
In a magical land there are n cities conveniently numbered 1, 2, ..., n. Some pairs of these cities are connected by magical colored roads. Magic is unstable, so at any time, new roads may appear between two cities.
Vicky the witch has been tasked with p... |
### Prompt
Generate a Cpp solution to the following problem:
The government of Berland decided to improve network coverage in his country. Berland has a unique structure: the capital in the center and n cities in a circle around the capital. The capital already has a good network coverage (so the government ignores i... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a2 is a divisor of x.
<image>
Malek has a number store! In his store, he has only divisors of pos... |
### Prompt
Develop a solution in Cpp to the problem described below:
Alex enjoys performing magic tricks. He has a trick that requires a deck of n cards. He has m identical decks of n different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs n cards at random and performs t... |
### Prompt
Your task is to create a cpp solution to the following problem:
The only difference between easy and hard versions is constraints.
Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you.
There are n voters, and two ways to convince each of them to vo... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an integer sequence of length N, a_1,a_2,...,a_N.
For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.
After these operations, you select an integer X and count the number of i such that ... |
### Prompt
Your task is to create a Cpp solution to the following problem:
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar a... |
### Prompt
Create a solution in Cpp for the following problem:
You are given a connected undirected simple graph, which has N vertices and M edges. The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects vertices A_i and B_i. Your task is to find a path that satisfies the follow... |
### Prompt
Please formulate a CPP solution to the following problem:
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs wi... |
### Prompt
Please formulate a CPP solution to the following problem:
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a ⊕ b ⊕ c = 0, where ⊕ denotes the [bitwise XOR operati... |
### Prompt
In CPP, your task is to solve the following problem:
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically... |
### Prompt
Create a solution in Cpp for the following problem:
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
*... |
### Prompt
Construct a cpp code solution to the problem outlined:
You are given an array a consisting of n integer numbers.
Let instability of the array be the following value: max_{i = 1}^{n} a_i - min_{i = 1}^{n} a_i.
You have to remove exactly one element from this array to minimize instability of the resulting ... |
### Prompt
Your task is to create a CPP solution to the following problem:
Celebrating the new year, many people post videos of falling dominoes; Here's a list of them: https://www.youtube.com/results?search_query=New+Years+Dominos
User ainta, who lives in a 2D world, is going to post a video as well.
There are n d... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.