name
stringlengths
2
112
description
stringlengths
29
13k
private_tests
dict
public_tests
dict
generated_tests
dict
lastride
Problem description. Toretto has no friends. He has got family, and now they need him. His bitter enemy, Ian Shaw, has captured Toretto's beloved Letty and evil cooks in his head. All Toretto has is the algorithmic message Shaw left before leaving- Letty(n): L = an empty list while n > 0: find the larg...
{ "input": [], "output": [] }
{ "input": [ "2\n1 2\n3 10" ], "output": [ "3\n25" ] }
{ "input": [], "output": [] }
pd32
Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := fn-1 + fn-2 (n ≥ 3) Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a,b]. Input The input contains several test cases. Each test case consists of two non-negative integer numbers a and b. Input is...
{ "input": [], "output": [] }
{ "input": [ "10 100\n1234567890 9876543210\n0 0" ], "output": [ "5\n4" ] }
{ "input": [], "output": [] }
stfm
For positive integer x let define function F(x) = 1 * (1! + x) + 2 * (2! + x) + .. + x * (x! + x). "k!" means factorial: k! = 1 * 2 * .. * k Chef wants to calculate F(p1) + F(p2) + ... + F(pn). As answer could be large, help him, calculate value modulo m. Input First line contains two integers n and m. Next line c...
{ "input": [], "output": [] }
{ "input": [ "5 7\n1 2 3 4 5" ], "output": [ "6" ] }
{ "input": [ "5 7\n1 2 3 4 4", "5 13\n1 2 3 4 4", "5 13\n1 2 0 4 4", "5 7\n1 2 3 4 3", "5 13\n1 4 3 4 4", "5 13\n1 3 0 4 4", "5 13\n1 3 0 4 6", "5 7\n1 0 0 5 4", "5 6\n0 2 4 4 6", "1 13\n1 17 0 4 6", "5 17\n1 6 0 4 3", "1 20\n1 17 2 0 6", "1 10\n1 23 3 0 6", "0 ...
1165_E. Two Arrays and Sum of Functions
You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo...
{ "input": [], "output": [] }
{ "input": [ "1\n1000000\n1000000\n", "5\n1 8 7 2 4\n9 7 2 9 3\n", "2\n1 3\n4 2\n" ], "output": [ "757402647\n", "646\n", "20\n" ] }
{ "input": [ "1\n1000010\n1000000\n", "5\n1 8 7 2 4\n9 11 2 9 3\n", "2\n1 3\n4 1\n", "1\n1000011\n1000000\n", "5\n1 8 7 2 5\n9 11 2 9 3\n", "2\n1 5\n4 1\n", "1\n1001011\n1000000\n", "5\n1 11 7 2 5\n9 11 2 9 3\n", "2\n1 9\n4 1\n", "1\n1101011\n1000000\n", "5\n1 11 7 3 5\n9 1...
ac-or-cooler
This summer is very hot in KGP. As the hostel rooms do not have coolers or ACs, it's even more difficult for the students. So, the management has decided to install a cooler or an AC in some of the rooms. There are N rooms in KGP. The management has alloted a budget of M units. There are N types of coolers and AC. But...
{ "input": [], "output": [] }
{ "input": [ "5 10\n2 5 2 2 10\n2 1 4 1 9\n\nSAMPLE" ], "output": [ "5" ] }
{ "input": [ "5 10\n2 5 2 2 10\n2 1 7 1 9\n\nSAMPLE", "5 10\n2 8 4 2 10\n2 4 7 1 9\n\nTAMPLE", "6 10\n2 5 1 2 0\n4 2 14 1 9\n\nDAMQLS", "5 4\n2 6 2 2 10\n3 2 7 1 9\n\nELPMAT", "5 4\n2 6 0 2 10\n3 2 7 1 9\n\nEMPMAT", "5 0\n2 6 2 2 20\n2 1 4 1 9\n\nSAMPLE", "10 20\n3 5 2 2 45\n6 0 11 0 8\n\n...
fun-with-primes-3
A prime number is one which is divisible by exactly two numbers 1 and itself. Given a number, find out if the number obtained by summing all digits of that number is a prime. Input Format: The input begins with number of test-cases t in a single line. In each of next tlines there is a number n. Output Format In each ...
{ "input": [], "output": [] }
{ "input": [ "2\n33\n122\n\nSAMPLE" ], "output": [ "NO\nYES\n" ] }
{ "input": [ "2\n33\n122\n\nSAMPLD", "2\n14\n122\n\nSAMPLD", "2\n14\n206\n\nSAMPLD", "2\n6\n206\n\nSAMPLD", "2\n6\n206\n\nSAMPKD", "2\n7\n206\n\nSAMPKD", "2\n7\n244\n\nSAMPKD", "2\n3\n244\n\nSAMPKD", "2\n3\n484\n\nSAMPKD", "2\n5\n484\n\nSAMPKD", "2\n5\n484\n\nKAMPSD", "...
rhezo-and-prime-problems
Rhezo and his friend Vanya love problem solving. They have a problem set containing N problems, with points assigned to each. Rhezo wants to solve problems in such a way that he gets the maximum number of points. Rhezo has a weird habit of solving only prime number of consecutive problems, that is, if he solves X conse...
{ "input": [], "output": [] }
{ "input": [ "4\n8 1 3 7\n\nSAMPLE" ], "output": [ "12" ] }
{ "input": [ "4\n8 2 3 7\n\nSAMPLE", "4\n8 0 3 7\n\nELPMAS", "4\n8 0 2 7\n\nELPMAS", "4\n8 -1 2 7\n\nELPMAS", "4\n8 -2 2 10\n\nELPMAS", "4\n8 -2 1 0\n\nELPMAS", "4\n8 -3 1 0\n\nELPMAS", "4\n1 -3 1 0\n\nELPMAS", "4\n1 -3 1 1\n\nELPMAS", "4\n1 -4 2 1\n\nELPMAS", "4\n0 -12 3 1...
trick-with-the-cards
Mr. X is performing a trick with the cards. He has N cards, lets name them 1.....N, on a round table. So card 1 is in between 2nd card and Nth card. Initially all cards are upside down. His trick involves making all cards face up. His trick is whenever he taps on a card, it flips (if card was originally upside down,...
{ "input": [], "output": [] }
{ "input": [ "2\n2\n3\n\nSAMPLE" ], "output": [ "1\n1\n" ] }
{ "input": [ "2\n2\n3\n\nSAMPME", "2\n2\n5\n\nSAMPME", "2\n0\n5\n\nEMPMAS", "2\n0\n2\n\nEMPMAS", "2\n2\n0\n\nSAMPME", "2\n0\n0\n\nEMPMAS", "2\n6\n5\n\nENPM@T", "2\n0\n4\n\nSMMPAE", "2\n11\n5\n\nENPM@T", "2\n0\n8\n\nSMMPAE", "2\n19\n5\n\nENPM@T", "2\n19\n4\n\nENPM@T", ...
p02578 AtCoder Beginner Contest 176 - Step
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a ...
{ "input": [], "output": [] }
{ "input": [ "5\n3 3 3 3 3", "5\n2 1 5 4 3" ], "output": [ "0", "4" ] }
{ "input": [ "5\n1 3 3 3 3", "5\n2 1 5 8 3", "5\n1 2 3 6 3", "5\n2 1 2 8 4", "5\n2 1 2 16 6", "5\n2 1 1 16 6", "5\n4 4 3 6 6", "5\n0 1 1 16 6", "5\n4 4 3 7 6", "5\n0 0 1 19 6", "5\n0 0 1 19 4", "5\n0 0 1 10 2", "5\n0 0 1 14 0", "5\n3 1 5 8 3", "5\n0 1 2 8 4"...
p02709 AtCoder Beginner Contest 163 - Active Infants
There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child...
{ "input": [], "output": [] }
{ "input": [ "4\n1 3 4 2", "6\n8 6 9 1 2 1", "6\n5 5 6 1 1 1" ], "output": [ "20", "85", "58" ] }
{ "input": [ "4\n1 4 4 2", "6\n8 6 11 1 2 1", "6\n5 5 6 0 1 1", "4\n1 8 4 2", "6\n8 6 22 1 2 1", "6\n5 5 9 0 1 1", "4\n2 8 4 2", "6\n8 6 22 1 1 1", "6\n5 0 9 0 1 1", "6\n8 6 33 1 1 1", "6\n5 0 9 0 0 1", "4\n4 8 4 1", "6\n8 10 33 1 1 1", "6\n5 0 6 0 1 1", "6\...
p02838 AtCoder Beginner Contest 147 - Xor Sum 4
We have N integers. The i-th integer is A_i. Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7). What is \mbox{ XOR }? The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows: * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if eith...
{ "input": [], "output": [] }
{ "input": [ "3\n1 2 3", "10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820", "10\n3 1 4 1 5 9 2 6 5 3" ], "output": [ "6", "103715602", "237" ] }
{ "input": [ "3\n1 2 1", "10\n1 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820", "10\n3 1 4 1 5 9 2 6 5 6", "3\n1 4 1", "10\n1 14 159 2653 58979 376446 2643383 27950288 419716939 9375105820", "10\n3 1 4 1 5 9 2 6 5 2", "10\n1 14 159 2653 58979 376446 2643383 33596518 419716...
p02975 AtCoder Grand Contest 035 - XOR Circle
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No...
{ "input": [], "output": [] }
{ "input": [ "3\n1 2 3", "4\n1 2 4 8" ], "output": [ "Yes", "No" ] }
{ "input": [ "3\n1 2 0", "3\n3 2 1", "4\n1 2 4 11", "3\n0 2 0", "4\n0 2 4 11", "3\n0 1 0", "4\n0 4 4 11", "3\n0 1 -1", "4\n0 4 4 20", "3\n1 2 1", "4\n0 4 1 20", "3\n2 2 1", "4\n0 4 1 33", "4\n0 4 1 63", "3\n3 4 1", "4\n0 4 1 39", "3\n3 7 1", "4\n...
p03111 AtCoder Beginner Contest 119 - Synthetic Kadomatsu
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 MP (magic point)....
{ "input": [], "output": [] }
{ "input": [ "8 1000 800 100\n300\n333\n400\n444\n500\n555\n600\n666", "5 100 90 80\n98\n40\n30\n21\n80", "8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n80" ], "output": [ "243", "23", "0" ] }
{ "input": [ "8 1100 800 100\n300\n333\n400\n444\n500\n555\n600\n666", "5 100 171 80\n98\n40\n30\n21\n80", "8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n20", "8 1100 800 100\n297\n333\n400\n444\n500\n555\n600\n666", "5 100 171 80\n68\n40\n30\n21\n80", "8 100 90 110\n100\n100\n90\n90\n90\n80\n80\...
p03258 AtCoder Grand Contest 027 - ABBreviate
There is a string s consisting of `a` and `b`. Snuke can perform the following two kinds of operation any number of times in any order: * Choose an occurrence of `aa` as a substring, and replace it with `b`. * Choose an occurrence of `bb` as a substring, and replace it with `a`. How many strings s can be obtained b...
{ "input": [], "output": [] }
{ "input": [ "babbabaaba", "ababababa", "aaaa", "aabb" ], "output": [ "35", "1", "6", "5" ] }
{ "input": [ "babbaababa", "bbabababa", "aaba", "ababbbaba", "baba", "ababbbbba", "abbabbaba", "abaababbab", "abaaababa", "baabaababa", "bbabaabbab", "ababbbabb", "aaab", "abaabbaba", "abaaaabbab", "baababbaba", "bbabbabbab", "abbbababa", "ba...
p03414 AtCoder Regular Contest 092 - Two Faced Edges
You are given a directed graph with N vertices and M edges. The vertices are numbered 1, 2, ..., N, and the edges are numbered 1, 2, ..., M. Edge i points from Vertex a_i to Vertex b_i. For each edge, determine whether the reversion of that edge would change the number of the strongly connected components in the graph...
{ "input": [], "output": [] }
{ "input": [ "2 2\n1 2\n2 1", "5 9\n3 2\n3 1\n4 1\n4 2\n3 5\n5 3\n3 4\n1 2\n2 5", "3 3\n1 2\n1 3\n2 3" ], "output": [ "diff\ndiff", "same\nsame\nsame\nsame\nsame\ndiff\ndiff\ndiff\ndiff", "same\ndiff\nsame" ] }
{ "input": [ "5 9\n5 2\n3 1\n4 1\n4 2\n3 5\n5 3\n3 4\n1 2\n2 5", "3 2\n1 2\n1 3\n2 3", "6 3\n1 2\n1 3\n2 3", "5 9\n3 2\n3 1\n4 1\n4 2\n3 5\n5 3\n5 4\n1 2\n4 5", "3 2\n1 2\n2 1", "6 3\n1 2\n1 3\n4 3", "5 9\n5 2\n3 1\n4 1\n4 2\n3 5\n5 3\n3 4\n1 2\n1 5", "5 9\n3 2\n3 2\n4 1\n4 2\n3 5\n5 3...
p03574 AtCoder Beginner Contest 075 - Minesweeper
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 containin...
{ "input": [], "output": [] }
{ "input": [ "3 5\n.....\n.#.#.\n.....", "3 5", "6 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#..." ], "output": [ "11211\n1#2#1\n11211", "", "3\n8#7##\n5#\n4#65#2\n5##21\n4#310" ] }
{ "input": [ "3 7\n.....\n.#.#.\n.....", "6 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...", "12 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...", "11 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...", "2 5\n.....\n.#.#.\n.....", "21 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...", "16 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...", ...
p03729 AtCoder Beginner Contest 060 - Shiritori
You are given three strings A, B and C. Check whether they form a word chain. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`....
{ "input": [], "output": [] }
{ "input": [ "a a a", "rng gorilla apple", "aaaaaaaaab aaaaaaaaaa aaaaaaaaab", "yakiniku unagi sushi" ], "output": [ "YES", "YES", "NO", "NO" ] }
{ "input": [ "a a `", "baaaa`aaaa aabaaaaaaa aaaaa`aaab", "rnh gorilla apple", "aaaaaaaaab aaaaaaaaaa aaaaa`aaab", "ybkiniku unagi sushi", "a b a", "rng gorilla paple", "aaaaaaaaab aaaaaaaaaa baaa`aaaaa", "ybkiniku inagu sushi", "a b `", "rnh gorilla paple", "aaaaaaaaab...
p03893 CODE FESTIVAL 2016 Relay (Parallel) - Trichotomy
We have a cord whose length is a positive integer. We will perform the following condition until the length of the cord becomes at most 2: * Operation: Cut the rope at two positions to obtain three cords, each with a length of a positive integer. Among these, discard one with the longest length and one with the shorte...
{ "input": [], "output": [] }
{ "input": [ "2" ], "output": [ "14" ] }
{ "input": [ "3", "1", "6", "4", "8", "10", "9", "16", "11", "18", "31", "7", "43", "15", "20", "5", "26", "38", "13", "17", "23", "12", "19", "33", "24", "21", "51", "44", "32", "37", "22", ...
p04052 AtCoder Grand Contest 001 - Wide Swap
You are given a permutation P_1 ... P_N of the set {1, 2, ..., N}. You can apply the following operation to this permutation, any number of times (possibly zero): * Choose two indices i,j (1 ≦ i < j ≦ N), such that j - i ≧ K and |P_i - P_j| = 1. Then, swap the values of P_i and P_j. Among all permutations that can...
{ "input": [], "output": [] }
{ "input": [ "8 3\n4 5 7 8 3 1 2 6", "5 1\n5 4 3 2 1", "4 2\n4 2 3 1" ], "output": [ "1\n2\n6\n7\n5\n3\n4\n8", "1\n2\n3\n4\n5", "2\n1\n4\n3" ] }
{ "input": [ "4 4\n4 2 3 1", "5 2\n5 4 3 2 1", "4 1\n4 2 3 1", "8 2\n4 5 7 8 3 1 2 6", "4 2\n4 3 2 1", "8 6\n4 5 7 8 3 1 2 6", "8 5\n4 5 7 8 3 1 2 6", "8 1\n4 5 7 8 3 1 2 6", "8 4\n4 5 7 8 3 1 2 6", "4 3\n4 1 3 2", "5 4\n4 5 3 2 1", "4 2\n4 1 3 2", "4 3\n3 2 4 1", ...
p00131 Doctor's Strange Particles
Dr .: Peter. I did. Peter: See you again? What kind of silly invention is this time? Dr .: You invented the detector for that phantom elementary particle axion. Peter: Speaking of Axion, researchers such as the European Organization for Nuclear Research (CERN) are chasing with a bloody eye, aren't they? Is that true...
{ "input": [], "output": [] }
{ "input": [ "1\n0 1 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 1 1 0 0 0 0\n0 0 0 1 0 0 1 0 0 0\n0 0 0 0 1 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 0 1 0" ], "output": [ "0 0 0 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n...
{ "input": [ "1\n0 1 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 0 0 0\n0 0 0 1 0 0 1 0 0 0\n0 0 0 0 1 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 0 1 0", "1\n0 1 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0\n1 1 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 0...
p00264 East Wind
I decided to move and decided to leave this place. There is nothing wrong with this land itself, but there is only one thing to worry about. It's a plum tree planted in the garden. I was looking forward to this plum blooming every year. After leaving here, the fun of spring will be reduced by one. Wouldn't the scent of...
{ "input": [], "output": [] }
{ "input": [ "6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 6\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0" ], "output": [ "5 6\nNA" ] }
{ "input": [ "6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 11\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0", "6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 14\n3 -4\n-3 0\n2 -2\n45 11\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0", "...
p00451 Common Sub-String
problem Given two strings, find the longest of the strings contained in both strings and write a program that answers that length. Here, the string s included in the string t means that s appears consecutively in t. An empty string, that is, a string of length 0, is included in any string. For example, the string ABR...
{ "input": [], "output": [] }
{ "input": [ "None", "ABRACADABRA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV" ], "output": [ "None", "5\n0" ] }
{ "input": [ "Nnne", "ABRACADAARA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV", "DBRACAAAARA\nECADADBBRBCRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBZDFOEV", "DBRACAAAARA\nECADADBBRBBRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBFDZOEU", "DBRACAAA@RA\nECADADBBRBBRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBFDZOEU", "CARB...
p00642 Ben Toh
As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while other...
{ "input": [], "output": [] }
{ "input": [ "1\n2\n3\n0" ], "output": [ "1.00000000\n1.50000000\n2.12500000" ] }
{ "input": [ "1\n2\n4\n0", "1\n4\n4\n0", "1\n4\n7\n0", "1\n4\n12\n0", "1\n4\n22\n0", "1\n2\n6\n0", "1\n2\n2\n0", "1\n4\n11\n0", "1\n4\n20\n0", "1\n0\n6\n0", "1\n1\n4\n0", "1\n6\n11\n0", "1\n4\n38\n0", "1\n1\n6\n0", "1\n4\n67\n0", "1\n4\n74\n0", "1\n2...
p00786 BUT We Need a Diagram
Consider a data structure called BUT (Binary and/or Unary Tree). A BUT is defined inductively as follows: * Let l be a letter of the English alphabet, either lowercase or uppercase (n the sequel, we say simply "a letter"). Then, the object that consists only of l, designating l as its label, is a BUT. In this case, it...
{ "input": [], "output": [] }
{ "input": [ "a(A,b(B,C));\nx( y( y( z(z), v( s, t ) ) ), u ) ;\n\na( b( c,\n d(\n e(f),\n g\n )\n ),\n h( i(\n j(\n k(k,k),\n l(l)\n ),\n m(m)\n )\n )\n );\n\na(B(C),d(e(f(g(h(i(j,k),l),m),n),o),p))\n.", "a(A,b(B,C));\nx(...
{ "input": [ "a(A,b(B,C));\nx( y( y( z(z), v( s, t ) ) ), u ) ;\n\na( b( c,\n d(\n e(f),\n g\n )\n ),\n g( i(\n j(\n k(k,k),\n l(l)\n ),\n m(m)\n )\n )\n );\n\na(B(C),d(e(f(g(h(i(j,k),l),m),n),o),p))\n.", "a(A,b(B,C));\nx(...
p00918 Dragon's Cruller
Dragon's Cruller is a sliding puzzle on a torus. The torus surface is partitioned into nine squares as shown in its development in Figure E.1. Here, two squares with one of the sides on the development labeled with the same letter are adjacent to each other, actually sharing the side. Figure E.2 shows which squares are...
{ "input": [], "output": [] }
{ "input": [ "4 9\n6 3 0\n8 1 2\n4 5 7\n6 3 0\n8 1 2\n4 5 7\n31 31\n4 3 6\n0 1 5\n8 2 7\n0 3 6\n4 1 5\n8 2 7\n92 4\n1 5 3\n4 0 7\n8 2 6\n1 5 0\n4 7 3\n8 2 6\n12 28\n3 4 5\n0 2 6\n7 1 8\n5 7 1\n8 6 2\n0 3 4\n0 0" ], "output": [ "0\n31\n96\n312" ] }
{ "input": [ "6 9\n6 3 0\n8 1 2\n4 5 7\n6 3 0\n8 1 2\n4 5 7\n31 31\n4 3 6\n0 1 5\n8 2 7\n0 3 6\n4 1 5\n8 2 7\n92 4\n1 5 3\n4 0 7\n8 2 6\n1 5 0\n4 7 3\n8 2 6\n12 28\n3 4 5\n0 2 6\n7 1 8\n5 7 1\n8 6 2\n0 3 4\n0 0", "4 9\n6 3 0\n8 1 2\n4 5 7\n6 3 0\n8 1 2\n4 5 7\n31 31\n4 3 6\n0 1 5\n8 2 7\n0 3 6\n4 1 5\n8 2 7\n...
p01051 Squid Ink
Problem In recent years, turf wars have frequently occurred among squids. It is a recent squid fighting style that multiple squids form a team and fight with their own squid ink as a weapon. There is still a turf war, and the battlefield is represented by an R × C grid. The squid Gesota, who is participating in the t...
{ "input": [], "output": [] }
{ "input": [ "4 5\nS#...\n.#.#.\n.#.#.\n...#G", "5 5\nSxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxG", "4 5\nS#ooo\no#o#o\no#o#o\nooo#G", "5 5\nS....\n.....\n.....\n.....\n....G", "4 5\nG####\nooxoo\nx#o\nSoooo" ], "output": [ "23", "15", "14", "14", "10" ] }
{ "input": [ "4 5\nS#...\n.#.$.\n.#.#.\n...#G", "5 5\n.S...\n.....\n.....\n.....\n....G", "4 5\nG####\nonxoo\nx#o\nSoooo", "4 5\nS#...\n.#.$.\n.#.#.\nG#../", "4 5\no#ooS\no#o#o\no#o#o\nooo#G", "7 5\nS....\n.....\n.....\n.....\n....G", "4 5\nS#-..\n.#.$.\n.#.$.\n/..#G", "4 5\nG####\npox...
p01183 Tetrahedra
Peter P. Pepper is facing a difficulty. After fierce battles with the Principality of Croode, the Aaronbarc Kingdom, for which he serves, had the last laugh in the end. Peter had done great service in the war, and the king decided to give him a big reward. But alas, the mean king gave him a hard question to try his in...
{ "input": [], "output": [] }
{ "input": [ "7 1 2 2 2 2 2 2\n0" ], "output": [ "0.942809" ] }
{ "input": [ "7 1 2 2 2 2 2 4\n0", "7 1 2 2 1 2 2 0\n0", "7 1 2 3 2 2 2 2\n0", "7 1 2 2 1 2 1 0\n0", "7 1 2 3 2 3 2 2\n0", "7 1 2 3 2 3 4 2\n0", "7 1 2 3 4 3 4 2\n0", "7 1 3 3 4 3 4 2\n0", "7 1 3 0 4 3 4 2\n0", "7 1 3 0 4 3 4 4\n0", "7 1 3 2 2 2 2 0\n0", "7 1 2 3 2 3 2 ...
p01320 Magical Island 2
It was an era when magic still existed as a matter of course. A clan of magicians lived on a square-shaped island created by magic. At one point, a crisis came to this island. The empire has developed an intercontinental ballistic missile and aimed it at this island. The magic of this world can be classified into eart...
{ "input": [], "output": [] }
{ "input": [ "4 4 1\n1 0\n0 1\n-1 0\n0 -1\n5 6 2\n1 1\n4 4\n2 -4\n-4 2\n1 5\n0 0 0" ], "output": [ "1.000000000\n6.797434948" ] }
{ "input": [ "4 4 1\n1 0\n0 1\n-1 0\n0 -1\n5 6 2\n1 1\n4 8\n2 -4\n-4 2\n1 5\n0 0 0", "4 4 1\n0 0\n0 1\n-1 -1\n0 -1\n5 6 2\n1 1\n4 8\n2 -4\n-4 2\n1 5\n0 -1 0", "4 4 1\n0 0\n0 1\n-1 -1\n-1 -1\n5 6 2\n1 1\n4 8\n2 -4\n-4 0\n1 5\n0 -1 0", "4 4 1\n1 0\n0 1\n-1 0\n0 -1\n5 6 2\n1 1\n4 8\n2 -4\n-2 2\n1 5\n0 0 ...
p01488 TransferTrain
Example Input 2 10 Warsaw Petersburg 3 Kiev Moscow Petersburg 150 120 3 Moscow Minsk Warsaw 100 150 Output 380 1
{ "input": [], "output": [] }
{ "input": [ "2 10\nWarsaw Petersburg\n3\nKiev Moscow Petersburg\n150 120\n3\nMoscow Minsk Warsaw\n100 150" ], "output": [ "380 1" ] }
{ "input": [ "2 10\nWarsaw Petersburg\n3\nKiev Moscow grubsreteP\n150 120\n3\nMoscow Minsk Warsaw\n100 150", "2 10\nWarsaw grubsreteP\n3\nKiev Moscow grubsreteP\n231 120\n3\nMoscow Minsk Warsaw\n000 150", "2 10\nWarsaw grubsreteP\n3\nKiev Moscow grubsreteP\n231 120\n3\nMoscow Minsk Warsaw\n000 101", "...
p01650 Stack Maze
Problem Statement There is a maze which can be described as a W \times H grid. The upper-left cell is denoted as (1, 1), and the lower-right cell is (W, H). You are now at the cell (1, 1) and have to go to the cell (W, H). However, you can only move to the right adjacent cell or to the lower adjacent cell. The followi...
{ "input": [], "output": [] }
{ "input": [ "3 3\nac#\nb#C\n.BA\n3 3\naaZ\na#Z\naZZ\n3 3\n..#\n.#.\n#..\n1 50\nabcdefghijklmnopqrstuvwxyYXWVUTSRQPONMLKJIHGFEDCBA\n1 50\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\n1 50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY\n1 50\naaaaaaaaaabbbbbbbbbbcccccCCCCCBBBBBBBBBBAAAAAAAAAA\n10 10\n....
{ "input": [ "3 3\nac#\nb#C\n.BA\n3 3\naaZ\na#Z\naZZ\n3 3\n..\"\n.#.\n#..\n1 50\nabcdefghijklmnopqrstuvwxyYXWVUTSRQPONMLKJIHGFEDCBA\n1 50\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\n1 50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY\n1 50\naaaaaaaaaabbbbbbbbbbcccccCCCCCBBBBBBBBBBAAAAAAAAAA\n10 10\n...
p01801 Wall Making Game
Example Input 2 2 .. .. Output Second
{ "input": [], "output": [] }
{ "input": [ "2 2\n..\n.." ], "output": [ "Second" ] }
{ "input": [ "1 2\n..\n..", "1 0\n..\n..", "1 1\n..\n..", "1 0\n-.\n..", "1 0\n-/\n..", "1 0\n-/\n./", "1 0\n,/\n./", "2 0\n,/\n./", "2 -1\n,/\n./", "2 -1\n/,\n./", "2 -2\n/,\n./", "2 -2\n/-\n./", "2 -2\n/.\n./", "2 -2\n/.\n..", "2 -2\n//\n..", "2 -3\n//...
p01935 Protect from the enemy attack
problem There are $ V $ islands, numbered $ 0, 1, ..., V-1 $, respectively. There are $ E $ bridges, numbered $ 0, 1, ..., E-1 $, respectively. The $ i $ th bridge spans island $ s_i $ and island $ t_i $ and is $ c_i $ wide. The AOR Ika-chan Corps (commonly known as the Squid Corps), which has a base on the island $ ...
{ "input": [], "output": [] }
{ "input": [ "4 4\n0 1 3\n0 2 4\n1 3 1\n2 3 5" ], "output": [ "4" ] }
{ "input": [ "4 4\n0 1 3\n0 2 4\n1 3 1\n0 3 5", "4 8\n0 1 6\n0 2 4\n1 3 1\n0 3 5", "4 4\n0 1 3\n0 2 0\n1 3 1\n2 3 5", "2 15\n0 1 0\n0 1 4\n2 3 0\n0 3 9", "5 8\n0 1 6\n0 0 4\n2 3 4\n1 4 5", "2 15\n0 1 0\n0 1 4\n2 3 0\n0 1 9", "2 15\n0 1 0\n0 2 4\n2 1 0\n0 1 9", "4 9\n0 2 6\n1 2 4\n1 3 2...
p02074 N-by-M grid calculation
Problem Statement Have you experienced $10$-by-$10$ grid calculation? It's a mathematical exercise common in Japan. In this problem, we consider the generalization of the exercise, $N$-by-$M$ grid calculation. In this exercise, you are given an $N$-by-$M$ grid (i.e. a grid with $N$ rows and $M$ columns) with an addit...
{ "input": [], "output": [] }
{ "input": [ "" ], "output": [ "" ] }
{ "input": [], "output": [] }
p02216 Array Game
Problem statement There is a positive integer sequence $ a_1, a_2, \ ldots, a_N $ of length $ N $. Consider the following game, which uses this sequence and is played by $ 2 $ players on the play and the play. * Alternately select one of the following operations for the first move and the second move. * Select a pos...
{ "input": [], "output": [] }
{ "input": [ "2\n1 2" ], "output": [ "First" ] }
{ "input": [ "2\n0 2", "2\n-1 4", "2\n0 4", "2\n0 1", "2\n1 0", "2\n0 7", "2\n-1 2", "2\n2 0", "2\n-1 10", "2\n-2 2", "2\n2 -1", "2\n-2 4", "2\n4 -1", "2\n-2 8", "2\n4 0", "2\n-2 5", "2\n5 0", "2\n1 1", "2\n2 2", "2\n2 4", "2\n4 4", ...
p02369 Cycle Detection for a Directed Graph
Find a cycle in a directed graph G(V, E). Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 1,000 * si ≠ ti Input A directed graph G is given in the following format: |V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 |V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1...
{ "input": [], "output": [] }
{ "input": [ "3 3\n0 1\n0 2\n1 2", "3 3\n0 1\n1 2\n2 0" ], "output": [ "0", "1" ] }
{ "input": [ "5 3\n0 1\n0 2\n1 2", "8 3\n0 1\n0 2\n1 2", "8 3\n0 2\n0 2\n1 2", "5 3\n0 2\n0 2\n1 2", "11 3\n0 1\n0 2\n1 2", "8 2\n0 1\n0 2\n1 2", "8 3\n1 2\n0 2\n1 2", "8 2\n0 1\n0 2\n1 4", "8 2\n0 1\n0 2\n2 4", "8 2\n0 2\n0 2\n2 4", "8 1\n0 2\n0 2\n2 4", "8 1\n0 4\n0 2...
aba15f
Problem description. “Murphy’s Law doesn’t meant that something bad will happen. It means that whatever can happen, will happen.” —Cooper While traveling across space-time,the data sent by NASA to "The Endurance" spaceship is sent in the format of, For...
{ "input": [], "output": [] }
{ "input": [ "5\n100\n23\n4\n1000\n5" ], "output": [ "68\n21\n4\n320\n5" ] }
{ "input": [], "output": [] }
chefch
Chef had a hard day and want to play little bit. The game is called "Chain". Chef has the sequence of symbols. Each symbol is either '-' or '+'. The sequence is called Chain if each two neighboring symbols of sequence are either '-+' or '+-'. For example sequence '-+-+-+' is a Chain but sequence '-+-+--+' is not. H...
{ "input": [], "output": [] }
{ "input": [ "2\n---+-+-+++\n-------" ], "output": [ "2\n3\n" ] }
{ "input": [ "2\n+++-+-+---\n-------", "2\n-+--+++--+\n-------", "2\n-+-+-+-+-+\n-------", "2\n--++---+++\n-----+-", "2\n---+-+-+++\n-----+-", "2\n+-+-+-+--+\n-------", "2\n---+++-+-+\n-------", "2\n-+-+++---+\n-------", "2\n+-+++----+\n-------", "2\n+-+-+++---\n-------", "...
directi
Chef recently printed directions from his home to a hot new restaurant across the town, but forgot to print the directions to get back home. Help Chef to transform the directions to get home from the restaurant. A set of directions consists of several instructions. The first instruction is of the form "Begin on XXX", i...
{ "input": [], "output": [] }
{ "input": [ "2\n4\nBegin on Road A\nRight on Road B\nRight on Road C\nLeft on Road D\n6\nBegin on Old Madras Road\nLeft on Domlur Flyover\nLeft on 100 Feet Road\nRight on Sarjapur Road\nRight on Hosur Road\nRight on Ganapathi Temple Road" ], "output": [ "Begin on Road D\nRight on Road C\nLeft on Road B\n...
{ "input": [ "2\n4\nBegin on Road A\nRight on Road B\nRight on Road C\nLeft on Road D\n6\nBegin on Old Madras daoR\nLeft on Domlur Flyover\nLeft on 100 Feet Road\nRight on Sarjapur Road\nRight on Hosur Road\nRight on Ganapathi Temple Road", "2\n4\nBegin on Roae A\nRight on Road B\nRight on Road C\nLeft on Roa...
insomb1
Modern cryptosystems rely heavily on our inability to factor large integers quickly as the basis for their security. They need a quick and easy way to generate and test for primes. Very often, the primes generated are very large numbers. You need to implement ways to test the primality of very large numbers. Input Lin...
{ "input": [], "output": [] }
{ "input": [ "2760727302517" ], "output": [ "PRIME\n\n" ] }
{ "input": [ "1894408473307", "1693567121009", "743871772032", "1207342155784", "1154588488711", "1798097736639", "3595571189300", "2584084900985", "156458315848", "199154598320", "2006419019646", "2229558751887", "7052041710222", "4231987175090", "212855285...
nfeb4
Buffalo Marketing Gopal wants to make some money from buffalos, but in a quite a different way. He decided that his future lay in speculating on buffalos. In the market in his village, buffalos were bought and sold everyday. The price fluctuated over the year, but on any single day the price was always the same. ...
{ "input": [], "output": [] }
{ "input": [ "2\n3\n1 2 90\n4\n1 3 1 2" ], "output": [ "177\n 3" ] }
{ "input": [], "output": [] }
scores
Mrityunjay is a high-school teacher, currently coaching students for JEE (Joint Entrance Exam). Mrityunjay every year gives prizes to the toppers of JEE in India. A lot of students give this exam in India and it is difficult for him to manually go through results and select two top students from them. So he asked for y...
{ "input": [], "output": [] }
{ "input": [ "3 \n30 30 20", "3 \n12 20 12" ], "output": [ "30 30", "20 12" ] }
{ "input": [ "3 \n30 30 7", "3 \n12 20 16", "3 \n30 40 7", "3 \n12 5 16", "3 \n30 31 7", "3 \n7 5 16", "3 \n30 51 3", "3 \n7 8 16", "3 \n30 26 0", "3 \n30 22 0", "3 \n7 6 2", "3 \n30 8 1", "3 \n7 4 3", "3 \n30 16 1", "3 \n11 4 3", "3 \n11 6 3", "3 \n...
1238_D. AB-string
The string t_1t_2 ... t_k is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some examp...
{ "input": [], "output": [] }
{ "input": [ "5\nAABBB\n", "3\nAAA\n", "7\nAAABABB\n" ], "output": [ "6\n", "3\n", "15\n" ] }
{ "input": [ "3\nABA\n", "7\nBBABAAA\n", "7\nBAAAABB\n", "5\nBBBBA\n", "7\nABABAAB\n", "7\nBBAAABA\n", "3\nBBB\n", "5\nABBAA\n", "5\nABBBA\n", "7\nBAAAAAB\n", "7\nAAAAAAA\n", "3\nBAA\n", "3\nAAB\n", "7\nBBAAAAB\n", "3\nBBA\n", "3\nBAB\n", "7\nABBAAAB...
1450_D. Rating Compression
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers a of length n. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter k, the program takes the minimum of ...
{ "input": [], "output": [] }
{ "input": [ "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 3 4 5 6 7 8 9 10\n3\n3 3 2\n" ], "output": [ "\n10111\n0001\n00111\n1111111111\n000\n" ] }
{ "input": [ "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 1 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 3 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 1 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 3 2 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 2 2\n4\n1 3 2 1\n5\n1 3 3 3...
1474_B. Different Divisors
Positive integer x is called divisor of positive integer y, if y is divisible by x without remainder. For example, 1 is a divisor of 7 and 3 is not divisor of 8. We gave you an integer d and asked you to find the smallest positive integer a, such that * a has at least 4 divisors; * difference between any two di...
{ "input": [], "output": [] }
{ "input": [ "2\n1\n2\n" ], "output": [ "\n6\n15\n" ] }
{ "input": [ "2\n2\n2\n", "2\n2\n3\n", "2\n3\n3\n", "2\n5\n3\n", "2\n5\n6\n", "2\n5\n12\n", "2\n1\n12\n", "2\n1\n4\n", "2\n2\n1\n", "2\n4\n6\n", "2\n5\n15\n", "2\n4\n2\n", "2\n6\n2\n", "2\n8\n6\n", "2\n2\n15\n", "2\n8\n7\n", "2\n2\n14\n", "2\n8\n...
341_D. Iahub and Xors
Iahub does not like background stories, so he'll tell you exactly what this problem asks you for. You are given a matrix a with n rows and n columns. Initially, all values of the matrix are zeros. Both rows and columns are 1-based, that is rows are numbered 1, 2, ..., n and columns are numbered 1, 2, ..., n. Let's den...
{ "input": [], "output": [] }
{ "input": [ "3 5\n2 1 1 2 2 1\n2 1 3 2 3 2\n2 3 1 3 3 3\n1 2 2 3 3\n1 2 2 3 2\n" ], "output": [ "3\n2\n" ] }
{ "input": [ "3 5\n2 1 1 2 2 1\n2 1 3 2 3 4\n2 3 1 3 3 3\n1 2 2 3 3\n1 2 2 3 2\n", "3 5\n2 1 1 2 2 1\n2 1 3 2 3 4\n2 2 1 3 3 3\n1 2 2 3 3\n1 2 2 3 2\n", "3 5\n2 1 1 2 2 0\n2 1 3 2 3 4\n2 2 1 3 3 3\n1 2 2 3 3\n1 2 2 3 2\n", "3 5\n2 1 1 2 2 1\n2 1 3 2 3 4\n2 2 1 3 3 3\n1 2 2 3 1\n1 2 2 3 2\n", "3 5\...
64_C. Table
The integer numbers from 1 to nm was put into rectangular table having n rows and m columns. The numbers was put from left to right, from top to bottom, i.e. the first row contains integers 1, 2, ..., m, the second — m + 1, m + 2, ..., 2 * m and so on. After it these numbers was written on the paper in another order: ...
{ "input": [], "output": [] }
{ "input": [ "3 4 11\n", "20000 10000 200000000\n" ], "output": [ "8\n", "200000000\n" ] }
{ "input": [], "output": [] }
number-theory
Quan_Lank is a great team with some uncommon interests in programming. Sometimes the team loves to solve strings puzzles, sometimes game puzzles and sometimes metrix type puzzles . Yesterday they have added a new interest to their list that is 'number theory' as they have solved some amazing puzzles related to number t...
{ "input": [], "output": [] }
{ "input": [ "2\n1\n10\n\nSAMPLE" ], "output": [ "1\n2" ] }
{ "input": [ "2\n1\n10\n\nSAMQLE", "2\n2\n15\n\nSAMSLE", "2\n2\n2\n\nSAMSLE", "2\n2\n24\n\nSAMSLE", "2\n14\n1\n\nSALPLE", "2\n12\n6\n\nELPMAS", "2\n10\n134\n\nMRL@SD", "2\n4\n378\n\nMRL@SD", "2\n4\n364\n\nMRL@SD", "2\n10\n364\n\nMRL@SD", "2\n10\n279\n\nMRL@SD", "2\n10\n...
raghu-vs-sayan
Raghu and Sayan both like to eat (a lot) but since they are also looking after their health, they can only eat a limited amount of calories per day. So when Kuldeep invites them to a party, both Raghu and Sayan decide to play a game. The game is simple, both Raghu and Sayan will eat the dishes served at the party till ...
{ "input": [], "output": [] }
{ "input": [ "3\n15 20 3\n10 5 4\n3 10 2\n4 7\n10 8 3\n4 5 5\n\nSAMPLE" ], "output": [ "Sayan Won\nSayan Won\nRaghu Won\n" ] }
{ "input": [ "3\n15 20 3\n8 5 4\n3 10 2\n4 7\n10 8 3\n4 5 5\n\nSAMPLE", "3\n15 20 3\n10 5 4\n3 10 2\n4 7\n10 8 3\n2 5 5\n\nSAMPLE", "3\n15 20 3\n13 5 4\n3 10 2\n4 7\n10 8 3\n4 5 5\n\nSAMPLE", "3\n15 7 3\n8 6 4\n3 10 2\n4 7\n10 8 3\n4 5 5\n\nSAMPLE", "3\n15 20 3\n10 5 4\n3 2 2\n4 7\n10 8 3\n2 5 5\n...
p02539 ACL Beginner Contest - Heights and Pairs
There are 2N people numbered 1 through 2N. The height of Person i is h_i. How many ways are there to make N pairs of people such that the following conditions are satisfied? Compute the answer modulo 998,244,353. * Each person is contained in exactly one pair. * For each pair, the heights of the two people in the pai...
{ "input": [], "output": [] }
{ "input": [ "2\n1\n1\n2\n3", "5\n30\n10\n20\n40\n20\n10\n10\n30\n50\n60" ], "output": [ "2", "516" ] }
{ "input": [ "2\n1\n1\n2\n5", "5\n30\n10\n20\n65\n20\n10\n10\n30\n50\n60", "5\n30\n10\n20\n65\n20\n10\n10\n3\n50\n100", "5\n30\n10\n38\n65\n20\n10\n10\n3\n50\n100", "2\n0\n1\n6\n7", "5\n30\n10\n38\n65\n20\n9\n10\n3\n50\n100", "5\n40\n2\n38\n91\n20\n9\n10\n3\n50\n100", "2\n1\n1\n2\n1", ...
p02670 AtCoder Grand Contest 044 - Joker
Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to rig...
{ "input": [], "output": [] }
{ "input": [ "4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "6\n11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "3\n1 3 7 9 5 4 8 6 2" ], "output": [ "3", "11", "1" ] }
{ "input": [ "3\n2 3 7 9 5 4 8 6 1", "3\n1 3 7 9 5 8 4 6 2", "3\n1 6 7 9 5 4 8 3 2", "3\n2 4 7 9 5 3 8 6 1", "3\n1 3 7 9 4 8 5 6 2", "3\n2 3 7 9 5 4 8 6 1" ], "output": [ "0\n", "1\n", "0\n", "0\n", "0\n", "0\n" ] }
p02799 Keyence Programming Contest 2020 - Bichromization
We have a connected undirected graph with N vertices and M edges. Edge i in this graph (1 \leq i \leq M) connects Vertex U_i and Vertex V_i bidirectionally. We are additionally given N integers D_1, D_2, ..., D_N. Determine whether the conditions below can be satisfied by assigning a color - white or black - to each v...
{ "input": [], "output": [] }
{ "input": [ "5 5\n3 4 3 5 7\n1 2\n1 3\n3 2\n4 2\n4 5", "4 6\n1 1 1 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 7\n1 2 3 4 5\n1 2\n1 3\n1 4\n2 3\n2 5\n3 5\n4 5" ], "output": [ "BWWBB\n4\n3\n1\n5\n2", "BBBW\n1\n1\n1\n2\n1\n1", "-1" ] }
{ "input": [ "5 5\n3 4 3 5 7\n1 2\n0 3\n3 2\n4 2\n4 5", "4 6\n1 1 1 1\n1 2\n1 3\n2 4\n2 3\n2 4\n3 4", "5 7\n1 1 3 4 5\n1 2\n1 3\n1 4\n2 3\n2 5\n3 5\n4 5", "4 6\n1 1 2 1\n1 2\n1 3\n2 4\n2 3\n2 4\n3 4", "4 6\n1 1 2 1\n1 2\n2 3\n2 4\n2 3\n2 4\n3 4", "5 7\n1 1 3 4 3\n1 2\n1 3\n1 4\n2 3\n2 5\n1 5\n...
p02935 AtCoder Beginner Contest 138 - Alchemist
You have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \leq i \leq N) is v_i. When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where...
{ "input": [], "output": [] }
{ "input": [ "2\n3 4", "3\n500 300 200", "5\n138 138 138 138 138" ], "output": [ "3.5", "375", "138" ] }
{ "input": [ "2\n1 4", "3\n500 300 210", "5\n138 138 232 138 138", "2\n1 2", "3\n500 105 210", "5\n138 138 232 218 138", "2\n2 4", "3\n500 4 210", "5\n37 138 232 218 138", "3\n500 4 409", "5\n37 138 232 218 25", "2\n3 1", "3\n500 4 478", "5\n37 138 232 218 5", ...
p03072 AtCoder Beginner Contest 124 - Great Ocean View
There are N mountains ranging from east to west, and an ocean to the west. At the top of each mountain, there is an inn. You have decided to choose where to stay from these inns. The height of the i-th mountain from the west is H_i. You can certainly see the ocean from the inn at the top of the westmost mountain. F...
{ "input": [], "output": [] }
{ "input": [ "4\n6 5 6 8", "5\n9 5 6 8 4", "5\n4 5 3 5 4" ], "output": [ "3", "1", "3" ] }
{ "input": [ "4\n6 5 5 8", "5\n9 0 6 8 4", "4\n6 5 8 8", "5\n2 3 3 4 8", "5\n2 3 3 4 2", "5\n4 5 3 1 4", "5\n9 -1 6 8 4", "5\n4 5 3 2 4", "4\n6 5 11 8", "5\n9 -1 4 8 4", "5\n1 5 3 2 4", "4\n12 5 11 8", "5\n9 0 4 8 4", "5\n1 5 3 2 8", "4\n11 5 11 8", "5\n...
p03214 Dwango Programming Contest V - Thumbnail
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of t...
{ "input": [], "output": [] }
{ "input": [ "3\n1 2 3", "4\n2 5 2 5" ], "output": [ "1", "0" ] }
{ "input": [ "3\n0 2 3", "4\n2 5 3 5", "3\n0 0 3", "4\n3 9 3 5", "4\n3 5 3 5", "3\n0 0 1", "4\n5 9 3 5", "4\n5 14 3 5", "4\n5 14 6 5", "4\n0 14 6 5", "4\n0 5 6 5", "4\n0 5 12 5", "4\n0 5 12 2", "4\n0 10 12 2", "4\n0 20 12 2", "4\n0 20 12 1", "4\n0 13...
p03363 AtCoder Grand Contest 023 - Zero-Sum Ranges
We have an integer sequence A, whose length is N. Find the number of the non-empty contiguous subsequences of A whose sums are 0. Note that we are counting the ways to take out subsequences. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from differ...
{ "input": [], "output": [] }
{ "input": [ "7\n1 -1 1 -1 1 -1 1", "5\n1 -2 3 -4 5", "6\n1 3 -4 2 2 -2" ], "output": [ "12", "0", "3" ] }
{ "input": [ "7\n0 -1 1 -1 1 -1 1", "5\n1 -2 5 -4 5", "6\n1 3 -2 2 2 -2", "7\n0 -1 0 -1 1 -1 1", "5\n1 -1 5 -4 5", "7\n0 -1 0 -1 1 -1 0", "7\n0 -1 0 -2 1 -1 0", "7\n0 -1 0 -2 1 0 -1", "6\n0 1 -4 3 0 -2", "7\n0 -1 1 -4 0 0 0", "5\n-2 1 2 2 21", "6\n-1 1 -1 0 0 0", "7...
p03521 CODE FESTIVAL 2017 Exhibition (Parallel) - Awkward
ButCoder Inc. is a startup company whose main business is the development and operation of the programming competition site "ButCoder". There are N members of the company including the president, and each member except the president has exactly one direct boss. Each member has a unique ID number from 1 to N, and the m...
{ "input": [], "output": [] }
{ "input": [ "4\n1\n2\n3", "15\n1\n2\n3\n1\n4\n2\n7\n1\n8\n2\n8\n1\n8\n2", "3\n1\n2", "5\n1\n1\n3\n3" ], "output": [ "2", "97193524", "0", "8" ] }
{ "input": [ "15\n1\n2\n3\n1\n4\n2\n7\n1\n8\n2\n4\n1\n8\n2", "15\n1\n2\n3\n1\n4\n4\n7\n1\n8\n2\n4\n1\n8\n2", "15\n1\n2\n3\n1\n4\n4\n7\n1\n8\n2\n8\n1\n8\n2", "15\n1\n2\n3\n1\n4\n2\n3\n1\n8\n2\n8\n1\n8\n2", "5\n1\n2\n3\n3", "15\n1\n2\n3\n1\n4\n2\n6\n1\n8\n2\n4\n1\n8\n2", "15\n1\n2\n3\n1\n4\n...
p03686 AtCoder Regular Contest 076 - Exhausted?
There are M chairs arranged in a line. The coordinate of the i-th chair (1 ≤ i ≤ M) is i. N people of the Takahashi clan played too much games, and they are all suffering from backaches. They need to sit in chairs and rest, but they are particular about which chairs they sit in. Specifically, the i-th person wishes to...
{ "input": [], "output": [] }
{ "input": [ "6 6\n1 6\n1 6\n1 5\n1 5\n2 6\n2 6", "4 4\n0 3\n2 3\n1 3\n3 4", "7 6\n0 7\n1 5\n3 6\n2 7\n1 6\n2 6\n3 7", "3 1\n1 2\n1 2\n1 2" ], "output": [ "2", "0", "2", "2" ] }
{ "input": [ "6 6\n0 6\n1 6\n1 5\n1 5\n2 6\n2 6", "6 6\n0 6\n1 6\n1 5\n1 5\n2 6\n2 2", "1 1\n1 2\n0 2\n1 2", "11 6\n0 6\n1 6\n1 7\n1 5\n2 6\n2 2", "11 5\n1 6\n1 6\n1 7\n1 5\n2 6\n2 2", "19 5\n1 6\n1 1\n1 7\n1 5\n2 6\n2 2", "9 6\n0 7\n1 5\n3 6\n2 7\n1 3\n2 4\n2 2", "38 5\n2 11\n1 1\n1 7...
p03839 AtCoder Grand Contest 008 - Contiguous Repainting
There are N squares aligned in a row. The i-th square from the left contains an integer a_i. Initially, all the squares are white. Snuke will perform the following operation some number of times: * Select K consecutive squares. Then, paint all of them white, or paint all of them black. Here, the colors of the squares...
{ "input": [], "output": [] }
{ "input": [ "10 5\n5 -4 -5 -8 -4 7 2 -4 0 7", "1 1\n-10", "5 3\n-10 10 -10 10 -10", "4 2\n10 -10 -10 10" ], "output": [ "17", "0", "10", "20" ] }
{ "input": [ "1 1\n-16", "5 3\n-10 10 -18 10 -10", "4 2\n7 -10 -10 10", "4 2\n7 -6 -10 12", "4 2\n7 -6 -10 20", "4 2\n9 -1 -10 20", "4 2\n13 -1 -10 20", "4 2\n3 -1 -10 20", "4 3\n3 -1 -10 20", "4 3\n3 -1 -1 20", "10 5\n5 -4 -5 -8 -4 0 2 -4 0 7", "4 4\n9 -1 -10 20", ...
p04006 AtCoder Grand Contest 004 - Colorful Slimes
Snuke lives in another world, where slimes are real creatures and kept by some people. Slimes come in N colors. Those colors are conveniently numbered 1 through N. Snuke currently has no slime. His objective is to have slimes of all the colors together. Snuke can perform the following two actions: * Select a color i ...
{ "input": [], "output": [] }
{ "input": [ "4 10\n1 2 3 4", "2 10\n1 100", "3 10\n100 1 100" ], "output": [ "10", "12", "23" ] }
{ "input": [ "4 10\n1 1 3 4", "2 10\n1 101", "3 12\n100 1 100", "3 12\n000 1 100", "3 12\n010 1 100", "3 12\n011 1 100", "3 18\n011 1 100", "3 18\n011 2 100", "3 35\n011 2 100", "3 35\n011 4 100", "3 35\n011 4 001", "4 10\n1 2 3 1", "3 7\n100 1 100", "4 10\n1 1 ...
p00092 Square Searching
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output. For example, each dataset is given the f...
{ "input": [], "output": [] }
{ "input": [ "10\n...*....**\n..........\n**....**..\n........*.\n..*.......\n..........\n.*........\n..........\n....*..***\n.*....*...\n10\n****.*****\n*..*.*....\n****.*....\n*....*....\n*....*****\n..........\n****.*****\n*..*...*..\n****...*..\n*..*...*..\n0" ], "output": [ "5\n3" ] }
{ "input": [ "10\n...*....**\n..........\n**....**..\n........*.\n..*.......\n..........\n.*........\n..........\n....*..***\n.*....*...\n10\n*****.****\n*..*.*....\n****.*....\n*....*....\n*....*****\n..........\n****.*****\n*..*...*..\n****...*..\n*..*...*..\n0", "10\n...*....**\n..........\n**....**..\n*.....
p00224 Bicycle Diet
Mr. A loves sweets, but recently his wife has told him to go on a diet. One day, when Mr. A went out from his home to the city hall, his wife recommended that he go by bicycle. There, Mr. A reluctantly went out on a bicycle, but Mr. A, who likes sweets, came up with the idea of ​​stopping by a cake shop on the way to e...
{ "input": [], "output": [] }
{ "input": [ "1 1 2 5\n35\nH L1 5\nC1 D 6\nC1 H 12\nL1 D 10\nC1 L1 20\n2 1 4 6\n100 70\nH L1 5\nC1 L1 12\nC1 D 11\nC2 L1 7\nC2 D 15\nL1 D 8\n0 0 0 0" ], "output": [ "1\n-2" ] }
{ "input": [ "1 1 2 5\n35\nH L1 5\nC1 D 6\nC1 H 12\nL1 D 10\nC1 L1 20\n2 1 4 6\n100 70\nH L1 5\nC1 L1 12\nC1 D 11\nC2 L1 7\nC2 D 10\nL1 D 8\n0 0 0 0", "1 1 2 5\n35\nH L1 5\nC1 D 6\nC1 H 12\nL1 D 10\nC1 L1 0\n2 1 4 6\n100 70\nH L1 5\nC1 L1 12\nC1 D 11\nC2 L1 7\nC2 D 10\nL1 D 8\n0 0 0 0", "1 1 2 5\n35\nH L1...
p00386 Gathering
You are a teacher at Iazu High School is the Zuia Kingdom. There are $N$ cities and $N-1$ roads connecting them that allow you to move from one city to another by way of more than one road. Each of the roads allows bidirectional traffic and has a known length. As a part of class activities, you are planning the follow...
{ "input": [], "output": [] }
{ "input": [ "15 15\n1 2 45\n2 3 81\n1 4 29\n1 5 2\n5 6 25\n4 7 84\n7 8 56\n4 9 2\n4 10 37\n7 11 39\n1 12 11\n11 13 6\n3 14 68\n2 15 16\n10 13 14\n13 14 15\n2 14 15\n7 12 15\n10 14 15\n9 10 15\n9 14 15\n8 13 15\n5 6 13\n11 13 15\n12 13 14\n2 3 10\n5 13 15\n10 11 14\n6 8 11", "5 3\n1 2 1\n2 3 1\n3 4 1\n4 5 1\n...
{ "input": [ "5 4\n1 4 3\n2 3 4\n2 4 2\n4 5 3\n1 3 4\n1 4 5\n1 2 3\n2 4 5", "5 4\n1 4 0\n2 3 4\n2 4 2\n4 5 3\n1 3 4\n1 4 5\n1 2 3\n2 4 5", "5 3\n1 2 1\n2 3 1\n3 4 2\n4 5 1\n1 2 3\n1 3 5\n1 2 4", "15 15\n1 2 45\n2 3 81\n1 4 29\n1 5 2\n1 6 25\n4 7 84\n7 8 56\n4 9 2\n4 10 37\n7 11 39\n1 12 11\n11 13 6\n3...
p00602 Fibonacci Sets
Fibonacci number f(i) appear in a variety of puzzles in nature and math, including packing problems, family trees or Pythagorean triangles. They obey the rule f(i) = f(i - 1) + f(i - 2), where we set f(0) = 1 = f(-1). Let V and d be two certain positive integers and be N ≡ 1001 a constant. Consider a set of V nodes, e...
{ "input": [], "output": [] }
{ "input": [ "5 5\n50 1\n13 13" ], "output": [ "2\n50\n8" ] }
{ "input": [ "5 5\n50 2\n13 13", "2 5\n50 1\n13 13", "2 5\n50 1\n15 13", "5 10\n50 1\n13 20", "5 10\n50 1\n22 20", "8 10\n50 1\n22 20", "8 2\n50 1\n22 20", "8 2\n50 2\n22 20", "5 5\n50 1\n13 18", "5 5\n50 2\n13 4", "2 5\n25 1\n13 13", "2 5\n6 1\n15 13", "5 10\n30 1\...
p00738 Roll-A-Big-Ball
ACM University holds its sports day in every July. The "Roll-A-Big-Ball" is the highlight of the day. In the game, players roll a ball on a straight course drawn on the ground. There are rectangular parallelepiped blocks on the ground as obstacles, which are fixed on the ground. During the game, the ball may not collid...
{ "input": [], "output": [] }
{ "input": [ "2\n-40 -40 100 30\n-100 -100 -50 -30 1\n30 -70 90 -30 10\n2\n-4 -4 10 3\n-10 -10 -5 -3 1\n3 -7 9 -3 1\n2\n-40 -40 100 30\n-100 -100 -50 -30 3\n30 -70 90 -30 10\n2\n-400 -400 1000 300\n-800 -800 -500 -300 7\n300 -700 900 -300 20\n3\n20 70 150 70\n0 0 50 50 4\n40 100 60 120 8\n130 80 200 200 1\n3\n20 ...
{ "input": [ "2\n-40 -40 100 30\n-100 -100 -50 -30 1\n30 -70 90 -30 10\n2\n-4 -4 10 3\n-10 -10 -5 -3 1\n3 -7 9 -3 1\n2\n-40 -40 100 30\n-100 -100 -50 -30 3\n30 -70 90 -30 10\n2\n-400 -400 1000 300\n-800 -800 -500 -300 7\n300 -700 900 -300 20\n3\n20 70 150 70\n0 0 50 50 4\n40 100 60 120 8\n130 80 200 200 1\n3\n20 ...
p00878 Origami Through-Hole
Origami is the traditional Japanese art of paper folding. One day, Professor Egami found the message board decorated with some pieces of origami works pinned on it, and became interested in the pinholes on the origami paper. Your mission is to simulate paper folding and pin punching on the folded sheet, and calculate t...
{ "input": [], "output": [] }
{ "input": [ "2\n90 90 80 20\n80 20 75 50\n50 35\n2\n90 90 80 20\n75 50 80 20\n55 20\n3\n5 90 15 70\n95 90 85 75\n20 67 20 73\n20 75\n3\n5 90 15 70\n5 10 15 55\n20 67 20 73\n75 80\n8\n1 48 1 50\n10 73 10 75\n31 87 31 89\n91 94 91 96\n63 97 62 96\n63 80 61 82\n39 97 41 95\n62 89 62 90\n41 93\n5\n2 1 1 1\n-95 1 -96...
{ "input": [ "2\n90 90 80 20\n80 20 75 50\n50 35\n2\n90 90 80 20\n75 50 80 20\n55 20\n3\n5 90 15 70\n95 90 85 75\n20 67 20 73\n20 75\n3\n5 90 15 70\n5 10 15 55\n20 67 20 73\n75 80\n8\n2 48 1 50\n10 73 10 75\n31 87 31 89\n91 94 91 96\n63 97 62 96\n63 80 61 82\n39 97 41 95\n62 89 62 90\n41 93\n5\n2 1 1 1\n-95 1 -96...
p01009 Room of Time and Spirit
Problem In 20XX, a scientist developed a powerful android with biotechnology. This android is extremely powerful because it is made by a computer by combining the cells of combat masters. At this rate, the earth would be dominated by androids, so the N warriors decided to fight the androids. However, today's warriors...
{ "input": [], "output": [] }
{ "input": [ "4 3\nIN 1 4 10\nIN 2 3 20\nCOMPARE 1 2", "10 4\nIN 10 8 2328\nIN 8 4 3765\nIN 3 8 574\nCOMPARE 4 8", "3 5\nCOMPARE 1 2\nIN 1 2 5\nIN 2 3 3\nCOMPARE 2 3\nCOMPARE 1 3", "3 4\nIN 2 1 2\nIN 3 1 2\nCOMPARE 1 3\nCOMPARE 2 3", "3 5\nIN 1 2 5\nIN 1 2 5\nIN 2 3 10\nCOMPARE 1 2\nCOMPARE 2 3" ...
{ "input": [ "3 4\nIN 2 1 1\nIN 3 1 2\nCOMPARE 1 3\nCOMPARE 2 3", "4 3\nIN 1 4 10\nIN 3 3 20\nCOMPARE 1 2", "10 4\nIN 10 8 2328\nIN 8 4 3765\nIN 3 8 40\nCOMPARE 4 8", "3 5\nCOMPARE 1 2\nIN 1 2 6\nIN 2 3 3\nCOMPARE 2 3\nCOMPARE 1 3", "3 5\nIN 1 2 5\nIN 1 2 5\nIN 1 3 10\nCOMPARE 1 2\nCOMPARE 2 3", ...
p01141 Lifeguard in the Pool
Lifeguard in the Pool Pool guard English text is not available in this practice contest. Horton Moore works as a pool watchman. As he walked around the edge of the pool to look around, he noticed a girl drowning in the pool. Of course, he must go to rescue immediately. Moreover, it is difficult for the girl to have ...
{ "input": [], "output": [] }
{ "input": [ "4\n0 0 10 0 10 10 0 10\n10\n12\n0 5\n9 5\n4\n0 0 10 0 10 10 0 10\n10\n12\n0 0\n9 1\n4\n0 0 10 0 10 10 0 10\n10\n12\n0 1\n9 1\n8\n2 0 4 0 6 2 6 4 4 6 2 6 0 4 0 2\n10\n12\n3 0\n3 5\n0" ], "output": [ "108.0\n96.63324958071081\n103.2664991614216\n60.0" ] }
{ "input": [ "4\n0 1 10 0 10 10 0 10\n10\n12\n0 5\n9 5\n4\n0 0 10 0 10 10 0 10\n10\n12\n0 0\n9 1\n4\n0 0 10 0 10 10 0 10\n10\n12\n0 1\n9 1\n8\n2 0 4 0 6 2 6 4 4 6 2 6 0 4 0 2\n10\n12\n3 0\n3 5\n0", "4\n0 1 10 0 10 10 0 10\n10\n12\n0 5\n9 7\n4\n0 0 10 0 10 10 0 10\n10\n12\n0 0\n9 1\n4\n0 0 10 0 10 10 0 10\n10\...
p01280 Galaxy Wide Web Service
The volume of access to a web service varies from time to time in a day. Also, the hours with the highest volume of access varies from service to service. For example, a service popular in the United States may receive more access in the daytime in the United States, while another service popular in Japan may receive m...
{ "input": [], "output": [] }
{ "input": [ "2\n4 0 1 2 3 4\n2 0 2 1\n0" ], "output": [ "5" ] }
{ "input": [ "2\n4 0 1 2 3 4\n2 -1 2 1\n0", "2\n4 0 1 2 3 4\n2 1 1 1\n0", "2\n4 0 2 2 3 8\n2 -1 2 2\n0", "2\n4 0 1 1 3 0\n2 1 1 1\n0", "2\n4 0 1 2 0 8\n2 0 2 1\n0", "2\n4 0 1 2 0 8\n2 1 3 2\n0", "2\n4 0 1 2 0 5\n2 1 3 0\n0", "2\n4 0 1 2 0 4\n2 1 3 0\n0", "2\n4 0 0 2 0 3\n2 2 2 0\n0...
p01450 My friends are small
I have a lot of friends. Every friend is very small. I often go out with my friends. Put some friends in your backpack and go out together. Every morning I decide which friends to go out with that day. Put friends one by one in an empty backpack. I'm not very strong. Therefore, there is a limit to the weight of friends...
{ "input": [], "output": [] }
{ "input": [ "6 37\n5\n9\n13\n18\n26\n33", "4 25\n20\n15\n20\n15", "4 8\n1\n2\n7\n9" ], "output": [ "6", "4", "2" ] }
{ "input": [ "6 37\n5\n9\n24\n18\n26\n33", "4 1\n1\n2\n7\n9", "4 1\n1\n1\n11\n2", "6 37\n5\n16\n13\n18\n26\n33", "4 25\n9\n15\n20\n15", "6 37\n5\n6\n24\n18\n26\n33", "6 37\n6\n16\n13\n18\n26\n16", "6 37\n5\n9\n24\n9\n26\n35", "6 37\n6\n16\n13\n18\n12\n16", "6 50\n6\n16\n13\n18\...
p01600 Tree Construction
Problem J: Tree Construction Consider a two-dimensional space with a set of points (xi, yi) that satisfy xi < xj and yi > yj for all i < j. We want to have them all connected by a directed tree whose edges go toward either right (x positive) or upward (y positive). The figure below shows an example tree. <image> Figu...
{ "input": [], "output": [] }
{ "input": [ "5\n1 5\n2 4\n3 3\n4 2\n5 1", "1\n10000 0" ], "output": [ "12", "0" ] }
{ "input": [ "1\n11000 0", "1\n10010 0", "1\n10000 -1", "1\n00000 -1", "1\n00010 -1", "1\n00011 -1", "1\n00011 -2", "1\n00011 0", "1\n00001 0", "1\n01001 0", "1\n01000 0", "1\n00000 0", "1\n00000 1", "1\n01000 1", "1\n01010 1", "1\n01010 0", "1\n1101...
p01756 Longest Match
Given the string S and m queries. The i-th query is given by the two strings xi and yi. For each query, answer the longest substring of the string S, starting with xi and ending with yi. For the string S, | S | represents the length of S. Also, the fact that the character string T is a substring of the character stri...
{ "input": [], "output": [] }
{ "input": [ "howistheprogress\n4\nist prog\ns ss\nhow is\nthe progress", "abracadabra\n5\nab a\na a\nb c\nac ca\nz z", "icpcsummertraining\n9\nmm m\nicpc summer\ntrain ing\nsummer mm\ni c\ni i\ng g\ntrain i\nsummer er" ], "output": [ "9\n12\n5\n11", "11\n11\n4\n3\n0", "2\n10\n8\n0\n4\n16\...
{ "input": [ "howistheprogress\n4\nist prog\ns ss\nhow is\nteh progress", "abracadabsa\n5\nab a\na a\nb c\nac ca\nz z", "icpcsummertraining\n9\nmm m\nicpc summer\ntrain ing\nsummer mm\ni c\ni i\ng f\ntrain i\nsummer er", "howistheprogress\n4\nist prog\ns ss\nohw is\nteh progress", "abracadabsa\n5\...
p01896 Folding Paper
Problem statement There is a rectangular piece of paper divided in a grid with a height of $ H $ squares and a width of $ W $ squares. The integer $ i \ times W + j $ is written in the cell of the $ i $ line from the top and the $ j $ column from the left counting from $ 0 $. An example of $ H = 2 and W = 3 $ is shown...
{ "input": [], "output": [] }
{ "input": [ "1 4\n0 1 2 3" ], "output": [ "YES" ] }
{ "input": [ "1 4\n0 1 2 5", "0 4\n0 1 2 10", "1 4\n0 1 2 10", "0 4\n0 1 2 8", "0 4\n0 1 2 1", "0 4\n0 1 2 2", "1 4\n0 1 2 2", "1 4\n1 1 2 5", "0 1\n0 1 2 10", "0 4\n-1 1 2 8", "0 3\n0 1 2 1", "0 3\n0 1 2 2", "1 6\n1 1 2 5", "1 1\n0 1 2 10", "0 3\n0 1 0 1", ...
p02033 Arrow
D: Arrow / Arrow problem rodea is in a one-dimensional coordinate system and stands at x = 0. From this position, throw an arrow of positive integer length that always moves at speed 1 towards the target at x = N. However, rodea is powerless, so we have decided to put a total of M blowers in the section 0 \ leq x \ l...
{ "input": [], "output": [] }
{ "input": [ "5 1\n2\n1\n3" ], "output": [ "2" ] }
{ "input": [ "6 1\n2\n1\n3", "5 1\n2\n1\n0", "6 1\n2\n1\n4", "5 1\n1\n1\n0", "6 1\n2\n1\n8", "5 1\n1\n1\n1", "7 1\n1\n1\n0", "8 1\n1\n1\n0", "10 1\n1\n1\n1", "11 1\n6\n1\n5", "15 1\n3\n1\n2", "15 1\n6\n1\n5", "15 1\n3\n1\n3", "15 1\n1\n1\n0", "15 1\n1\n1\n1"...
p02176 Shortest Crypt
problem Cryptography is all the rage at xryuseix's school. Xryuseix, who lives in a grid of cities, has come up with a new cryptography to decide where to meet. The ciphertext consists of the $ N $ character string $ S $, and the $ S_i $ character determines the direction of movement from the current location. The di...
{ "input": [], "output": [] }
{ "input": [ "5\nANazA" ], "output": [ "1\nA" ] }
{ "input": [ "5\nAzaNA", "5\nAMazA", "5\nzAaNA", "5\nAzaAN", "5\nzAaNB", "5\nAMAza", "5\nAzaBN", "5\nzAaNC", "5\nAMBza", "5\nNBazA", "5\nAaBzM", "5\nNBAza", "5\nAazBM", "5\nzBANa", "5\nzBAOa", "5\nzOABa", "5\nzOABb", "5\nzOAbB", "5\nyOAbB", ...
p02319 0-1 Knapsack Problem II
You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. Find the maximum total value of i...
{ "input": [], "output": [] }
{ "input": [ "4 5\n4 2\n5 2\n2 1\n8 3", "2 20\n5 9\n4 10" ], "output": [ "13", "9" ] }
{ "input": [ "4 5\n0 2\n5 2\n2 1\n8 3", "2 20\n5 9\n3 10", "4 2\n0 2\n5 2\n2 1\n8 3", "2 20\n5 9\n2 10", "2 20\n5 9\n1 8", "2 20\n4 5\n0 4", "4 5\n4 2\n5 2\n2 0\n8 3", "2 20\n5 9\n7 10", "4 7\n4 2\n5 2\n2 0\n8 3", "2 20\n9 14\n2 10", "0 20\n4 5\n1 2", "2 33\n9 14\n2 10"...
p02464 Set Intersection
Find the intersection of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$. Constraints * $1 \leq n, m \leq 200,000$ * $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$ * $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$ Input The input is given in the following format. $n$ $a_0 \; a_1 \; ....
{ "input": [], "output": [] }
{ "input": [ "4\n1 2 5 8\n5\n2 3 5 9 11" ], "output": [ "2\n5" ] }
{ "input": [ "4\n1 2 5 8\n5\n4 3 5 9 11", "4\n1 2 5 8\n9\n2 3 5 9 11", "4\n1 2 9 8\n5\n4 3 5 9 11", "4\n1 2 5 8\n9\n1 3 5 9 11", "4\n1 2 9 8\n7\n2 3 5 9 11", "4\n1 2 2 8\n9\n1 3 5 9 11", "4\n1 3 9 8\n7\n2 3 5 9 11", "4\n0 2 5 8\n5\n0 3 5 9 12", "4\n1 0 4 10\n9\n2 4 5 9 11", "4\...
a3
Alice and Johnny are playing a simple guessing game. Johnny picks an arbitrary positive integer n (1 ≤ n ≤ 10^9) and gives Alice exactly k hints about the value of n. It is Alice's task to guess n, based on the received hints. Alice often has a serious problem guessing the value of n, and she's beginning to suspect t...
{ "input": [], "output": [] }
{ "input": [ "3\n2\n< 100 No\n> 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1 Yes\n= 1 Yes\n> 1 Yes\n= 1 Yes" ], "output": [ "0\n1\n2" ] }
{ "input": [ "3\n2\n< 100 No\n> 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1 Yes\n= 1 Yes\n= 1 Yes\n= 1 Yes", "3\n2\n< 100 No\n? 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1 Yes\n= 1 Yes\n> 1 Yes\n= 1 Yes", "3\n2\n< 100 No\n> 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Ye...
chefbm
Spring is interesting season of year. Chef is thinking about different things, but last time he thinks about interesting game - "Strange Matrix". Chef has a matrix that consists of n rows, each contains m elements. Initially, the element aij of matrix equals j. (1 ≤ i ≤ n, 1 ≤ j ≤ m). Then p times some element aij is...
{ "input": [], "output": [] }
{ "input": [ "4 4 6\n2 2\n3 2 \n3 2 \n4 3\n4 4\n4 3" ], "output": [ "3\n3\n-1\n4" ] }
{ "input": [ "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 1", "4 4 6\n3 2\n3 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 6\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 2\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "3 6 2\n1 2\n3 0 \n6 2 \n4 3\n1 1\n5 3", "3 4 2\n1 2\n3 0 \n6 2 \n4 3\n1...
digjump
Chef loves games! But he likes to invent his own. Now he plays game "Digit Jump". Chef has sequence of digits S1, S2,..., SN,. He is staying in the first digit (S1) and want to reach the last digit (SN) in the minimal number of jumps. While staying in some digit x with index i (digit Si) Chef can jump into digits with...
{ "input": [], "output": [] }
{ "input": [ "01234567890", "012134444444443" ], "output": [ "1\n", "4\n" ] }
{ "input": [ "1352328136", "20776892991725", "6858574858270", "10353326888495", "2595212919780", "1149262658611", "361054554527", "6", "1404985567", "22244193067", "616962463", "495895796", "521512370", "14708953637626", "973504405", "721897112", "12...
insoma4
In the hidden country of Lapatrecta, an age old custom was followed to ensure that no outsider ever entered their country undetected. The security measure, though simple, was an effective one. Every person born in Lapatrecta had the initials of all his forefathers included in front of his name. Every once in a while, c...
{ "input": [], "output": [] }
{ "input": [ "3\nAPJQ\nAPJRS\nPJQ" ], "output": [ "3" ] }
{ "input": [], "output": [] }
nf02
NITMAS Fest is live. The members of the community are very busy. People from different colleges have come to compete. But, Naveen is very possessive about his girlfriend, Archana. He always remains close to his girlfriend. Couples (boys in a line and girls in another) have to stand in different rows in a line for a gam...
{ "input": [], "output": [] }
{ "input": [ "4 2 4 6 8\n5 1 3 5 7 9" ], "output": [ "1" ] }
{ "input": [], "output": [] }
salg04
p { font-size:14px; text-align:justify; } Two positive integers n amd m, n greater than or equal to m, will be given as input. Make a code that generates all possible combinations of 1,2,3,...,n taking m integers at a time in "increasing order". Comparison between two combinations: a1,a2,a3,...,am b1,b2,b3,...,bm ...
{ "input": [], "output": [] }
{ "input": [ "5\n3" ], "output": [ "1 2 3 \n1 2 4\n1 2 5\n1 3 4\n1 3 5\n1 4 5\n2 3 4\n2 3 5\n2 4 5\n3 4 5" ] }
{ "input": [], "output": [] }
1384_D. GameGame
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of...
{ "input": [], "output": [] }
{ "input": [ "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n", "3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n" ], "output": [ "WIN\nWIN\nDRAW\nWIN\n", "WIN\nLOSE\nDRAW\n" ] }
{ "input": [ "3\n3\n2 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n", "4\n5\n4 1 3 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n", "3\n3\n2 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n", "3\n3\n4 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n", "3\n3\n4 2 0\n3\n2 2 4\n5\n0 0 0 2 2\n", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n1\n2\n5 4\n", "3\n3\n1 2 2\n3\n2 ...
1427_B. Chess Cheater
You like playing chess tournaments online. In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 ...
{ "input": [], "output": [] }
{ "input": [ "8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 1\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n" ], "output": [ "7\n11\n6\n26\n46\n0\n1\n6\n" ] }
{ "input": [ "8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 2\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n", "8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 2\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 11\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n", ...
1450_B. Balls of Steel
You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all ba...
{ "input": [], "output": [] }
{ "input": [ "3\n3 2\n0 0\n3 3\n1 1\n3 3\n6 7\n8 8\n6 9\n4 1\n0 0\n0 1\n0 2\n0 3\n" ], "output": [ "\n-1\n1\n-1\n" ] }
{ "input": [ "3\n3 2\n0 0\n3 3\n1 1\n3 3\n6 7\n8 8\n6 9\n4 1\n0 0\n1 1\n0 2\n0 3\n", "3\n3 2\n0 0\n3 3\n1 2\n3 3\n6 7\n9 6\n6 9\n4 1\n0 0\n0 0\n1 2\n1 3\n", "3\n3 2\n0 0\n1 3\n1 1\n3 3\n6 7\n9 8\n6 9\n4 1\n-1 0\n0 1\n0 2\n1 5\n", "3\n3 4\n0 0\n3 3\n1 1\n3 3\n6 7\n8 6\n6 9\n4 0\n0 0\n0 2\n0 2\n0 3\n", ...
1473_G. Tiles
Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged. The road is constructed as follows: * the first row consist...
{ "input": [], "output": [] }
{ "input": [ "2\n4 2\n2 3\n", "8\n328 323\n867 868\n715 718\n721 722\n439 435\n868 870\n834 834\n797 796\n", "3\n4 1\n2 3\n3 1\n" ], "output": [ "\n850\n", "\n759099319\n", "\n10150\n" ] }
{ "input": [ "2\n4 2\n2 2\n", "3\n4 1\n2 3\n6 1\n", "3\n4 1\n2 3\n6 2\n", "3\n4 1\n2 4\n6 1\n", "3\n4 1\n2 3\n5 1\n", "2\n4 2\n4 2\n", "3\n4 1\n1 3\n6 1\n", "3\n4 1\n2 3\n1 2\n", "3\n4 1\n2 4\n6 2\n", "3\n4 1\n0 3\n5 1\n", "2\n5 2\n4 2\n", "3\n4 1\n1 3\n10 1\n", "3\...
64_A. Factorial
Print the factorial of the given integer number n. The factorial of n is equal to 1·2·...·n. Input The only line contains n (1 ≤ n ≤ 10). Output Print the factorial of n. Examples Input 3 Output 6 Input 5 Output 120
{ "input": [], "output": [] }
{ "input": [ "3\n", "5\n" ], "output": [ "6\n", "120\n" ] }
{ "input": [], "output": [] }
benny-and-shopping
Yesterday, Benny decided to buy something from a television shop. She created a list that consisted of small description of N orders. The description for an order number i is a string Si. The description may consist of uppercase/lowercase Latin letters, digits and a '$' sign. But, every time after the sign '$', Benny...
{ "input": [], "output": [] }
{ "input": [ "4\nI want to buy Microsoft for $10000\nthis house costs $0 5 0 00 0 Just buy it\nsiejfsuhn $ 1 2 3 4 5 6 7 8 9 hello123\nthe cost is zero $ 0 0 0 0 0 0\n\nSAMPLE" ], "output": [ "$10000\n$50000\n$123456789\n$0\n" ] }
{ "input": [ "4\nI want to buy Microsoft for $10000\nthis house stsoc $0 5 0 00 0 Just buy it\nsiejfsuhn $ 1 2 3 4 5 6 7 8 9 hello123\nthe cost is zero $ 0 0 0 0 0 0\n\nSAMPLE", "4\nI want to buy Microsoft for $10000\nthis house stsoc $0 5 0 00 0 Just buy it\nsiejfsuhn $ 1 2 3 4 5 6 7 2 9 hello123\nthe cost i...
ikshu-and-his-class-1
Ikshu and his class Ikshu's class is very fond of playing games. Their teacher tied them with many ropes with each other, Such that each student is tied with exactly one rope. It means that if students 2 and 3 are connected and 2 is connected to 4 as well then 2,3 and 4 must be sharing the same rope. Now, teacher ask...
{ "input": [], "output": [] }
{ "input": [ "5 2\n1 2\n3 4\n\nSAMPLE" ], "output": [ "4\n" ] }
{ "input": [ "5 2\n0 2\n3 4\n\nSAMPLE", "7 0\n0 2\n3 4\n\nSAMPLE", "7 2\n0 0\n3 4\n\nSAMPLE", "5 2\n1 4\n3 4\n\nSAMPLE", "7 2\n0 2\n3 4\n\nSAMPLE", "7 0\n0 2\n3 4\n\nELPMAS", "0 0\n0 2\n3 4\n\nELPMAS", "0 0\n0 2\n1 4\n\nELPMAS", "0 0\n0 2\n1 5\n\nELPMAS", "0 0\n0 0\n1 5\n\nELPM...
number-miss
Vicky, the Artist, had two lists A and B, such that B was a permutation of A. Vicky was very proud of these lists. Unfortunately, while transporting them from one exhibition to another, some numbers were left out of A. Can you find the missing numbers? If a number occurs multiple times in the lists, you must ensure tha...
{ "input": [], "output": [] }
{ "input": [ "10\n203 204 205 206 207 208 203 204 205 206\n13\n203 204 204 205 206 207 205 208 203 206 205 206 204\n\nSAMPLE" ], "output": [ "204 205 206 \n" ] }
{ "input": [ "10\n203 204 205 206 207 208 203 204 205 206\n13\n203 204 204 205 206 207 205 208 203 206 205 206 204\n\nRAMPLE", "10\n203 204 205 206 207 208 203 204 205 206\n11\n203 204 204 205 206 207 205 208 203 206 205 206 203\n\nRANPLE", "10\n205 204 205 206 207 208 203 204 205 206\n11\n203 204 204 205...
racers
There are N bikers present in a city (shaped as a grid) having M bikes. All the bikers want to participate in the HackerRace competition, but unfortunately only K bikers can be accommodated in the race. Jack is organizing the HackerRace and wants to start the race as soon as possible. He can instruct any biker to move ...
{ "input": [], "output": [] }
{ "input": [ "3 3 2\n0 1\n0 2\n0 3\n100 1\n200 2 \n300 3\n\nSAMPLE" ], "output": [ "40000" ] }
{ "input": [], "output": [] }
shil-and-survival-game
The Mad King arrested Shil's comrades for participating in a rebellion against the King. Instead of punishing them with death, the King decided to play the Game of survival with them. The game is played as follows: All the N people are forced to stand in a line. Now the king randomly chooses any two persons standi...
{ "input": [], "output": [] }
{ "input": [ "5\n2 6 8 1 3\n\nSAMPLE" ], "output": [ "1 2 3 5" ] }
{ "input": [ "5\n2 10 8 1 3\n\nSAMPLE", "5\n2 13 4 2 6\n\nSAMPLE", "5\n-1 76 14 1 0\n\nELPLAR", "5\n1 0 13 0 6\n\nSAMPLE", "5\n2 10 8 2 3\n\nSAMPLE", "5\n2 10 8 2 6\n\nSAMPLE", "5\n2 10 13 2 6\n\nSAMPLE", "5\n2 10 14 2 6\n\nSAMPLE", "5\n2 13 14 2 6\n\nSAMPLE", "5\n2 13 14 2 11\...
the-old-monk
Big Chandan is a dire lover of Biryani, especially Old Monk's Biryani. Today, he went over to have some of it. To his surprise, the waiter turns out be to be a coding geek and refuses to serves him unless Chandu solves his two- arrays problem, stated as: Given two non-increasing array of integers A,B i.e A[i] ≥ A[i...
{ "input": [], "output": [] }
{ "input": [ "2\n9\n7 7 3 3 3 2 2 2 1\n8 8 7 7 5 5 4 3 2\n6\n6 5 4 4 4 4\n2 2 2 2 2 2\n\nSAMPLE" ], "output": [ "5\n0\n" ] }
{ "input": [ "2\n9\n7 7 3 3 3 2 2 2 1\n8 8 9 7 5 5 4 3 2\n6\n6 5 4 4 4 4\n2 2 2 2 2 2\n\nSAMPLE", "2\n9\n9 7 3 3 3 2 2 2 1\n8 8 9 7 5 5 4 1 2\n6\n6 5 4 4 4 0\n2 2 2 2 2 2\n\nSAMQLE", "2\n9\n6 4 3 3 3 2 2 3 1\n8 8 9 7 5 5 4 4 2\n6\n6 16 4 4 4 4\n2 2 2 2 2 2\n\nSAMQLE", "2\n9\n9 7 3 3 3 3 2 2 1\n8 8 10 ...
p02537 ACL Beginner Contest - Flat Subsequence
You are given a sequence A_1, A_2, ..., A_N and an integer K. Print the maximum possible length of a sequence B that satisfies the following conditions: * B is a (not necessarily continuous) subsequence of A. * For each pair of adjacents elements of B, the absolute difference of the elements is at most K. Constraint...
{ "input": [], "output": [] }
{ "input": [ "10 3\n1\n5\n4\n3\n8\n6\n9\n7\n2\n4" ], "output": [ "7" ] }
{ "input": [ "10 3\n1\n5\n4\n3\n8\n6\n9\n7\n4\n4", "10 3\n1\n5\n4\n3\n6\n6\n9\n7\n4\n4", "10 3\n0\n1\n4\n3\n6\n6\n9\n7\n4\n4", "10 3\n1\n5\n4\n3\n8\n6\n9\n7\n3\n4", "10 3\n1\n5\n4\n3\n8\n11\n9\n7\n3\n4", "10 1\n0\n1\n4\n0\n5\n9\n9\n7\n8\n4", "10 1\n0\n5\n4\n3\n8\n11\n9\n7\n6\n2", "10 3...
p02668 NOMURA Programming Competition 2020 - Sorting Game
Takahashi and Snuke came up with a game that uses a number sequence, as follows: * Prepare a sequence of length M consisting of integers between 0 and 2^N-1 (inclusive): a = a_1, a_2, \ldots, a_M. * Snuke first does the operation below as many times as he likes: * Choose a positive integer d, and for each i (1 \leq ...
{ "input": [], "output": [] }
{ "input": [ "2020 530", "2 5" ], "output": [ "823277409", "352" ] }
{ "input": [ "3829 530", "3 5", "6 5", "2777 530", "1 5", "4536 530", "3 4", "6 9", "1722 530", "4536 629", "6 4", "6 13", "2633 530", "5 13", "2633 804", "8 13", "2633 890", "3785 890", "2020 991", "2 8", "700 530", "3 1", "8...
p02797 Keyence Programming Contest 2020 - Subarray Sum
Given are three integers N, K, and S. Find a sequence A_1, A_2, ..., A_N of N integers between 1 and 10^9 (inclusive) that satisfies the condition below. We can prove that, under the conditions in Constraints, such a sequence always exists. * There are exactly K pairs (l, r) of integers such that 1 \leq l \leq r \leq...
{ "input": [], "output": [] }
{ "input": [ "5 3 100", "4 2 3" ], "output": [ "50 50 50 30 70", "1 2 3 4" ] }
{ "input": [ "5 3 000", "5 0 100", "4 1 3", "5 3 010", "4 0 3", "10 3 010", "8 0 3", "10 5 010", "8 1 3", "10 5 000", "10 1 3", "10 9 000", "10 2 3", "17 9 000", "10 0 3", "10 9 001", "7 0 3", "10 6 001", "7 0 6", "13 6 001", "2 0 6",...
p02933 AtCoder Beginner Contest 138 - Red or Not
You will be given an integer a and a string s consisting of lowercase English letters as input. Write a program that prints s if a is not less than 3200 and prints `red` if a is less than 3200. Constraints * 2800 \leq a < 5000 * s is a string of length between 1 and 10 (inclusive). * Each character of s is a lowerca...
{ "input": [], "output": [] }
{ "input": [ "4049\nred", "3199\npink", "3200\npink" ], "output": [ "red", "red", "pink" ] }
{ "input": [ "4049\nrdd", "3199\nknip", "3200\npinl", "4049\nqdd", "3200\npiml", "4049\nqcd", "3200\nlmip", "4049\nqdc", "3200\nkmip", "4049\nddq", "3200\nknip", "4049\nddr", "3200\nkniq", "4049\ndrd", "3200\nlniq", "4049\ndqd", "3200\nqinl", "40...
p03069 Tenka1 Programmer Beginner Contest 2019 - Stones
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`. Takahashi wants to change the colors of some stones to black or white so t...
{ "input": [], "output": [] }
{ "input": [ "3\n.#", "5\n.##.", "9\n.........", "3\n#.#" ], "output": [ "1", "2", "0", "1" ] }
{ "input": [ "5\n.#.#", "3\n.##", "3\n##.", "5\n..##", "5\n#..#", "3\n.# ", "3\n##.", "3\n.##", "5\n.#.#", "5\n..##", "5\n#..#", "3\n.# " ], "output": [ "1\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n", "0\n", ...
p03212 AtCoder Beginner Contest 114 - 755
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there? Here, a Shichi-Go-San number is a positive integer that satisfies the following condition: * When the number is written in base ten, each of the digits `7`, `5` ...
{ "input": [], "output": [] }
{ "input": [ "575", "3600", "999999999" ], "output": [ "4", "13", "26484" ] }
{ "input": [ "60", "1134", "656396080", "1260308870", "251112438", "3669", "4753", "3412", "5825", "471776498", "377370744", "563", "35191132", "26435227", "635", "5689978", "7251994", "2751855", "585456", "3750", "406", "75919180...
p03361 AtCoder Beginner Contest 096 - Grid Repainting 2
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, ...
{ "input": [], "output": [] }
{ "input": [ "3 3\n.#.\n###\n.#.", "5 5\n.#.#\n.#.#.\n.#.#\n.#.#.\n.#.#", "11 11\n...#####...\n.##.....##.\n..##.##..#\n..##.##..#\n.........#\n...###...#\n.#########.\n.#.#.#.#.#.\n.#.#.#.##\n..##.#.##..\n.##..#..##.", "3 3\n.#.\n\n.#." ], "output": [ "Yes", "No", "Yes", "Yes" ]...
{ "input": [ "3 5\n.#.\n###\n.#.", "5 5\n.#.#\n.#.#.\n-#.#\n.#.#.\n.#.#", "11 11\n...#####...\n.##.....##.\n..##.##..#\n..##.##..#\n.........#\n...###...#\n.#########.\n.#.#.#.#.#.\n.#.#.#.#$\n..##.#.##..\n.##..#..##.", "3 6\n.#.\n###\n.#.", "11 11\n...#####...\n.##.....##.\n..##.##..#\n..##.##..#...