id
stringlengths
11
14
content
stringlengths
424
1.17M
apps_data_4500
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan. -----Constraints----- - All input ...
apps_data_4501
Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? -----Constraints----- - 1 \leq N \leq 50 - 1 \leq A \leq 50 ...
apps_data_4502
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: - Append a_i to the end of b. - Reverse the order of the elements in b. Find the sequence b obtained after these n operations. -----Constraints...
apps_data_4503
Raccoon is fighting with a monster. The health of the monster is H. Raccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i. There is no other way to decrease the monster's health. Raccoon wins when the monster's health becomes 0 or below. If Raccoon can win without using the...
apps_data_4504
We will call a string that can be obtained by concatenating two equal strings an even string. For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one o...
apps_data_4505
You are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc. -----Constraints----- - |S|=3 - S consists of a, b and c. -----Input----- Input is given from Standard Input in the following format: S -----Output----- If S can be obtained by permuting abc, print Yes; ...
apps_data_4506
You are given two arrays $a$ and $b$, both of length $n$. Let's define a function $f(l, r) = \sum\limits_{l \le i \le r} a_i \cdot b_i$. Your task is to reorder the elements (choose an arbitrary order of elements) of the array $b$ to minimize the value of $\sum\limits_{1 \le l \le r \le n} f(l, r)$. Since the answer ...
apps_data_4507
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
apps_data_4508
You are given an undirected tree consisting of $n$ vertices. An undirected tree is a connected undirected graph with $n - 1$ edges. Your task is to add the minimum number of edges in such a way that the length of the shortest path from the vertex $1$ to any other vertex is at most $2$. Note that you are not allowed to...
apps_data_4509
You are given two positive integers $n$ and $k$. Print the $k$-th positive integer that is not divisible by $n$. For example, if $n=3$, and $k=7$, then all numbers that are not divisible by $3$ are: $1, 2, 4, 5, 7, 8, 10, 11, 13 \dots$. The $7$-th number among them is $10$. -----Input----- The first line contains a...
apps_data_4510
The only difference between easy and hard versions are constraints on $n$ and $k$. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most $k$ most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations eq...
apps_data_4511
You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game. The boss battle consists of $n$ turns. During each turn, you will get several cards. Each card has two parameters: its cost $c_i$ and damage $d_i$. You may play some of your cards during each ...
apps_data_4512
You are given a string $s$ consisting of lowercase Latin letters and $q$ queries for this string. Recall that the substring $s[l; r]$ of the string $s$ is the string $s_l s_{l + 1} \dots s_r$. For example, the substrings of "codeforces" are "code", "force", "f", "for", but not "coder" and "top". There are two types o...
apps_data_4513
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here. The picture showing the correct sudoku solution: [Image] Blocks are bordered with bold black color. Your task is to change at most $9$ elements of this field (i.e. choose some $1 \le i, j \le 9$ ...
apps_data_4514
In this problem you will have to help Berland army with organizing their command delivery system. There are $n$ officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer $a$ is the direct superior of off...
apps_data_4515
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has $a$ coins, Barbara has $b$ coins and Cerene has $c$ coins. Recently Polycarp has returned from the trip around the world and brought $n$ coins. He wants to distribute all these $n$ coins between his sisters in such a...
apps_data_4516
Let's define $p_i(n)$ as the following permutation: $[i, 1, 2, \dots, i - 1, i + 1, \dots, n]$. This means that the $i$-th permutation is almost identity (i.e. which maps every element to itself) permutation but the element $i$ is on the first position. Examples: $p_1(4) = [1, 2, 3, 4]$; $p_2(4) = [2, 1, 3, 4]$; $p_...
apps_data_4517
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_i$ distinct vertices $v_i[1], v_i[2], \dots, v_i[k_i]$. Your task...
apps_data_4518
There are $n$ districts in the town, the $i$-th district belongs to the $a_i$-th bandit gang. Initially, no districts are connected to each other. You are the mayor of the city and want to build $n-1$ two-way roads to connect all districts (two districts can be connected directly or through other connected districts)....
apps_data_4519
You are given a binary string of length $n$ (i. e. a string consisting of $n$ characters '0' and '1'). In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given one if you can perform no more than $k$ moves? It is possible that y...
apps_data_4520
The only difference between easy and hard versions is constraints. You are given $n$ segments on the coordinate axis $OX$. Segments can intersect, lie inside each other and even coincide. The $i$-th segment is $[l_i; r_i]$ ($l_i \le r_i$) and it covers all integer points $j$ such that $l_i \le j \le r_i$. The integer...
apps_data_4521
There are $n$ points on a coordinate axis $OX$. The $i$-th point is located at the integer point $x_i$ and has a speed $v_i$. It is guaranteed that no two points occupy the same coordinate. All $n$ points move with the constant speed, the coordinate of the $i$-th point at the moment $t$ ($t$ can be non-integer) is calc...
apps_data_4522
You are given a weighted tree consisting of $n$ vertices. Recall that a tree is a connected graph without cycles. Vertices $u_i$ and $v_i$ are connected by an edge with weight $w_i$. You are given $m$ queries. The $i$-th query is given as an integer $q_i$. In this query you need to calculate the number of pairs of ver...
apps_data_4523
You are given the array $a$ consisting of $n$ positive (greater than zero) integers. In one move, you can choose two indices $i$ and $j$ ($i \ne j$) such that the absolute difference between $a_i$ and $a_j$ is no more than one ($|a_i - a_j| \le 1$) and remove the smallest of these two elements. If two elements are equ...
apps_data_4524
You are given two huge binary integer numbers $a$ and $b$ of lengths $n$ and $m$ respectively. You will repeat the following process: if $b > 0$, then add to the answer the value $a~ \&~ b$ and divide $b$ by $2$ rounding down (i.e. remove the last digit of $b$), and repeat the process again, otherwise stop the process....
apps_data_4525
You are given a positive integer $n$, it is guaranteed that $n$ is even (i.e. divisible by $2$). You want to construct the array $a$ of length $n$ such that: The first $\frac{n}{2}$ elements of $a$ are even (divisible by $2$); the second $\frac{n}{2}$ elements of $a$ are odd (not divisible by $2$); all elements of...
apps_data_4526
Pay attention to the non-standard memory limit in this problem. In order to cut off efficient solutions from inefficient ones in this problem, the time limit is rather strict. Prefer to use compiled statically typed languages (e.g. C++). If you use Python, then submit solutions on PyPy. Try to write an efficient solut...
apps_data_4527
You are given $n$ segments on a coordinate axis $OX$. The $i$-th segment has borders $[l_i; r_i]$. All points $x$, for which $l_i \le x \le r_i$ holds, belong to the $i$-th segment. Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments i...
apps_data_4528
New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $h$ hours and $m$ minutes, where $0 \le hh < 24$ and $0 \le mm < 60$. We use 24-hour time format! Your task is to find the number of minutes before the New Year. You know that New Year co...
apps_data_4529
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' (left): means that the robot moves from the point $(x, y)$ to the poin...
apps_data_4530
You have $n$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $i$-th student skill is denoted by an integer $a_i$ (different students can have the same skills). So, about the teams. Firstly, these two teams should have...
apps_data_4531
You are given a tree consisting exactly of $n$ vertices. Tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a value $a_v$ assigned to it. Let $dist(x, y)$ be the distance between the vertices $x$ and $y$. The distance between the vertices is the number of edges on the simple path b...
apps_data_4532
You are given an array $a$ consisting of $n$ positive integers. Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $...
apps_data_4533
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size sj. If sj >= gi, we can assign the cookie j to the...
apps_data_4534
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0. In Pascal's triangle, each number is the sum of the two numbers directly above it. Example: Input: 3 Output: [1,3,3,1] Follow up: Could you optimize your algorithm to use only O(...
apps_data_4535
Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). Note: Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as...
apps_data_4536
Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit. You may assume the integer does not contain any leading zero, except the number 0...
apps_data_4537
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. -----Constraints----- - -1000 \leq A,B \leq 1000 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: A B -----Output----- Print the largest value among A+B, A-B and ...
apps_data_4538
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i). Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there? We remind you that the distance between the origin and the point (p, q) can be represented as \sq...
apps_data_4539
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. -----Constraints----- - 1?N?10^8 - N is an integer. -----Input----- Input is given from Standard Input in the following f...
apps_data_4540
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from ...
apps_data_4541
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: a, e, i, o and u. -----Constraints----- - c is a lowercase English letter. -----Input----- The input is given from Standard Input in the following format: c -----Output----- If c is a vowel, pri...
apps_data_4542
Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones b...
apps_data_4543
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number. -----Constraints----- - 1 ≤ a,b ≤ 100 - a and b are integers. -----Input----- Input is given from Standard Input in the following format: a b -----Output----- If the concaten...
apps_data_4544
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 a_i=X. Maximize this count by making optimal choices. -----Constraints----- - 1≤N...
apps_data_4545
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black? -----Constraints----- - 1 \leq N \leq 100 - 0 \leq A \leq N^2 -----Inputs----- Input is given from Standard Input in the following format: N A ...
apps_data_4546
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful. -----Constraints----- - 1 \leq a,b,...
apps_data_4547
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N? -----Constraints----- - 10≤N≤99 -----Input----- Input is given from Standard Input in the following format: N -----Output----- If 9 is contained in the decimal notation of N, print ...
apps_data_4548
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a co...
apps_data_4549
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i,...
apps_data_4550
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note t...
apps_data_4551
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and pla...
apps_data_4552
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those p...
apps_data_4553
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -, and the other characters are digits from 0 through 9. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom. -----Constraints----- - 1≤A,B≤5 - |S|=A+B+1 - S consists of - and...
apps_data_4554
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and the second rectangle covers the vertical range of [1,2] and the ho...
apps_data_4555
Print all the integers that satisfies the following in ascending order: - Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers. -----Constraints----- - 1 \leq A \leq B \leq 10^9 - 1 \leq K \leq 100 - All values in input are integers. -----Inp...
apps_data_4556
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the upper...
apps_data_4557
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals. -----Constraints----- - 1 \leq A \leq 100 - 1 \leq B \leq 100 - 1 \leq X \leq 200 - All val...
apps_data_4558
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds? -----Constraints----- - 1≤X≤10^9 - 1≤t≤10^9 - X and t are integers. -----I...
apps_data_4559
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print -1 instead. -----Constraints----- - 2 \leq N \leq 10^5 - 0 \leq A_i \leq 10^{18} - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N A_1 ......
apps_data_4560
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins. -----Constraints----- - N is an integer between 1 and 10000 (inclusive). - A is an integer between 0 and 1000 (inclusive). -----Input----- Input is given from Standard Input in the following f...
apps_data_4561
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Oth...
apps_data_4562
Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer. -----Constraints----- - 1 \leq N \leq 10^9 - N is an integer. -----Input----- Input is given from Standard Input in the following format: N -----Output----- Print the largest squ...
apps_data_4563
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he c...
apps_data_4564
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different. -----Constraints----- - 2 ≤ |S| ≤ 26, where |S| denotes the length of S. - S consists of lowercase English letters. -----Input----- Input is given from Standard Input in the following format: S...
apps_data_4565
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = E, and west if S_i = W. You will appoint one of the N people as the leader, then command the rest of them to ...
apps_data_4566
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city? -----Constraints----- - 2≤N,M≤50 - 1≤a_i,b_i≤N - a_i ≠ b_i - All i...
apps_data_4567
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When...
apps_data_4568
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when ...
apps_data_4569
The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ... Given is a string S representing the weather in the town today. Predict the weather tomorrow. -----Constraints----- - S is Sunny, Cloudy, or Rainy. -----Input----- Input is given from Standard ...
apps_data_4570
You are parking at a parking lot. You can choose from the following two fee plans: - Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. - Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours. -----Constraints----- - 1≤N≤20 - 1≤A≤1...
apps_data_4571
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is YES or NO. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M ...
apps_data_4572
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print None instead. -----Constraints----- - 1 \leq |S| \leq 10^5 (|S| is the length of string S.) - ...
apps_data_4573
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ......
apps_data_4574
We have N sticks with negligible thickness. The length of the i-th stick is A_i. Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle. -----Constraints----- - 4 \leq N \leq 10^5 - 1 \leq...
apps_data_4575
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X ...
apps_data_4576
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coi...
apps_data_4577
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. -----Constraints----- - -100≤A,B,C≤100 - A, B and C are all integers. -----Input----- Input is given from Standard Input in the following format: A B C -----Output----- If the condition is satisfied, print Ye...
apps_data_4578
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams o...
apps_data_4579
You drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i. How many kinds of items did you get? -----Constraints----- - 1 \leq N \leq 2\times 10^5 - S_i consists of lowercase English letters and has a length between 1 and 10 (inclusive). -----Input----- Input is given from ...
apps_data_4580
In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows: - Rating 1-399 : gray - Rating 400-799 : brown - Rating 800-1199 : green - Rating 1200-1599 : cyan - Rating 1600-1999 : blue - Rating 2000-2399 : yellow - Rating 2400-2799 : orange - R...
apps_data_4581
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is t...
apps_data_4582
Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either H or D, and carries the following information: If a=H, AtCoDeer is h...
apps_data_4583
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds. The given input gua...
apps_data_4584
A company has N members, who are assigned ID numbers 1, ..., N. Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number. When a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X. You are given the information tha...
apps_data_4585
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be a...
apps_data_4586
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good. You are given a 4-digit integer N. Answer the question: Is N good? -----Constraints----- - 1000 ≤ N ≤ 9999 - N is an integer. -----Input----- Input is given from Standard Input in the following format: N -----Output----- If N...
apps_data_4587
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper p...
apps_data_4588
In programming, hexadecimal notation is often used. In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters A, B, C, D, E and F are used to represent the values 10, 11, 12, 13, 14 and 15, respectively. In this problem, you are given two letters X and Y. Each X and Y is A, B, C, D, E or F. When X a...
apps_data_4589
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). . stands for an empty square, and # stands for a square containing ...
apps_data_4590
We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it. It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M). Consider the following action: - Choo...
apps_data_4591
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the curr...
apps_data_4592
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7. -----Constraints----- - 1≤N≤10^3 -----Input----- The input is given from Standard Input in the following format: N -----Output----- Print the number of the positive divisors of N!, modulo 10^9+7. -----Sample Input----- 3 --...
apps_data_4593
You are given a positive integer X. Find the largest perfect power that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2. -----Constraints----- - 1 ≤ X ≤ 1000 - X is an integer. -----Input----- Input is given ...
apps_data_4594
An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have...
apps_data_4595
Snuke has decided to construct a string that starts with A and ends with Z, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A and ends with Z. ...
apps_data_4596
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: - Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform. -----Constraints----- - 1 ...
apps_data_4597
Snuke loves working out. He is now exercising N times. Before he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7. -----Constraints----- - 1 ...
apps_data_4598
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total? -----Constraints----- - 1≦N≦100 -----Input----- The input is given...
apps_data_4599
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the car...