text stringlengths 424 69.5k |
|---|
### Prompt
Generate a cpp solution to the following problem:
There are n balls. They are arranged in a row. Each ball has a color (for convenience an integer) and an integer value. The color of the i-th ball is ci and the value of the i-th ball is vi.
Squirrel Liss chooses some balls and makes a new sequence without... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shif... |
### Prompt
Create a solution in cpp for the following problem:
It is known that passages in Singer house are complex and intertwined. Let's define a Singer k-house as a graph built by the following process: take complete binary tree of height k and add edges from each vertex to all its successors, if they are not yet... |
### Prompt
Please provide a CPP coded solution to the problem described below:
You're given a tree with n vertices.
Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.
Input
The first line contains an inte... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second ... |
### Prompt
In Cpp, your task is to solve the following problem:
The Smart Beaver has recently designed and built an innovative nanotechnologic all-purpose beaver mass shaving machine, "Beavershave 5000". Beavershave 5000 can shave beavers by families! How does it work? Very easily!
There are n beavers, each of them ... |
### Prompt
In cpp, your task is to solve the following problem:
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
Constraints
* 1 \leq X \leq 10^9
* X is an integer.
* There exists a pair of integers (A, B) satisfying the condition in Probl... |
### Prompt
Develop a solution in Cpp to the problem described below:
There is a robot on a coordinate plane. Initially, the robot is located at the point (0, 0). Its path is described as a string s of length n consisting of characters 'L', 'R', 'U', 'D'.
Each of these characters corresponds to some move:
* 'L' (... |
### Prompt
Please create a solution in Cpp to the following problem:
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given ... |
### Prompt
Your task is to create a CPP solution to the following problem:
Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads rema... |
### Prompt
Your task is to create a Cpp solution to the following problem:
A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in additio... |
### Prompt
Develop a solution in cpp to the problem described below:
You are given a string of length n. Each character is one of the first p lowercase Latin letters.
You are also given a matrix A with binary values of size p Γ p. This matrix is symmetric (A_{ij} = A_{ji}). A_{ij} = 1 means that the string can have ... |
### Prompt
Please provide a Cpp coded solution to the problem described below:
We have a rectangular parallelepiped of size AΓBΓC, built with blocks of size 1Γ1Γ1. Snuke will paint each of the AΓBΓC blocks either red or blue, so that:
* There is at least one red block and at least one blue block.
* The union of all ... |
### Prompt
Your task is to create a CPP solution to the following problem:
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constru... |
### Prompt
In cpp, your task is to solve the following problem:
This problem is same as the next one, but has smaller constraints.
Aki is playing a new video game. In the video game, he will control Neko, the giant cat, to fly between planets in the Catniverse.
There are n planets in the Catniverse, numbered from 1... |
### Prompt
Your challenge is to write a cpp solution to the following problem:
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water an... |
### Prompt
Please provide a cpp coded solution to the problem described below:
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... |
### Prompt
Generate a CPP solution to the following problem:
Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string s, of all occurrences o... |
### Prompt
Please provide a Cpp coded solution to the problem described below:
At Akabe High School, a programmer training school, there is a unique study session run by the students themselves. It is important for programmers to constantly adopt new technologies, so the aim of this activity is to develop the habit o... |
### Prompt
Generate a cpp solution to the following problem:
Anna is a girl so brave that she is loved by everyone in the city and citizens love her cookies. She is planning to hold a party with cookies. Now she has a vanilla cookies and b chocolate cookies for the party.
She invited n guests of the first type and m... |
### Prompt
Please provide a Cpp coded solution to the problem described below:
In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick.
Let's assume that all these students are numbered from... |
### Prompt
Create a solution in Cpp for the following problem:
One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth center tile:
<image> By the pieces lay a large square w... |
### Prompt
Your task is to create a cpp solution to the following problem:
The only difference between easy and hard versions is the size of the input.
You are given a string s consisting of n characters, each character is 'R', 'G' or 'B'.
You are also given an integer k. Your task is to change the minimum number o... |
### Prompt
Develop a solution in Cpp to the problem described below:
()
Problem Statement
There is a string S. Initially, S is an empty string.
Perform the following processing in order of n.
* Add x_i p_i (=" (" or") ") to the end of S.
After processing, determine if S is a well-balanced string.
"The string i... |
### Prompt
Your challenge is to write a CPP solution to the following problem:
Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria.
1. first by $x$-coordinate
2. in case of a tie, by $y$-coordinate
Constraints
* $1 \leq n \leq 100,000$
* $-1,000,000,000 \... |
### Prompt
Your challenge is to write a cpp solution to the following problem:
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is... |
### Prompt
Please formulate a Cpp solution to the following problem:
Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described by an integer a_i.
Yui loves sweets, but she can eat at most m sweets each day for health reasons.
... |
### Prompt
Please provide a cpp coded solution to the problem described below:
You are given a rooted tree consisting of n vertices numbered from 1 to n. The root of the tree is a vertex number 1.
A tree is a connected undirected graph with n-1 edges.
You are given m queries. The i-th query consists of the set of k... |
### Prompt
Construct a cpp code solution to the problem outlined:
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, ca... |
### Prompt
Develop a solution in cpp to the problem described below:
In the house where Krosh used to live, he had n cupboards standing in a line, the i-th cupboard had the height of h_i. Krosh moved recently, but he wasn't able to move the cupboards with him. Now he wants to buy n new cupboards so that they look as ... |
### Prompt
Develop a solution in CPP to the problem described below:
Twin adventurers Rin and Len are searching for treasure in the Mirror Cave. The cave has two pairs of rooms, the Hall of Mirrors, and an expensive treasure lies behind the door of the room.
For convenience, each of the two rooms is considered to ha... |
### Prompt
Please provide a CPP coded solution to the problem described below:
You still have partial information about the score during the historic football match. You are given a set of pairs (a_i, b_i), indicating that at some point during the match the score was "a_i: b_i". It is known that if the current score ... |
### Prompt
Your challenge is to write a CPP solution to the following problem:
Read the coordinates of four different points on the plane, $ A (x_A, y_A) $, $ B (x_B, y_B) $, $ C (x_C, y_C) $, $ D (x_D, y_D) $, and straight line $ Create a program that outputs YES if AB $ and $ CD $ are orthogonal, and NO if they are... |
### Prompt
Construct a CPP code solution to the problem outlined:
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture... |
### Prompt
In CPP, your task is to solve the following problem:
We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}.
You need to rearrange these numbers a... |
### Prompt
Develop a solution in Cpp to the problem described below:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction <image> is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its nu... |
### Prompt
Your task is to create a Cpp solution to the following problem:
In an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning to plant some flower gardens to complement the lush, grassy fields of Bovinia. As any good horticulturist knows, each garden they plant must hav... |
### Prompt
Develop a solution in CPP to the problem described below:
Osaki
Osaki
English text is not available in this practice contest.
The Yamanote Line is a circular railway line laid in the 23 wards of Tokyo. The total route distance is 34.5km, and one lap takes about one hour. There are 29 stations in total. ... |
### Prompt
In cpp, your task is to solve the following problem:
One day a bear lived on the Oxy axis. He was afraid of the dark, so he couldn't move at night along the plane points that aren't lit. One day the bear wanted to have a night walk from his house at point (l, 0) to his friend's house at point (r, 0), along... |
### Prompt
Create a solution in cpp for the following problem:
Not so long ago as a result of combat operations the main Berland place of interest β the magic clock β was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be repres... |
### Prompt
Please create a solution in CPP to the following problem:
This is an interactive problem.
Vasya and Petya are going to play the following game: Petya has some positive integer number a. After that Vasya should guess this number using the following questions. He can say a pair of non-negative integer numbe... |
### Prompt
Generate a Cpp solution to the following problem:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector... |
### Prompt
In Cpp, your task is to solve the following problem:
PCK Taxi in Aizu city, owned by PCK company, has adopted a unique billing system: the user can decide the taxi fare. Today as usual, many people are waiting in a queue at the taxi stand in front of the station.
In front of the station, there are $N$ par... |
### Prompt
Develop a solution in Cpp to the problem described below:
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good.
Now she is interested in good sequences. A sequence x1, x2, ..., xk is called good if it satisfies the followi... |
### Prompt
Develop a solution in CPP to the problem described below:
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal t... |
### Prompt
Please create a solution in CPP to the following problem:
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A Γ floor(x/B) for a non-negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t.
Constraints
* 1 β€ A β€... |
### Prompt
Please formulate a cpp solution to the following problem:
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cu... |
### Prompt
Construct a cpp code solution to the problem outlined:
Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feede... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
Nauuo is a girl who loves playing cards.
One day she was playing cards but found that the cards were mixed with some empty ones.
There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n ... |
### Prompt
Construct a cpp code solution to the problem outlined:
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 tha... |
### Prompt
Construct a cpp code solution to the problem outlined:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travel... |
### Prompt
Develop a solution in CPP to the problem described below:
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct... |
### Prompt
Please provide a CPP coded solution to the problem described below:
This is the easy version of the problem. The difference between the versions is the constraint on n and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings a a... |
### Prompt
Develop a solution in CPP to the problem described below:
You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.
Notes
Constraints
* Elements in S is sorted in ascending order
* n β€ 1000... |
### Prompt
Construct a Cpp code solution to the problem outlined:
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wal... |
### Prompt
Generate a cpp solution to the following problem:
There is an infinite 2-dimensional grid. The robot stands in cell (0, 0) and wants to reach cell (x, y). Here is a list of possible commands the robot can execute:
* move north from cell (i, j) to (i, j + 1);
* move east from cell (i, j) to (i + 1, j)... |
### Prompt
Develop a solution in Cpp to the problem described below:
Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if
1. the sequence consists of at least two elements
2. f0 and f1 are arbitrary
3. fn + 2 = fn + 1 + fn for all n β₯ 0.
... |
### Prompt
Generate a cpp solution to the following problem:
Polycarpus enjoys studying Berland hieroglyphs. Once Polycarp got hold of two ancient Berland pictures, on each of which was drawn a circle of hieroglyphs. We know that no hieroglyph occurs twice in either the first or the second circle (but in can occur on... |
### Prompt
Construct a Cpp code solution to the problem outlined:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum n... |
### Prompt
Please provide a cpp coded solution to the problem described below:
Petya has a polygon consisting of n vertices. All sides of the Petya's polygon are parallel to the coordinate axes, and each two adjacent sides of the Petya's polygon are perpendicular. It is guaranteed that the polygon is simple, that is,... |
### Prompt
Construct a CPP code solution to the problem outlined:
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can optimiz... |
### Prompt
Create a solution in CPP for the following problem:
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 on... |
### Prompt
Please create a solution in Cpp to the following problem:
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 Γ n table).
At the beginning of the game Alice puts k ships on the field without telling their posit... |
### Prompt
Construct a CPP code solution to the problem outlined:
Programming teacher Dmitry Olegovich is going to propose the following task for one of his tests for students:
You are given a tree T with n vertices, specified by its adjacency matrix a[1... n, 1... n]. What is the output of the following pseudocode?... |
### Prompt
In CPP, your task is to solve the following problem:
Polycarp was given an array of a[1 ... n] of n integers. He can perform the following operation with the array a no more than n times:
* Polycarp selects the index i and adds the value a_i to one of his choice of its neighbors. More formally, Polycarp... |
### Prompt
Develop a solution in Cpp to the problem described below:
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons:... |
### Prompt
Generate a cpp solution to the following problem:
You've got an array consisting of n integers: a[1], a[2], ..., a[n]. Moreover, there are m queries, each query can be described by three integers li, ri, ki. Query li, ri, ki means that we should add <image> to each element a[j], where li β€ j β€ ri.
Record ... |
### Prompt
Your challenge is to write a cpp solution to the following problem:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a b... |
### Prompt
Please create a solution in Cpp to the following problem:
Tyndex is again well ahead of the rivals! The reaction to the release of Zoozle Chrome browser was the release of a new browser Tyndex.Brome!
The popularity of the new browser is growing daily. And the secret is not even the Tyndex.Bar installed (t... |
### Prompt
Develop a solution in CPP to the problem described below:
Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.
At the beginn... |
### Prompt
Create a solution in Cpp for the following problem:
Kilani and Abd are neighbors for 3000 years, but then the day came and Kilani decided to move to another house. As a farewell gift, Kilani is going to challenge Abd with a problem written by their other neighbor with the same name Abd.
<image>
The probl... |
### Prompt
Please formulate a CPP solution to the following problem:
Joisino is planning on touring Takahashi Town. The town is divided into square sections by north-south and east-west lines. We will refer to the section that is the x-th from the west and the y-th from the north as (x,y).
Joisino thinks that a tour... |
### Prompt
Generate a Cpp solution to the following problem:
Arkady words in a large company. There are n employees working in a system of a strict hierarchy. Namely, each employee, with an exception of the CEO, has exactly one immediate manager. The CEO is a manager (through a chain of immediate managers) of all emp... |
### Prompt
Please create a solution in Cpp to the following problem:
Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S.
For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows:
* f(L, R) is the number of sequences of integers (x_1, x_2, \ldots ... |
### Prompt
Create a solution in cpp for the following problem:
Ayoub had an array a of integers of size n and this array had two interesting properties:
* All the integers in the array were between l and r (inclusive).
* The sum of all the elements was divisible by 3.
Unfortunately, Ayoub has lost his arra... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads.
The Β«Two PathsΒ» company, whe... |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.
You can take and complete at most one of these jobs in a day.
However, you cannot retake... |
### Prompt
Create a solution in CPP for the following problem:
A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 β€ l β€ r β€ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements ... |
### Prompt
Please create a solution in CPP to the following problem:
One day, Okazaki Tomoya has bought a tree for Furukawa Nagisa's birthday. The tree is so strange that every node of the tree has a value. The value of the i-th node is vi. Now Furukawa Nagisa and Okazaki Tomoya want to play a game on the tree.
Let ... |
### Prompt
Your task is to create a CPP solution to the following problem:
Print the K-th element of the following sequence of length 32:
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
Constraints
* 1 \leq K \leq 32
* All values in input are integers.
Input
Inp... |
### Prompt
Please create a solution in cpp to the following problem:
Shrek and the Donkey (as you can guess, they also live in the far away kingdom) decided to play a card game called YAGame. The rules are very simple: initially Shrek holds m cards and the Donkey holds n cards (the players do not see each other's car... |
### Prompt
Your challenge is to write a CPP solution to the following problem:
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n... |
### Prompt
Please formulate a Cpp solution to the following problem:
This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points.
Manao has developed a model to predict ... |
### Prompt
Construct a CPP code solution to the problem outlined:
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 ste... |
### Prompt
Create a solution in CPP for the following problem:
There is a stack of N cards, each of which has a non-negative integer written on it. The integer written on the i-th card from the top is A_i.
Snuke will repeat the following operation until two cards remain:
* Choose three consecutive cards from the st... |
### Prompt
In Cpp, your task is to solve the following problem:
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such ... |
### Prompt
Please provide a CPP coded solution to the problem described below:
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 t... |
### Prompt
Please create a solution in CPP to the following problem:
Welcome to PC Koshien, players. This year marks the 10th anniversary of Computer Koshien, but the number of questions and the total score will vary from year to year. Scores are set for each question according to the difficulty level. When the numbe... |
### Prompt
Your challenge is to write a CPP solution to the following problem:
For given $n$ segments which are parallel to X-axis or Y-axis, find the number of intersections of them.
Constraints
* $1 \leq n \leq 100,000$
* $ -1,000,000,000 \leq x_1, y_1, x_2, y_2 \leq 1,000,000,000$
* Two parallel segments never o... |
### Prompt
Generate a cpp solution to the following problem:
You are given a string s consisting of exactly n characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings.
Your task is to replace minimum number of characters in this string with other characters to obtain a balanc... |
### Prompt
Construct a CPP code solution to the problem outlined:
An n Γ n square matrix is special, if:
* it is binary, that is, each cell contains either a 0, or a 1;
* the number of ones in each row and column equals 2.
You are given n and the first m rows of the matrix. Print the number of special n Γ n... |
### Prompt
Please formulate a Cpp solution to the following problem:
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers... |
### Prompt
Your task is to create a CPP solution to the following problem:
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
SelectionSort(A)
1 for i = 0 to A.length-1
2 mini = i
3 for j = i to A.length-1
4... |
### Prompt
Your challenge is to write a cpp solution to the following problem:
You have a computer literacy course in your university. In the computer system, the login/logout records of all PCs in a day are stored in a file. Although students may use two or more PCs at a time, no one can log in to a PC which has bee... |
### Prompt
Generate a CPP solution to the following problem:
Β«PolygonΒ» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the sy... |
### Prompt
Please create a solution in Cpp to the following problem:
For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.
Max is a young biologist. For n days he watched a specific shark, and now he... |
### Prompt
Please provide a CPP coded solution to the problem described below:
The athletics competition 200M semi-final three races were held. Eight players (24 players in total) will participate in each group. A total of eight players, including the top two players in each group and the top two players from all the... |
### Prompt
Develop a solution in Cpp to the problem described below:
You are given one integer n (n > 1).
Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (... |
### Prompt
Develop a solution in Cpp to the problem described below:
VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications.
The latest A/B test ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.