name
stringlengths
2
112
description
stringlengths
29
13k
private_tests
dict
public_tests
dict
generated_tests
dict
p02423 Bit Operation I
Given a non-negative decimal integer $x$, convert it to binary representation $b$ of 32 bits. Then, print the result of the following operations to $b$ respecitvely. * Inversion: change the state of each bit to the opposite state * Logical left shift: shift left by 1 * Logical right shift: shift right by 1 Constraint...
{ "input": [], "output": [] }
{ "input": [ "13", "8" ], "output": [ "00000000000000000000000000001101\n11111111111111111111111111110010\n00000000000000000000000000011010\n00000000000000000000000000000110", "00000000000000000000000000001000\n11111111111111111111111111110111\n00000000000000000000000000010000\n0000000000000000000...
{ "input": [ "9", "5", "7", "3", "2", "1", "10", "0", "4", "-1", "-2", "14", "-3", "-4", "-6", "-8", "-10", "-12", "-18", "-9", "-27", "6", "12", "-5", "16", "-7", "24", "-17", "19", "-23", "33"...
abcstr
Mike likes strings. He is also interested in algorithms. A few days ago he discovered for himself a very nice problem: You are given an AB-string S. You need to count the number of substrings of S, which have an equal number of 'A'-s and 'B'-s. Do you know how to solve it? Good. Mike will make the problem a little ...
{ "input": [], "output": [] }
{ "input": [ "ABACABA" ], "output": [ "2\n" ] }
{ "input": [ "ABBCABA", "ABABBBA", "@BABBBA", "@BABCBA", "AB@BCAB", "BCABACB", "ABCBACB", "ABACBBA", "ABBBABA", "ABBB@BA", "AB@BBBA", "ABCBAB@", "BABB@BA", "@BABCBB", "AB@BBAB", "?BABCBB", "BABBABA", "BBCBAB?", "BACBABA", "CBCBAB?", "...
cheflr
Chef has a nice complete binary tree in his garden. Complete means that each node has exactly two sons, so the tree is infinite. Yesterday he had enumerated the nodes of the tree in such a way: Let's call the nodes' level a number of nodes that occur on the way to this node from the root, including this node. This wa...
{ "input": [], "output": [] }
{ "input": [ "4\nlrl\nrll\nr\nlllr" ], "output": [ "10\n14\n4\n13\n" ] }
{ "input": [ "4\nrll\nrll\nr\nlllr", "4\nlrl\nrll\nr\nrlll", "4\nlrl\nrll\nr\nllrl", "4\nrll\nllr\nr\nlllr", "4\nrll\nrll\nr\nllrl", "4\nrll\nllr\nr\nrlll", "4\nllr\nllr\nr\nrlll", "4\nllr\nrll\nr\nrlll", "4\nrll\nrll\nr\nrlll", "4\nllr\nrll\nr\nlllr", "4\nrll\nlrl\nr\nlllr...
divgold
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve....
{ "input": [], "output": [] }
{ "input": [ "2\n4\nDCBA\n7\nXYZZYZZ" ], "output": [ "ADCB\nXYYZZZZ\n" ] }
{ "input": [ "2\n4\nDCBA\n7\nXYZZYZY", "2\n4\nDCBA\n7\nXZZZYZZ", "2\n4\nABCD\n7\nXYZZYZY", "2\n4\nCBAD\n7\nXYZZYZY", "2\n4\nCBAD\n7\nYZYZZYX", "2\n4\nCDAB\n7\nYZYZZYX", "2\n4\nCDAB\n7\nYZYZZYW", "2\n4\nDCBA\n7\nYZYZZYX", "2\n4\nDBAD\n7\nXYZZYZY", "2\n4\nBBAD\n7\nYZYZZYX", "...
intresec
Problem description. Chef is playing with 'n' set of planes. He notices that when two planes intersects a line is formed. Being that curious guy that chef already is, he wonders as to how many maximum possible line intersections can he obtain with his n set of planes.Given n set of planes find the maximum number of lin...
{ "input": [], "output": [] }
{ "input": [ "2\n2\n3" ], "output": [ "1\n3\n" ] }
{ "input": [ "2\n2\n0", "2\n2\n-1", "2\n2\n-2", "2\n0\n-2", "2\n-1\n-4", "2\n0\n-4", "2\n0\n-3", "2\n2\n-3", "2\n4\n-3", "2\n4\n-5", "2\n4\n-2", "2\n3\n-2", "2\n3\n0", "2\n0\n1", "2\n-4\n-2", "2\n-4\n0", "2\n-5\n0", "2\n-1\n-8", "2\n-1\n-5", ...
nita10
Alan threw a party and invited all her close friend to it. Let us suppose there were 2n people in the party and all of them were sitting across a round table. The host asked them to shake hands with the condition that no two hands should cross each other i.e if 4 people are sitting then 1st person cannot shake hands wi...
{ "input": [], "output": [] }
{ "input": [ "2\n2\n4" ], "output": [ "2\n14" ] }
{ "input": [], "output": [] }
seakam
Sereja has an undirected graph on N vertices. There are edges between all but M pairs of vertices. A permutation p on the vertices of the graph is represented as p[1], p[2], … , p[N] such that for all i, p[i] is a vertex of the graph. A permutation is called connected if there is an edge between vertices p[i] and p[i+...
{ "input": [], "output": [] }
{ "input": [ "2\n4 3\n1 2\n2 3\n3 4\n2 1\n1 2" ], "output": [ "2\n0" ] }
{ "input": [], "output": [] }
1385_D. a-Good String
You are given a string s[1 ... n] consisting of lowercase Latin letters. It is guaranteed that n = 2^k for some integer k ≥ 0. The string s[1 ... n] is called c-good if at least one of the following three conditions is satisfied: * The length of s is 1, and it consists of the character c (i.e. s_1=c); * The lengt...
{ "input": [], "output": [] }
{ "input": [ "6\n8\nbbdcaaaa\n8\nasdfghjk\n8\nceaaaabb\n8\nbbaaddcc\n1\nz\n2\nac\n" ], "output": [ "0\n7\n4\n5\n1\n1\n" ] }
{ "input": [ "6\n8\nbbdcaaaa\n8\nasdfghjk\n8\nceaaaabb\n8\nbbaaddcc\n1\nz\n2\nbc\n", "6\n8\nbbdcaaaa\n8\nasdfghjk\n8\nceaaaacb\n8\nbbaaddcc\n1\ny\n2\nbc\n", "6\n8\nbbdcaaaa\n8\nasdfghjk\n8\nbbaaaaec\n8\nbbaadccc\n1\nz\n2\nac\n", "6\n8\nbbdaacaa\n8\nasdfghjk\n8\nbbaaaaec\n8\nbbaadccc\n1\nz\n2\nac\n", ...
294_E. Shaass the Great
The great Shaass is the new king of the Drakht empire. The empire has n cities which are connected by n - 1 bidirectional roads. Each road has an specific length and connects a pair of cities. There's a unique simple path connecting each pair of cities. His majesty the great Shaass has decided to tear down one of the ...
{ "input": [], "output": [] }
{ "input": [ "6\n1 3 1\n2 3 1\n3 4 100\n4 5 2\n4 6 1\n", "6\n1 2 1\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n", "3\n1 2 2\n1 3 4\n" ], "output": [ "825", "29", "12" ] }
{ "input": [ "6\n1 3 1\n2 3 1\n3 4 100\n4 5 1\n4 6 1\n", "6\n1 2 1\n2 3 1\n3 4 1\n4 5 2\n5 6 1\n", "6\n1 3 1\n2 6 1\n3 4 100\n4 5 2\n4 6 1\n", "6\n1 3 1\n2 3 1\n3 4 100\n4 5 1\n4 6 2\n", "6\n1 3 1\n2 3 1\n3 4 000\n4 5 1\n4 6 2\n", "6\n1 3 1\n2 3 2\n3 4 000\n4 5 1\n4 6 2\n", "6\n1 3 0\n2 3 ...
64_G. Path Canonization
A path in some Unix-similar file system is given. The path consists of elements separated with characters "/". For example: "/usr/share/mysql/../tomcat6/conf/server.xml". The path starts with the root directory (i.e. starts with the character "/"). Each element means a name of file or directory, or it is one of two spe...
{ "input": [], "output": [] }
{ "input": [ "/usr/share/mysql/../tomcat6/conf/server.xml\n", "/a/./././..\n" ], "output": [ "/usr/share/tomcat6/conf/server.xml\n", "/\n" ] }
{ "input": [], "output": [] }
find-me
Sam is dangerous boy. He like to fight with everyone who is more powerful than him. One day, Sam enters in the meeting of all gangsters of the city. He wants to fight with everyone who is more powerful than him. But one man know his motive and tell to all gangsters about Sam. But gangsters don't know whether the Sam i...
{ "input": [], "output": [] }
{ "input": [ "1\n6 5\n1 3 7 2 6 8\n\nSAMPLE" ], "output": [ "NO 0\n" ] }
{ "input": [ "1\n6 5\n1 3 7 3 6 8\n\nSAMPLE", "1\n6 5\n1 3 5 3 1 8\n\nSAMPLE", "1\n6 5\n0 3 5 3 6 8\n\nSAMPLE", "1\n6 0\n1 3 5 3 0 8\n\nSBMPLE", "1\n6 2\n1 3 4 4 6 2\n\nSAMPLE", "1\n6 5\n1 3 7 3 1 8\n\nSAMPLE", "1\n6 5\n1 3 5 3 1 8\n\nSANPLE", "1\n6 5\n2 3 5 3 1 8\n\nSANPLE", "1\n6...
in-love-with-primes
Little Arjit is in love with Deepa. They have always thought of themselves as the ideal couple - the best, possible match they could've managed. (No kidding!) And like every other couple, they promised each other not to fight after every other fight. But, when has that happened before? But, this is a different couple ...
{ "input": [], "output": [] }
{ "input": [ "2\n4\n8\n\nSAMPLE" ], "output": [ "Deepa\nDeepa\n" ] }
{ "input": [ "2\n4\n8\n\nSANPLE", "2\n4\n2\n\nSBMPLE", "2\n2\n2\n\nMBSPLE", "2\n2\n8\n\nELMPBS", "2\n4\n8\n\nSBMPLE", "2\n4\n8\n\nASMPLE", "2\n4\n8\n\nELPNAS", "2\n4\n2\n\nMBSPLE", "2\n2\n2\n\nMBSPLD", "2\n4\n2\n\nMBSPLD", "2\n4\n2\n\nMBRPLD", "2\n4\n6\n\nSAMPLE", "...
odd-mathematics-2
Mandark thinks he is better than Dexter. He challenges Dexter to find answer to a mathematics problem he created. Dexter accepts the challenge and decides to write a program for it to reduce manual calculations. The problem: Let f(x) be the greatest odd divisor of x, where x is a positive integer. You are given a posi...
{ "input": [], "output": [] }
{ "input": [ "2\n7\n777\n\nSAMPLE" ], "output": [ "21\n201537\n" ] }
{ "input": [ "2\n2\n777\n\nSAMPLE", "2\n2\n548\n\nMASPLE", "2\n2\n73\n\nMATPLE", "2\n4\n73\n\nMATPLE", "2\n4\n117\n\nMATPLE", "2\n4\n158\n\nMATPLE", "2\n7\n158\n\nMATPLE", "2\n14\n158\n\nMATPLE", "2\n25\n158\n\nMATPLE", "2\n11\n158\n\nMATPLE", "2\n11\n278\n\nMBTPLE", "2...
p02544 ACL Contest 1 - Shuffle Window
Given are a permutation p_1, p_2, \dots, p_N of (1, 2, ..., N) and an integer K. Maroon performs the following operation for i = 1, 2, \dots, N - K + 1 in this order: * Shuffle p_i, p_{i + 1}, \dots, p_{i + K - 1} uniformly randomly. Find the expected value of the inversion number of the sequence after all the oper...
{ "input": [], "output": [] }
{ "input": [ "10 3\n1 8 4 9 2 3 7 10 5 6", "3 2\n1 2 3" ], "output": [ "164091855", "1" ] }
{ "input": [ "3 3\n1 2 3", "10 6\n1 8 4 9 2 3 7 10 5 6", "3 2\n2 1 3", "10 5\n1 8 4 9 2 3 7 10 5 6", "10 7\n1 8 4 9 2 3 7 10 5 6", "3 2\n2 3 1", "10 8\n1 8 4 9 2 3 7 10 5 6", "10 4\n1 8 4 9 2 3 7 10 5 6", "3 3\n1 2 2", "3 3\n1 2 1", "3 3\n1 3 3", "3 3\n2 3 3", "3 3\...
p02675 AtCoder Beginner Contest 168 - ∴ (Therefore)
The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese. When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of "本" in the phrase "N 本" for a pos...
{ "input": [], "output": [] }
{ "input": [ "16", "2", "183" ], "output": [ "pon", "hon", "bon" ] }
{ "input": [ "31", "4", "23", "39", "49", "6", "76", "62", "12", "58", "70", "9", "8", "5", "0", "10", "15", "1", "7", "13", "11", "3", "14", "21", "22", "44", "52", "57", "-5", "-10", "151", ...
p02803 AtCoder Beginner Contest 151 - Maze Master
Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`. From a road square, you can move to a horizontally or vertically adjacent ro...
{ "input": [], "output": [] }
{ "input": [ "3 3\n...\n...\n...", "3 5\n...#.\n.#.#.\n.#..." ], "output": [ "4", "10" ] }
{ "input": [ "3 3\n...\n../\n...", "0 5\n...#.\n.#.#.\n.#...", "0 5\n.#...\n.#.#.\n.#...", "0 5\n.#...\n.#.#.\n.$...", "0 5\n.#..-\n.#.#.\n.$...", "0 5\n.#..-\n.#.#.\n.$..-", "-1 5\n.#..-\n.#.#.\n.$..-", "0 6\n.#..-\n.#.#.\n.$..-", "0 6\n.#..-\n.#.$.\n.$..-", "0 6\n.#..-\n.#/$....
p02939 AtCoder Grand Contest 037 - Dividing a String
Given is a string S consisting of lowercase English letters. Find the maximum positive integer K that satisfies the following condition: * There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1). Here S_1S_2...S_K represents the concatenation of S_1,S_2,....
{ "input": [], "output": [] }
{ "input": [ "aaaccacabaababc", "aabbaa" ], "output": [ "12", "4" ] }
{ "input": [ "aaaccacabaababb", "a`bbaa", "abbccacabaababa", "abbccaaabaababc", "b`aba`", "b``aaa", "`abab`cbbba`c`b", "`_b`ab`_babcdba", "aabccacabaababb", "a`bcaa", "bbabaabacaccbaa", "a`acaa", "c`aaaa", "b`aaaa", "abbbcaaabaababc", "b`abaa", "abbb...
p03076 AtCoder Beginner Contest 123 - Five Dishes
The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is ...
{ "input": [], "output": [] }
{ "input": [ "123\n123\n123\n123\n123", "29\n20\n7\n35\n120", "101\n86\n119\n108\n57" ], "output": [ "643", "215", "481" ] }
{ "input": [ "123\n123\n161\n123\n123", "29\n20\n13\n35\n120", "101\n86\n119\n108\n92", "123\n123\n161\n123\n163", "29\n20\n9\n35\n120", "101\n86\n119\n125\n92", "123\n123\n161\n123\n263", "29\n20\n4\n35\n120", "101\n26\n119\n125\n92", "123\n123\n40\n123\n263", "29\n20\n4\n...
p03218 Dwango Programming Contest V - Cyclic GCDs
Niwango-kun has \\(N\\) chickens as his pets. The chickens are identified by numbers \\(1\\) to \\(N\\), and the size of the \\(i\\)-th chicken is a positive integer \\(a_i\\). \\(N\\) chickens decided to take each other's hand (wing) and form some cycles. The way to make cycles is represented by a permutation \\(p\\)...
{ "input": [], "output": [] }
{ "input": [ "4\n2 5 2 5", "2\n4 3" ], "output": [ "2", "3" ] }
{ "input": [ "4\n2 5 2 8", "2\n4 4", "4\n2 9 3 8", "4\n0 9 3 8", "2\n3 8", "2\n4 1", "4\n2 1 3 1", "2\n24 8", "2\n5 8", "2\n15 11", "2\n7 8", "4\n3 12 6 4", "2\n10 16", "4\n2 5 3 8", "2\n4 7", "2\n4 8", "4\n0 1 3 8", "4\n0 1 2 8", "2\n4 0", ...
p03367 AtCoder Grand Contest 023 - Inversions
Snuke has an integer sequence A whose length is N. He likes permutations of (1, 2, ..., N), P, that satisfy the following condition: * P_i \leq A_i for all i ( 1 \leq i \leq N ). Snuke is interested in the inversion numbers of such permutations. Find the sum of the inversion numbers over all permutations that satis...
{ "input": [], "output": [] }
{ "input": [ "5\n4 4 4 4 4", "30\n22 30 15 20 10 29 11 29 28 11 26 10 18 28 22 5 29 16 24 24 27 10 21 30 29 19 28 27 18 23", "3\n2 3 3", "6\n4 2 5 1 6 3" ], "output": [ "0", "848414012", "4", "7" ] }
{ "input": [ "5\n4 4 4 4 2", "30\n22 30 15 20 10 29 11 29 28 11 26 10 18 28 22 5 29 10 24 24 27 10 21 30 29 19 28 27 18 23", "3\n2 3 1", "30\n22 30 1 20 10 29 11 29 28 11 26 10 18 28 22 5 29 16 24 24 27 10 21 30 29 19 28 27 18 23", "30\n22 30 15 20 10 29 11 26 28 11 26 10 18 28 22 5 29 10 24 24 27...
p03529 CODE FESTIVAL 2017 Final - Mancala
Consider the following game: * The game is played using a row of N squares and many stones. * First, a_i stones are put in Square i\ (1 \leq i \leq N). * A player can perform the following operation as many time as desired: "Select an integer i such that Square i contains exactly i stones. Remove all the stones from S...
{ "input": [], "output": [] }
{ "input": [ "20 17", "2 2" ], "output": [ "983853488", "10" ] }
{ "input": [ "36 17", "4 2", "36 18", "4 3", "36 22", "59 22", "3 2", "49 17", "4 0", "36 9", "4 1", "29 22", "59 35", "6 1", "62 9", "8 1", "72 35", "12 1", "88 9", "72 32", "5 1", "3 3", "41 17", "2 1", "36 12", ...
p03690 AtCoder Grand Contest 016 - XOR Replace
There is a sequence of length N: a = (a_1, a_2, ..., a_N). Here, each a_i is a non-negative integer. Snuke can repeatedly perform the following operation: * Let the XOR of all the elements in a be x. Select an integer i (1 ≤ i ≤ N) and replace a_i with x. Snuke's objective is to match a with another sequence b = (...
{ "input": [], "output": [] }
{ "input": [ "3\n0 1 2\n3 1 0", "4\n0 1 2 3\n1 0 3 2", "3\n0 1 2\n0 1 2", "2\n1 1\n0 0" ], "output": [ "2", "5", "0", "-1" ] }
{ "input": [ "3\n0 1 2\n3 1 1", "3\n0 0 1\n1 0 0", "3\n1 -3 1\n-3 -3 1", "4\n0 1 2 3\n1 0 3 4", "3\n0 2 2\n0 1 2", "2\n1 1\n-1 0", "3\n0 1 2\n3 0 0", "4\n0 1 2 0\n1 0 3 4", "3\n0 2 4\n0 1 2", "2\n2 1\n-1 0", "3\n0 1 2\n5 0 0", "4\n0 1 3 0\n1 0 3 4", "3\n0 4 4\n0 1 2...
p03843 AtCoder Grand Contest 008 - Black Radius
There is a tree with N vertices. The vertices are numbered 1 through N. For each 1 ≤ i ≤ N - 1, the i-th edge connects vertices a_i and b_i. The lengths of all the edges are 1. Snuke likes some of the vertices. The information on his favorite vertices are given to you as a string s of length N. For each 1 ≤ i ≤ N, s_i...
{ "input": [], "output": [] }
{ "input": [ "4\n1 2\n1 3\n1 4\n1100", "5\n1 2\n1 3\n1 4\n4 5\n11111", "6\n1 2\n1 3\n1 4\n2 5\n2 6\n100011" ], "output": [ "4", "11", "8" ] }
{ "input": [ "4\n1 2\n2 3\n1 4\n1100", "6\n1 2\n1 3\n1 4\n2 5\n2 6\n101011", "4\n2 2\n2 3\n1 4\n1100", "4\n2 4\n2 3\n1 4\n1100", "4\n2 4\n2 3\n2 4\n1100", "4\n1 2\n1 3\n1 3\n1100", "5\n1 2\n1 3\n1 4\n3 5\n11111", "4\n1 2\n1 3\n1 3\n0100", "5\n1 2\n1 3\n1 4\n5 5\n11111", "5\n2 2...
p04010 AtCoder Grand Contest 004 - Namori
You are given an undirected graph with N vertices and M edges. Here, N-1≤M≤N holds and the graph is connected. There are no self-loops or multiple edges in this graph. The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects vertices a_i and b_i. The color of each vertex can be e...
{ "input": [], "output": [] }
{ "input": [ "6 5\n1 2\n1 3\n1 4\n2 5\n2 6", "3 2\n1 2\n2 3", "6 6\n1 2\n2 3\n3 1\n1 4\n1 5\n1 6", "4 4\n1 2\n2 3\n3 4\n4 1" ], "output": [ "5", "-1", "7", "2" ] }
{ "input": [ "6 0\n1 2\n1 3\n1 4\n2 5\n2 6", "3 1\n1 2\n2 3", "6 6\n2 2\n2 3\n3 1\n1 4\n1 5\n1 6", "6 0\n1 2\n1 6\n1 4\n2 5\n2 6", "6 0\n0 2\n1 6\n1 4\n2 5\n2 6", "6 0\n0 2\n1 6\n1 4\n2 8\n2 6", "6 0\n0 1\n1 6\n1 4\n2 8\n2 6", "6 0\n0 1\n1 6\n1 4\n2 7\n2 6", "7 0\n0 1\n1 6\n1 4\n2 ...
p00096 Sum of 4 Integers II
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000. a + b + c + d = n Create a program that outputs the number of combinations that satisfy the conditions. Input Given multiple datasets. Each dataset is given n on one row. Please process until the end of the inpu...
{ "input": [], "output": [] }
{ "input": [ "2\n3\n35" ], "output": [ "10\n20\n8436" ] }
{ "input": [ "2\n0\n35", "2\n-1\n35", "2\n-1\n24", "2\n-1\n43", "2\n-1\n72", "2\n-1\n81", "2\n-1\n61", "2\n-1\n82", "2\n0\n82", "2\n-1\n59", "2\n-1\n100", "2\n-2\n110", "2\n-2\n111", "2\n2\n35", "2\n0\n63", "2\n-1\n21", "2\n-1\n17", "2\n0\n43", ...
p00228 Seven Segments
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments). The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to d...
{ "input": [], "output": [] }
{ "input": [ "3\n0\n5\n1\n1\n0\n-1" ], "output": [ "0111111\n1010010\n1101011\n0111111" ] }
{ "input": [ "3\n0\n5\n1\n1\n1\n-1", "3\n0\n9\n1\n1\n0\n-1", "3\n0\n5\n1\n1\n2\n-1", "3\n1\n9\n1\n1\n0\n-1", "3\n0\n6\n1\n1\n2\n-1", "3\n1\n9\n0\n1\n0\n-1", "3\n0\n5\n0\n1\n0\n-1", "3\n1\n5\n1\n1\n0\n-1", "3\n0\n6\n1\n1\n1\n-1", "3\n0\n7\n1\n1\n0\n-1", "3\n1\n1\n1\n1\n0\n-1...
p00390 A Round Table for Sages
$N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation. * If sage $i$ is right-handed and a left-handed sage sits on his right, a level of frustration $w_i$ occurs to him. A right-handed sage on his right d...
{ "input": [], "output": [] }
{ "input": [ "3\n0 0 0\n1 2 3", "5\n1 0 0 1 0\n2 3 5 1 2" ], "output": [ "0", "3" ] }
{ "input": [ "3\n0 0 0\n1 1 3", "5\n1 0 0 1 0\n2 3 6 1 2", "5\n1 1 0 1 0\n4 3 5 1 4", "5\n1 1 0 1 0\n4 3 0 1 4", "5\n1 0 0 1 0\n2 3 5 2 2", "3\n0 1 0\n1 1 2", "3\n0 0 1\n1 2 5", "3\n0 0 1\n1 0 7", "3\n0 0 1\n1 0 14", "5\n1 1 0 1 0\n1 3 1 -2 4", "3\n0 0 1\n-2 -1 14", "3\...
p00606 Cleaning Robot
Dr. Asimov, a robotics researcher, loves to research, but hates houseworks and his house were really dirty. So, he has developed a cleaning robot. As shown in the following figure, his house has 9 rooms, where each room is identified by an alphabet: <image> The robot he developed operates as follows: * If the bat...
{ "input": [], "output": [] }
{ "input": [ "1\nE A C\n1\nE B C\n2\nE A B\n0" ], "output": [ "0.00000000\n0.25000000\n0.06250000" ] }
{ "input": [ "1\nD A C\n1\nE B C\n2\nE A B\n0", "1\nD A C\n1\nE B C\n2\nF A B\n0", "1\nD A C\n0\nE B C\n2\nF A B\n0", "1\nC A C\n0\nE B C\n2\nF A B\n0", "1\nE A B\n1\nE B C\n2\nE A B\n0", "1\nD A C\n1\nE A D\n2\nF A B\n0", "1\nC A D\n1\nD B C\n2\nF A B\n0", "1\nD A C\n1\nE A D\n3\nF A ...
p00743 Discrete Speed
Consider car trips in a country where there is no friction. Cars in this country do not have engines. Once a car started to move at a speed, it keeps moving at the same speed. There are acceleration devices on some points on the road, where a car can increase or decrease its speed by 1. It can also keep its speed there...
{ "input": [], "output": [] }
{ "input": [ "2 0\n1 2\n5 4\n1 5\n1 2 1 1\n2 3 2 2\n3 4 2 2\n4 5 1 1\n6 6\n1 6\n1 2 2 1\n2 3 2 1\n3 6 2 1\n1 4 2 30\n4 5 3 30\n5 6 2 30\n6 7\n1 6\n1 2 1 30\n2 3 1 30\n3 1 1 30\n3 4 100 30\n4 5 1 30\n5 6 1 30\n6 4 1 30\n0 0" ], "output": [ "unreachable\n4.00000\n5.50000\n11.25664" ] }
{ "input": [ "2 0\n1 2\n5 4\n1 5\n1 2 1 1\n2 3 2 2\n3 4 2 2\n4 5 1 1\n6 6\n1 6\n1 2 2 1\n2 3 2 1\n3 6 2 1\n1 4 2 30\n4 5 3 30\n5 6 2 30\n6 7\n1 6\n1 2 1 30\n2 4 1 30\n3 1 1 30\n3 4 100 30\n4 5 1 30\n5 6 1 30\n6 4 1 30\n0 0", "2 0\n1 1\n5 4\n1 5\n1 2 1 1\n2 3 2 2\n3 4 2 2\n4 5 1 1\n6 6\n1 6\n1 2 2 1\n2 3 2 1\n...
p00882 Hobby on Rails
ICPC (International Connecting Points Company) starts to sell a new railway toy. It consists of a toy tramcar and many rail units on square frames of the same size. There are four types of rail units, namely, straight (S), curve (C), left-switch (L) and right-switch (R) as shown in Figure 9. A switch has three ends, na...
{ "input": [], "output": [] }
{ "input": [ "5 2\nC L S R C\nC C S C C\n6 4\nC C C C C C\nS L R R C S\nS S S L C S\nC C C C C C\n6 6\nC L S S S C\nC C C S S C\nC C C S S C\nC L C S S C\nC C L S S C\nC S L S S C\n6 6\nC S S S S C\nS C S L C S\nS C S R C S\nS C L S C S\nS C R S C S\nC S S S S C\n4 4\nS C C S\nS C L S\nS L C S\nC C C C\n6 4\nC R ...
{ "input": [ "5 2\nC L S R C\nC C T C C\n6 4\nC C C C C C\nS L R R C S\nS S S L C S\nC C C C C C\n6 6\nC L S S S C\nC C C S S C\nC C C S S C\nC L C S S C\nC C L S S C\nC S L S S C\n6 6\nC S S S S C\nS C S L C S\nS C S R C S\nS C L S C S\nS C R S C S\nC S S S S C\n4 4\nS C C S\nS C L S\nS L C S\nC C C C\n6 4\nC R ...
p01013 Cone Cut
Problem In this problem, a straight line passing through a certain point X and a certain point Y in the three-dimensional space is written as a straight line XY. A cone and a point P inside the cone are given in three-dimensional space. Let point Q be the intersection of a straight line passing through point P and pe...
{ "input": [], "output": [] }
{ "input": [ "0 0 10\n0 0 0 4\n0 0 1" ], "output": [ "91.769438 75.782170" ] }
{ "input": [ "0 -1 10\n0 0 0 4\n0 0 1", "0 -1 10\n0 -1 0 4\n0 0 1", "0 -1 20\n0 -1 0 4\n0 0 1", "0 -1 10\n0 0 0 4\n-1 0 1", "0 -1 10\n-1 -1 0 4\n0 0 1", "0 -2 10\n0 0 0 4\n-1 0 1", "0 -1 10\n0 -1 0 4\n0 0 2", "0 -2 10\n0 0 0 4\n-1 -1 1", "0 -1 10\n0 -1 1 4\n0 0 2", "0 -3 10\n0 ...
p01146 Princess in Danger
Princess in Danger Princess crisis English text is not available in this practice contest. A brave princess in a poor country's tomboy is married to another country for a political marriage. However, a villain who was trying to kill the princess attacked him on the way to his wife, and the princess was seriously inj...
{ "input": [], "output": [] }
{ "input": [ "2 1 0 1 0 1\n0 1 2\n3 1 1 2 0 1\n2\n0 2 1\n1 2 1\n3 2 1 2 0 1\n2\n0 2 1\n1 2 1\n4 4 1 4 1 3\n2\n0 1 2\n1 2 4\n0 2 1\n3 0 3\n5 3 2 6 0 3\n1 2\n2 1 2\n1 0 1\n3 4 1\n2 4 1\n4 1 2\n2 0 2\n5 4 2 6 0 3\n1 2\n4 2 4\n2 1 2\n4 3 1\n0 1 5\n1 4 2\n2 0 3\n0 0 0 0 0 0" ], "output": [ "Help!\n3\n2\n10\n5\...
{ "input": [ "2 1 0 1 0 1\n0 1 2\n3 1 1 2 0 1\n2\n0 2 1\n1 2 1\n3 2 1 2 0 1\n2\n0 2 1\n1 2 1\n4 4 1 4 1 3\n2\n0 1 2\n1 2 4\n0 2 1\n3 0 3\n5 3 2 6 0 3\n1 2\n2 1 2\n1 0 1\n3 4 1\n2 4 1\n4 1 2\n2 0 2\n5 4 2 6 0 3\n1 2\n4 2 4\n2 2 2\n4 3 1\n0 1 5\n1 4 2\n2 0 3\n0 0 0 0 0 0", "2 1 0 1 0 1\n0 1 2\n3 1 1 2 0 1\n2\n0...
p01284 Erratic Sleep Habits
Peter is a person with erratic sleep habits. He goes to sleep at twelve o'lock every midnight. He gets up just after one hour of sleep on some days; he may even sleep for twenty-three hours on other days. His sleeping duration changes in a cycle, where he always sleeps for only one hour on the first day of the cycle. ...
{ "input": [], "output": [] }
{ "input": [ "2\n1 23\n3\n1 1\n2 1\n3 1\n0" ], "output": [ "2" ] }
{ "input": [ "2\n0 23\n3\n1 1\n2 1\n3 1\n0", "2\n0 23\n3\n1 1\n1 1\n3 1\n0", "2\n1 23\n3\n1 1\n4 1\n3 1\n0", "2\n1 23\n3\n2 1\n10 1\n3 1\n0", "2\n0 23\n3\n1 1\n2 1\n3 2\n0", "2\n0 23\n3\n1 1\n1 0\n3 1\n0", "2\n0 23\n3\n1 2\n1 0\n3 1\n0", "2\n0 23\n3\n1 2\n1 0\n3 2\n0", "2\n0 5\n3\n...
p01454 Remodeling Plan for Neko-Nabe (tentative)
You have a lot of cats at home. Your daily routine is to take a picture of your cat in a clay pot and taking a nap (commonly known as a cat pot). The appearance of some cats curling up and sleeping together in a pot is really lovely. Each cat has a "weight" mi and a "Cute" ci defined. Cute is a numerical value that co...
{ "input": [], "output": [] }
{ "input": [ "8 6 65\n30 98\n27 51\n4 74\n65 87\n49 19\n27 48\n43 7\n35 28\n43 69\n8 47\n64 75\n18 23\n54 29\n40 43", "1 3 10\n1 15\n6 8\n5 9\n8 7", "4 3 12\n3 6\n2 4\n7 9\n10 1\n6 5\n8 4\n15 19" ], "output": [ "8", "6", "2" ] }
{ "input": [ "8 6 65\n30 98\n27 51\n4 74\n65 87\n49 19\n27 48\n43 7\n35 28\n43 69\n8 47\n64 75\n18 23\n7 29\n40 43", "1 3 10\n1 15\n6 8\n5 3\n8 7", "3 3 12\n3 6\n2 4\n7 9\n10 1\n6 5\n8 4\n15 19", "8 6 65\n30 98\n27 65\n4 74\n65 87\n49 19\n27 48\n43 7\n35 28\n43 69\n8 47\n64 75\n18 23\n7 29\n40 43", ...
p01605 Replace
replace replace Problem Statement Given the string S. The following processing is performed in the order of Q pieces. * Replace all the characters c_i contained in S with the character string p_i at the same time. Finally, output (1-indexed) from the A character to the B character of the character string S. Cons...
{ "input": [], "output": [] }
{ "input": [ "aaaa\n2 1 1\na .\na nothing", "original\n1 2 5\nx notchange", "abaz\n3 1 5\na cab\nb .\nc x" ], "output": [ ".", "rigi", "xaxaz" ] }
{ "input": [ "aaaa\n2 1 1\na .\na gnihton", "original\n2 2 5\nx notchange", "original\n2 2 7\nx notchange", "original\n2 2 8\nx notchange", "original\n2 2 4\nx notchange", "baaa\n2 1 1\na .\na nothing", "abaz\n3 1 5\na cab\nb .\nc w", "origioal\n2 2 7\nx notchange", "oqiginal\n1 2 ...
p01766 Soccer
Problem statement We played an AI soccer match between Country A and Country B. You have a table that records the player who had the ball at a certain time and its position. The table consists of N rows, and the i-th row from the top consists of the following elements. * Number of frames f_i * The uniform number of t...
{ "input": [], "output": [] }
{ "input": [ "5\n0 1 0 3 4\n30 1 0 3 4\n90 2 0 6 8\n120 1 1 1 1\n132 2 1 2 2" ], "output": [ "5.00000000 1.00000000\n1.41421356 0.20000000" ] }
{ "input": [ "5\n0 1 0 3 4\n30 1 0 3 4\n90 2 0 6 8\n120 1 1 1 1\n132 0 1 2 2", "5\n0 1 0 3 4\n16 1 0 3 4\n90 2 0 6 8\n120 1 1 1 1\n132 -1 1 2 2", "5\n0 1 0 3 4\n16 1 0 3 4\n90 2 1 6 8\n120 1 1 1 1\n132 -1 1 2 2", "5\n0 1 0 3 6\n16 1 0 3 4\n90 2 1 10 8\n120 1 1 1 1\n132 -1 1 2 2", "5\n0 1 0 3 4\n30...
p01900 Mod!Mod!
C: Mod! Mod! story That's right! I'm looking for eyewitness testimony! A phantom thief has appeared in Aizu! Everyone's horse stick was stolen! Who is the culprit! ?? Unravel! Mod! Mod! Problem statement "Eyes" ... it's a miracle bud that swells in the hearts of the chosen ones ... You can steal anything with the s...
{ "input": [], "output": [] }
{ "input": [ "6\n2 5 2 5 2 1" ], "output": [ "5" ] }
{ "input": [ "6\n2 5 2 6 2 1", "6\n1 25 1 10 1 3", "6\n0 5 0 11 2 2", "6\n0 3 0 9 0 0", "6\n2 5 0 6 2 1", "6\n2 9 0 6 2 1", "6\n2 9 1 6 2 1", "6\n0 9 1 6 2 1", "6\n0 9 1 6 2 2", "6\n0 9 1 6 2 3", "6\n0 9 1 5 2 3", "6\n0 9 1 3 2 3", "6\n0 10 1 3 2 3", "6\n0 20 1 ...
p02037 Tile
problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge o...
{ "input": [], "output": [] }
{ "input": [ "5 8\n2 2" ], "output": [ "8" ] }
{ "input": [ "5 8\n3 2", "5 8\n6 2", "6 8\n6 3", "12 8\n6 3", "12 8\n9 3", "16 8\n9 3", "27 8\n9 6", "27 8\n9 9", "27 14\n9 9", "27 14\n9 16", "27 15\n5 16", "27 9\n5 16", "0 9\n5 29", "-1 10\n2 49", "-1 12\n4 49", "12 8\n11 3", "12 8\n17 3", "16...
p02181 AOR-String
problem Given $ N $ strings $ S_i $. Find the maximum number of "AOR" in the string obtained by connecting $ S_i $ in any order. output Output the maximum number of "AOR" contained in the character string obtained by connecting $ S_i $ in any order. Also, output a line feed at the end. Example Input 2 AORA OR ...
{ "input": [], "output": [] }
{ "input": [ "2\nAORA\nOR" ], "output": [ "2" ] }
{ "input": [ "2\nAORA\nPR", "2\nAROA\nRQ", "2\nAORA\nRP", "2\nAORA\nRQ", "2\nAQOA\nRQ", "2\nAQOA\nRP", "2\nAQOA\nPR", "2\nAQOA\nPQ", "2\nAQOA\nQP", "2\n@QOA\nPQ", "2\n@QOA\nQP", "2\n@QOA\nPP", "2\n?QOA\nPP", "2\n?QOA\nPO", "2\nAOQ?\nPO", "2\nAOQ?\nOP", ...
p02323 Traveling Salesman Problem
For a given weighted directed graph G(V, E), find the distance of the shortest route that meets the following criteria: * It is a closed cycle where it ends at the same point it starts. * It visits each vertex exactly once. Constraints * 2 ≤ |V| ≤ 15 * 0 ≤ di ≤ 1,000 * There are no multiedge Input |V| |E| s0 t0 d...
{ "input": [], "output": [] }
{ "input": [ "3 3\n0 1 1\n1 2 1\n0 2 1", "4 6\n0 1 2\n1 2 3\n1 3 9\n2 0 1\n2 3 6\n3 2 4" ], "output": [ "-1", "16" ] }
{ "input": [ "3 3\n0 0 1\n1 2 1\n0 2 1", "4 6\n0 1 2\n2 2 3\n1 3 9\n2 0 1\n2 3 6\n3 2 4", "4 6\n0 1 2\n2 2 3\n1 3 1\n2 0 1\n2 3 6\n3 2 4", "4 6\n0 1 2\n2 2 3\n1 3 14\n2 0 1\n2 3 19\n3 2 4", "1 1\n0 0 0\n1 2 1\n0 2 1", "4 6\n0 1 2\n2 2 3\n1 3 8\n2 0 1\n2 3 19\n3 2 4", "3 3\n0 0 1\n2 2 1\n0 ...
p02468 Power
For given integers m and n, compute mn (mod 1,000,000,007). Here, A (mod M) is the remainder when A is divided by M. Constraints * 1 ≤ m ≤ 100 * 1 ≤ n ≤ 109 Input m n Two integers m and n are given in a line. Output Print mn (mod 1,000,000,007) in a line. Examples Input 2 3 Output 8 Input 5 8 Output...
{ "input": [], "output": [] }
{ "input": [ "2 3", "5 8" ], "output": [ "8", "390625" ] }
{ "input": [ "2 1", "5 9", "2 2", "7 9", "3 3", "13 9", "1 3", "13 1", "12 1", "3 1", "0 1", "4 3", "5 15", "6 9", "2 4", "2 9", "3 4", "12 2", "-1 1", "-2 1", "4 4", "2 15", "6 8", "4 9", "3 2", "4 5", "14 2",...
acball
Akhil has many balls of white and black colors. One day, he was playing with them. During the play, he arranged the balls into two rows both consisting of N number of balls. These two rows of balls are given to you in the form of strings X, Y. Both these string consist of 'W' and 'B', where 'W' denotes a white colored ...
{ "input": [], "output": [] }
{ "input": [ "1\nWBWB\nWBBB" ], "output": [ "BWBW\n" ] }
{ "input": [ "1\nBWBW\nWBBB", "1\nBWWB\nWBBB", "1\nWWBB\nWBBB", "1\nWBWB\nBBBW", "1\nBWBW\nBBBW", "1\nBBWW\nBBBW", "1\nBWWB\nBBBW", "1\nBWWB\nBBWB", "1\nWBBW\nBBBW", "1\nWBWB\nBBWB", "1\nBBWW\nWBBB", "1\nWWBB\nBBBW", "1\nBWBW\nBWBB", "1\nWWBB\nBWBB", "1\nBBW...
chefpath
Chef is stuck in a two dimensional maze having N rows and M columns. He needs to get out of the maze as soon as possible and arrive at the kitchen in order to serve his hungry customers. But, he can get out of the maze only if he is able to successfully find any magical path in the given maze. A path is defined as ma...
{ "input": [], "output": [] }
{ "input": [ "1\n2 2" ], "output": [ "Yes\n" ] }
{ "input": [ "1\n2 4", "1\n8 1", "1\n4 4", "1\n8 4", "1\n2 1", "1\n4 7", "1\n8 3", "1\n8 5", "1\n8 7", "1\n8 12", "1\n8 6", "1\n13 1", "1\n10 1", "1\n1 2", "1\n3 5", "1\n4 1", "1\n4 13", "1\n7 3", "1\n13 5", "1\n15 7", "1\n12 12", ...
dmsg
Dilku and Bhopu live in Artland. Dilku loves Bhopu and he writes a message : “iloveyou” on paper and wishes to send it to Bhopu. As Dilku is busy making an artwork, he asks his friend Raj to send the message to Bhopu. However Raj has a condition that he may add/remove some characters and jumble the letters of the mes...
{ "input": [], "output": [] }
{ "input": [ "abcvleouioydef", "iloveyou", "ulrvysioqjifo" ], "output": [ "happy", "happy", "sad" ] }
{ "input": [], "output": [] }
ism05
On a Planet where people are obssessed with Numbers, they have human definitions for relation among Numbers. In one such case, they have designated a father number to be a number formed by the sum of the child number's digits along with the child number itself. For example, for number 481, (4+8+1+481=)494 is the father...
{ "input": [], "output": [] }
{ "input": [ "3\n216\n121\n2005" ], "output": [ "198\nNONE\n1979" ] }
{ "input": [ "3\n427\n121\n2005", "3\n427\n38\n2005", "3\n427\n38\n2635", "3\n427\n37\n2635", "3\n229\n37\n2635", "3\n337\n37\n2635", "3\n643\n37\n2635", "3\n643\n37\n4817", "3\n643\n53\n4817", "3\n643\n20\n7968", "3\n643\n13\n7968", "3\n643\n13\n10804", "3\n1030\n1...
nokia
To protect people from evil, a long and tall wall was constructed a few years ago. But just a wall is not safe, there should also be soldiers on it, always keeping vigil. The wall is very long and connects the left and the right towers. There are exactly N spots (numbered 1 to N) on the wall for soldiers. The K^t...
{ "input": [], "output": [] }
{ "input": [ "4\n3 8\n3 9\n2 4\n5 25" ], "output": [ "0\n0\n-1\n5\n" ] }
{ "input": [ "4\n3 8\n3 9\n2 4\n8 25", "4\n5 8\n3 9\n2 4\n8 25", "4\n5 16\n5 9\n2 1\n8 25", "4\n5 31\n5 9\n2 1\n8 25", "4\n9 31\n5 9\n1 0\n8 25", "4\n4 15\n5 9\n1 0\n8 25", "4\n3 8\n3 9\n2 4\n5 49", "4\n5 8\n1 9\n2 4\n8 25", "4\n5 16\n3 9\n1 4\n8 25", "4\n5 31\n5 9\n1 0\n8 47",...
seavote
Sereja conducted a voting about N of his opinions. Ai percent of people voted for opinion number i. This statistics is called valid if sum of all Ai is equal to 100. Now let us define rounding up of a statistics A. If Ai is not an integer, it will be rounded up to next integer. Otherwise it will be left as it is...
{ "input": [], "output": [] }
{ "input": [ "3\n3\n30 30 30\n4\n25 25 25 25\n2\n50 51" ], "output": [ "NO\nYES\nYES\n" ] }
{ "input": [ "3\n3\n30 30 30\n4\n25 40 25 25\n2\n50 51", "3\n3\n30 15 30\n4\n25 25 25 25\n2\n50 51", "3\n3\n30 30 30\n4\n25 40 25 25\n2\n50 36", "3\n3\n30 30 30\n4\n25 25 25 25\n2\n31 51", "3\n3\n7 30 63\n4\n25 48 10 19\n2\n50 80", "3\n3\n40 30 30\n4\n14 38 43 25\n2\n50 36", "3\n3\n30 30 3...
1385_G. Columns Swaps
You are given a table a of size 2 × n (i.e. two rows and n columns) consisting of integers from 1 to n. In one move, you can choose some column j (1 ≤ j ≤ n) and swap values a_{1, j} and a_{2, j} in it. Each column can be chosen no more than once. Your task is to find the minimum number of moves required to obtain pe...
{ "input": [], "output": [] }
{ "input": [ "6\n4\n1 2 3 4\n2 3 1 4\n5\n5 3 5 1 4\n1 2 3 2 4\n3\n1 2 1\n3 3 2\n4\n1 2 2 1\n3 4 3 4\n4\n4 3 1 4\n3 2 2 1\n3\n1 1 2\n3 2 2\n" ], "output": [ "0\n\n2\n1 4 \n1\n1 \n2\n1 2 \n2\n1 2 \n-1\n" ] }
{ "input": [ "6\n4\n1 2 3 4\n2 3 1 4\n5\n5 3 5 1 4\n1 2 3 2 4\n3\n1 2 1\n3 3 2\n4\n1 2 2 1\n3 4 3 4\n4\n4 3 1 4\n3 2 2 2\n3\n1 1 2\n3 2 2\n", "6\n4\n1 2 3 4\n2 3 1 4\n5\n5 3 5 1 4\n1 2 3 2 4\n3\n1 2 1\n3 3 2\n4\n1 2 3 1\n3 4 3 4\n4\n4 3 1 4\n3 2 2 2\n3\n1 1 2\n3 2 2\n", "6\n4\n1 2 3 4\n2 3 1 4\n5\n5 3 5 1...
1428_C. ABBB
Zookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a substring, the substring gets deleted from the string and the remaining parts of the string get concatenated....
{ "input": [], "output": [] }
{ "input": [ "3\nAAA\nBABA\nAABBBABBBB\n" ], "output": [ "3\n2\n0\n" ] }
{ "input": [ "3\nAAA\nAABA\nAABBBABBBB\n", "3\nAAB\nBABA\nAABBBABBBB\n", "3\nAAB\nBABA\nBBBBABBBAA\n", "3\nAAB\nBAAA\nBBBBABBBAA\n", "3\nAAA\nBABB\nAABBBABBBB\n", "3\nAAB\nABAB\nBBBBABBBAA\n", "3\nBAA\nBAAA\nBBBBABBBAA\n", "3\nBBA\nBAAA\nBBABABBBBB\n", "3\nAAA\nBABB\nBBBBABBBAA\n",...
1451_C. String Equality
Ashish has two strings a and b, each of length n, and an integer k. The strings only contain lowercase English letters. He wants to convert string a into string b by performing some (possibly zero) operations on a. In one move, he can either * choose an index i (1 ≤ i≤ n-1) and swap a_i and a_{i+1}, or * choos...
{ "input": [], "output": [] }
{ "input": [ "4\n3 3\nabc\nbcd\n4 2\nabba\nazza\n2 1\nzz\naa\n6 2\naaabba\nddddcc\n" ], "output": [ "\nNo\nYes\nNo\nYes\n" ] }
{ "input": [ "4\n1 3\nabc\nbcd\n4 2\nabba\nazza\n2 1\nzz\naa\n6 2\naaabba\nddddcc\n", "4\n3 3\nabc\nbcd\n4 2\nabba\nazza\n2 1\nzz\naa\n6 2\naaabba\nedddcc\n", "4\n3 3\nabb\nacd\n4 2\naaba\nazza\n2 1\nzz\naa\n6 2\naaabba\nedddcc\n", "4\n1 3\nabc\nbcd\n4 2\nabba\nayza\n2 1\nzz\naa\n6 1\naaabba\nddddcc\n...
1475_C. Ball in Berland
At the school where Vasya is studying, preparations are underway for the graduation ceremony. One of the planned performances is a ball, which will be attended by pairs of boys and girls. Each class must present two couples to the ball. In Vasya's class, a boys and b girls wish to participate. But not all boys and not...
{ "input": [], "output": [] }
{ "input": [ "3\n3 4 4\n1 1 2 3\n2 3 2 4\n1 1 1\n1\n1\n2 2 4\n1 1 2 2\n1 2 1 2\n" ], "output": [ "\n4\n0\n2\n" ] }
{ "input": [ "3\n6 4 4\n1 1 2 3\n2 3 2 4\n1 1 1\n1\n1\n2 2 4\n1 1 2 2\n1 2 1 2\n", "3\n6 4 4\n1 1 2 3\n2 3 2 3\n2 1 1\n1\n1\n2 2 4\n1 1 2 2\n1 2 1 2\n", "3\n6 4 4\n1 1 2 3\n2 3 1 4\n1 1 1\n1\n1\n2 2 4\n1 1 2 2\n1 2 1 2\n", "3\n6 4 4\n1 1 4 3\n2 3 2 2\n1 1 1\n1\n1\n2 2 4\n1 1 2 2\n1 2 1 2\n", "3\n6...
530_B. String inside out
You are given a string S of even length s1..s2n . Perform the following manipulations: * divide it into two halves s1..sn and sn + 1..s2n * reverse each of them sn..s1 and s2n..sn + 1 * concatenate the resulting strings into sn..s1s2n..sn + 1 Output the result of these manipulations. Input The only line of ...
{ "input": [], "output": [] }
{ "input": [ "codeforces\n", "qwertyasdfgh\n" ], "output": [ "fedocsecro\n", "ytrewqhgfdsa\n" ] }
{ "input": [], "output": [] }
find-the-hub
After decrypting the code Enigma crew came to know that there are N locations where bombs has been planted. X1, X2 …. Xn are the N locations. Among this locations, one X location is the central hub which control all the other Xn-1 location. 1 or more than 1 signal is send to N locations. The decrypted code simplified ...
{ "input": [], "output": [] }
{ "input": [ "10\n1 3 5 17 21 17 5 11 10 40\n\nSAMPLE" ], "output": [ "17\n2\n" ] }
{ "input": [ "10\n1 3 5 17 21 17 5 11 7 40\n\nSAMPLE", "10\n1 3 5 17 19 17 5 11 1 38\n\nSAMPLE", "10\n2 3 5 17 21 29 5 16 7 38\n\nSAMPLE", "10\n1 3 5 17 19 5 5 19 1 38\n\nSAMPLD", "10\n1 0 4 4 19 5 5 9 1 23\n\nSAMPLE", "10\n1 3 5 32 21 17 5 22 4 18\n\nSAMPME", "10\n1 3 5 17 19 5 2 10 1 41\...
mattey-multiplication-6
Mattey has an assignment that he should submit tomorrow. The assignment has one question which asks to write a program to multiply two numbers without using ''* operator. As Mattey finds no interest in this subject, he never listens to classes and so do not know about shift operators. He comes to you to learn about th...
{ "input": [], "output": [] }
{ "input": [ "2\n2 1\n2 3\n\nSAMPLE" ], "output": [ "(2<<0)\n(2<<1) + (2<<0)\n" ] }
{ "input": [ "2\n3 1\n2 3\n\nSAMPLE", "2\n1 1\n2 3\n\nSAMPKE", "2\n2 1\n2 3\n\nSAMPKE", "2\n2 1\n2 1\n\nSAMPKE", "2\n1 1\n2 1\n\nSAMPKE", "2\n3 1\n3 3\n\nSAMPLE", "2\n6 1\n2 3\n\nSAMPLE", "2\n1 2\n2 3\n\nSAMPKE", "2\n2 1\n3 1\n\nSAMPKE", "2\n6 1\n3 3\n\nSAMPLE", "2\n2 1\n2 ...
p02547 AtCoder Beginner Contest 179 - Go to Jail
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}. Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold. Constraints * 3 \...
{ "input": [], "output": [] }
{ "input": [ "5\n1 2\n6 6\n4 4\n3 3\n3 2", "5\n1 1\n2 2\n3 4\n5 5\n6 6", "6\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6" ], "output": [ "Yes", "No", "Yes" ] }
{ "input": [ "5\n1 2\n6 6\n4 4\n3 3\n3 3", "5\n1 2\n2 2\n3 4\n5 5\n6 6", "6\n1 1\n2 2\n3 3\n4 4\n5 5\n10 6", "5\n1 2\n6 6\n4 1\n3 3\n3 2", "5\n1 2\n2 2\n3 4\n9 5\n6 6", "6\n1 0\n2 2\n3 3\n4 4\n5 5\n10 6", "5\n1 0\n6 6\n4 1\n3 3\n3 2", "5\n1 2\n2 2\n3 4\n9 5\n0 6", "6\n1 0\n2 2\n3 3...
p02678 AtCoder Beginner Contest 168 - .. (Double Dots)
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in th...
{ "input": [], "output": [] }
{ "input": [ "6 9\n3 4\n6 1\n2 4\n5 3\n4 6\n1 5\n6 2\n4 5\n5 6", "4 4\n1 2\n2 3\n3 4\n4 2" ], "output": [ "Yes\n6\n5\n5\n1\n1", "Yes\n1\n2\n2" ] }
{ "input": [ "4 4\n1 4\n2 3\n3 4\n4 2", "6 9\n3 4\n6 1\n2 4\n5 3\n4 6\n1 5\n6 2\n4 5\n5 3", "4 4\n1 4\n2 3\n4 4\n4 2", "6 9\n3 4\n6 1\n2 4\n5 3\n4 6\n1 5\n6 4\n4 5\n5 3", "6 9\n3 4\n6 1\n2 1\n5 3\n4 6\n1 5\n6 4\n4 5\n5 3", "6 5\n3 4\n6 1\n2 1\n5 3\n4 6\n1 5\n6 4\n4 5\n3 3", "6 9\n3 4\n6 1\...
p02806 Dwango Programming Contest 6th - Falling Asleep
Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, w...
{ "input": [], "output": [] }
{ "input": [ "15\nypnxn 279\nkgjgwx 464\nqquhuwq 327\nrxing 549\npmuduhznoaqu 832\ndagktgdarveusju 595\nwunfagppcoi 200\ndhavrncwfw 720\njpcmigg 658\nwrczqxycivdqn 639\nmcmkkbnjfeod 992\nhtqvkgkbhtytsz 130\ntwflegsjz 467\ndswxxrxuzzfhkp 989\nszfwtzfpnscgue 958\npmuduhznoaqu", "3\ndwango 2\nsixth 5\nprelims 25...
{ "input": [ "15\nypnxn 279\nkgjgwx 464\nqquhuwq 327\nrxing 549\npmuduhznoaqu 832\ndagktgdarveusju 595\nwunfagppcoi 200\ndhavrncwfw 720\njpcmigg 658\nwrczqxycivdqn 639\nmcmkkbnjfeod 992\nzstythbkgkvqth 130\ntwflegsjz 467\ndswxxrxuzzfhkp 989\nszfwtzfpnscgue 958\npmuduhznoaqu", "1\nabcde 0000\nabcde", "15\n...
p02942 AtCoder Grand Contest 037 - Sorting a Grid
We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}. You need to rearrange these numbers as follows: 1. First, for each of the N rows, rearrange the number...
{ "input": [], "output": [] }
{ "input": [ "3 2\n2 6\n4 3\n1 5", "3 4\n1 4 7 10\n2 5 8 11\n3 6 9 12" ], "output": [ "2 6\n4 3\n5 1\n2 1\n4 3\n5 6", "1 4 7 10\n5 8 11 2\n9 12 3 6\n1 4 3 2\n5 8 7 6\n9 12 11 10" ] }
{ "input": [ "3 2\n2 5\n4 3\n1 5", "3 2\n2 6\n4 3\n2 5", "3 2\n1 6\n4 3\n2 5", "3 2\n1 6\n4 4\n2 5", "3 4\n1 4 7 10\n2 6 8 11\n3 6 9 12", "3 2\n2 5\n3 3\n1 5", "3 2\n2 6\n4 3\n2 6", "3 2\n1 6\n4 3\n2 6", "3 2\n1 6\n4 3\n1 5", "3 4\n1 4 8 10\n2 5 8 11\n3 6 9 12", "3 4\n1 4 7...
p03079 ExaWizards 2019 - Regular Triangle
You are given three integers A, B and C. Determine if there exists an equilateral triangle whose sides have lengths A, B and C. Constraints * All values in input are integers. * 1 \leq A,B,C \leq 100 Input Input is given from Standard Input in the following format: A B C Output If there exists an equilateral ...
{ "input": [], "output": [] }
{ "input": [ "2 2 2", "3 4 5" ], "output": [ "Yes", "No" ] }
{ "input": [ "2 4 2", "0 0 0", "3 4 2", "2 6 2", "3 4 1", "2 7 2", "3 0 1", "1 7 2", "4 0 1", "0 7 2", "4 0 2", "0 13 2", "5 0 2", "1 13 2", "6 0 2", "1 13 3", "8 0 2", "1 15 3", "8 -1 2", "2 15 3", "15 -1 2", "4 15 3", "13 -1...
p03222 AtCoder Beginner Contest 113 - Number of Amidakuji
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical l...
{ "input": [], "output": [] }
{ "input": [ "2 3 1", "1 3 2", "1 3 1", "7 1 1", "2 3 3", "15 8 5" ], "output": [ "5", "1", "2", "1", "1", "437760187" ] }
{ "input": [ "4 3 1", "1 2 2", "1 5 1", "16 8 5", "4 6 1", "1 9 1", "16 8 3", "8 6 1", "1 9 2", "15 8 3", "9 6 1", "0 9 2", "2 6 1", "2 7 1", "1 7 1", "2 7 2", "2 6 2", "2 2 2", "16 8 7", "3 6 1", "16 9 3", "1 5 2", "15 8 6", ...
p03370 AtCoder Beginner Contest 095 - Bitter Alchemy
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...
{ "input": [], "output": [] }
{ "input": [ "3 1000\n120\n100\n140", "5 3000\n150\n130\n150\n130\n110", "4 360\n90\n90\n90\n90" ], "output": [ "9", "26", "4" ] }
{ "input": [ "3 1001\n120\n100\n140", "5 3000\n150\n130\n150\n130\n100", "3 1001\n120\n110\n140", "4 360\n90\n13\n126\n90", "4 293\n90\n13\n126\n90", "4 293\n144\n13\n126\n90", "4 293\n144\n13\n41\n90", "3 0111\n129\n110\n140", "4 293\n144\n13\n17\n90", "4 293\n144\n13\n27\n90"...
p03532 CODE FESTIVAL 2017 Final - Tree MST
Ringo has a tree with N vertices. The i-th of the N-1 edges in this tree connects Vertex A_i and Vertex B_i and has a weight of C_i. Additionally, Vertex i has a weight of X_i. Here, we define f(u,v) as the distance between Vertex u and Vertex v, plus X_u + X_v. We will consider a complete graph G with N vertices. Th...
{ "input": [], "output": [] }
{ "input": [ "4\n1 3 5 1\n1 2 1\n2 3 2\n3 4 3", "6\n44 23 31 29 32 15\n1 2 10\n1 3 12\n1 4 16\n4 5 8\n4 6 15", "2\n1000000000 1000000000\n2 1 1000000000" ], "output": [ "22", "359", "3000000000" ] }
{ "input": [ "4\n1 3 5 1\n1 2 1\n2 3 2\n2 4 3", "6\n44 23 31 29 32 15\n1 2 10\n1 3 12\n1 4 16\n4 5 8\n5 6 15", "4\n1 3 5 0\n1 2 1\n2 3 2\n2 4 3", "6\n44 33 31 29 32 15\n1 2 10\n1 3 12\n1 4 16\n4 5 8\n5 6 15", "6\n5 33 31 29 32 15\n1 2 10\n1 3 12\n1 4 16\n4 5 8\n5 6 15", "6\n5 33 31 29 32 15\n1...
p03693 AtCoder Beginner Contest 064 - RGB Cards
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer...
{ "input": [], "output": [] }
{ "input": [ "4 3 2", "2 3 4" ], "output": [ "YES", "NO" ] }
{ "input": [ "7 3 2", "2 3 3", "7 3 0", "2 6 3", "7 6 0", "2 6 0", "9 6 0", "0 6 0", "5 6 0", "0 1 0", "8 6 0", "0 0 0", "4 3 3", "2 0 4", "1 3 3", "0 3 0", "2 6 1", "1 6 0", "0 2 0", "8 6 1", "1 0 0", "5 3 3", "2 1 4", "1...
p03846 AtCoder Beginner Contest 050 - Lining Up
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the nu...
{ "input": [], "output": [] }
{ "input": [ "8\n7 5 1 1 7 3 5 3", "7\n6 4 0 2 4 0 2", "5\n2 4 4 0 2" ], "output": [ "16", "0", "4" ] }
{ "input": [ "8\n7 5 1 2 7 3 5 3", "7\n6 4 0 2 4 0 4", "5\n0 4 4 0 2", "7\n6 4 0 2 4 -1 4", "5\n0 4 4 0 1", "7\n6 4 0 2 8 -1 4", "5\n0 4 1 0 1", "7\n6 4 0 2 8 0 4", "5\n0 4 0 0 1", "7\n6 4 1 2 8 0 4", "5\n-1 4 0 0 1", "7\n6 4 1 2 8 -1 4", "5\n-1 4 1 0 1", "7\n6 ...
p04014 AtCoder Beginner Contest 044 - Digit Sum
For integers b (b \geq 2) and n (n \geq 1), let the function f(b,n) be defined as follows: * f(b,n) = n, when n < b * f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b), when n \geq b Here, {\rm floor}(n / b) denotes the largest integer not exceeding n / b, and n \ {\rm mod} \ b denotes the remainder of n div...
{ "input": [], "output": [] }
{ "input": [ "87654\n30", "87654\n138", "87654\n45678", "31415926535\n1", "1\n31415926535" ], "output": [ "10", "100", "-1", "31415926535", "-1" ] }
{ "input": [ "87654\n60", "87654\n178", "87654\n26288", "31415926535\n2", "1\n40483159044", "87654\n58", "87654\n92", "87654\n15577", "31415926535\n4", "87654\n114", "87654\n34", "87654\n5894", "87654\n148", "87654\n33", "87654\n11178", "87654\n131", ...
p00099 Surf Smelt Fishing Contest II
A smelt fishing tournament was held at Lake Hibara. It seems that catch and release is recommended this time. Create a program that reads the participant number and the number of fish caught or released in order as one event, and outputs the participant number and the number of animals that have acquired the most smel...
{ "input": [], "output": [] }
{ "input": [ "3 5\n1 4\n2 5\n1 3\n3 6\n2 7" ], "output": [ "1 4\n2 5\n1 7\n1 7\n2 12" ] }
{ "input": [ "3 5\n1 4\n2 5\n1 3\n3 4\n2 7", "3 5\n1 4\n2 3\n1 3\n3 6\n2 7", "3 5\n1 4\n2 5\n1 3\n3 4\n2 11", "3 5\n1 4\n2 3\n1 3\n3 6\n2 1", "3 5\n1 4\n2 5\n1 5\n3 4\n2 11", "3 5\n1 4\n2 3\n2 3\n3 6\n2 1", "3 5\n1 4\n3 5\n1 5\n3 4\n2 11", "3 5\n1 4\n2 0\n2 3\n3 6\n2 1", "3 5\n1 4\...
p00231 Dangerous Bridge
In Aizuwakamatsu Village, which is located far north of Aizuwakamatsu City, a bridge called "Yabashi" is the only way to move to the surrounding villages. Despite the large number of passers-by, the bridge is so old that it is almost broken. <image> Yabashi is strong enough to withstand up to 150 [kg]. For example,...
{ "input": [], "output": [] }
{ "input": [ "3\n80 0 30\n50 5 25\n90 27 50\n3\n80 0 30\n70 5 25\n71 30 50\n0" ], "output": [ "NG\nOK" ] }
{ "input": [ "3\n80 0 30\n50 5 25\n90 27 50\n3\n80 0 30\n70 5 25\n71 30 84\n0", "3\n80 0 15\n64 5 25\n149 27 50\n3\n80 0 10\n70 10 25\n22 30 84\n0", "3\n80 0 30\n50 5 25\n90 27 50\n3\n80 0 30\n70 5 25\n71 23 50\n0", "3\n1 0 30\n50 5 25\n90 28 50\n3\n80 0 40\n70 5 25\n71 30 84\n0", "3\n80 0 15\n64 ...
p00393 Beautiful Sequence
Alice is spending his time on an independent study to apply to the Nationwide Mathematics Contest. This year’s theme is "Beautiful Sequence." As Alice is interested in the working of computers, she wants to create a beautiful sequence using only 0 and 1. She defines a "Beautiful" sequence of length $N$ that consists on...
{ "input": [], "output": [] }
{ "input": [ "4 3", "4 2" ], "output": [ "3", "8" ] }
{ "input": [ "6 3", "1 2", "6 4", "8 2", "6 1", "2 2", "6 5", "13 2", "10 1", "14 1", "5 2", "27 1", "4 1", "9 3", "10 4", "8 1", "13 4", "6 2", "16 1", "10 2", "13 1", "3 1", "15 4", "7 3", "12 6", "19 2", "9 ...
p00609 Amazing Graze
In 2215 A.D., a war between two planets, ACM and ICPC, is being more and more intense. ACM introduced new combat planes. These planes have a special system that is called Graze, and fighting power of a plane increases when it is close to energy bullets that ICPC combat planes shoot. Both combat planes and energy bull...
{ "input": [], "output": [] }
{ "input": [ "2 2 1\n0 0\n0 4\n2 2\n2 8\n0 0 0" ], "output": [ "2" ] }
{ "input": [ "2 2 1\n0 0\n0 5\n2 2\n2 8\n0 0 0", "2 2 1\n0 0\n0 4\n2 2\n2 12\n0 0 0", "2 2 1\n0 0\n0 5\n2 4\n2 9\n0 0 0", "2 2 1\n0 0\n0 4\n2 2\n2 2\n0 0 0", "2 2 1\n1 0\n0 2\n1 10\n0 8\n0 0 0", "2 2 1\n0 0\n0 5\n2 4\n2 8\n0 0 0", "2 2 1\n0 0\n0 1\n2 2\n2 12\n0 0 0", "2 2 1\n0 0\n0 1\n...
p00746 Pablo Squarson's Headache
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth. At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squ...
{ "input": [], "output": [] }
{ "input": [ "1\n5\n0 0\n0 1\n0 2\n0 3\n12\n0 0\n1 0\n2 0\n3 1\n4 1\n5 1\n6 2\n7 2\n8 2\n9 3\n10 3\n10\n0 2\n1 2\n2 2\n3 2\n2 1\n5 1\n6 1\n7 1\n8 1\n0" ], "output": [ "1 1\n3 3\n4 4\n5 6" ] }
{ "input": [ "1\n5\n0 0\n0 1\n0 2\n0 3\n12\n0 0\n1 1\n2 0\n3 1\n4 1\n5 1\n6 2\n7 2\n8 2\n9 3\n10 3\n10\n0 2\n1 2\n2 2\n3 2\n2 1\n5 1\n6 1\n7 1\n8 1\n0", "1\n5\n0 0\n0 1\n0 2\n0 3\n12\n0 0\n1 0\n2 0\n3 1\n4 1\n5 1\n6 2\n7 2\n8 2\n9 3\n10 3\n10\n0 2\n1 3\n2 2\n3 2\n2 1\n5 1\n6 1\n7 1\n8 1\n0", "1\n5\n0 0\n0...
p00885 Balloon Collecting
"Balloons should be captured efficiently", the game designer says. He is designing an oldfashioned game with two dimensional graphics. In the game, balloons fall onto the ground one after another, and the player manipulates a robot vehicle on the ground to capture the balloons. The player can control the vehicle to mov...
{ "input": [], "output": [] }
{ "input": [ "2\n10 100\n100 270\n2\n10 100\n100 280\n3\n100 150\n10 360\n40 450\n3\n100 150\n10 360\n40 440\n2\n100 10\n50 200\n2\n100 100\n50 110\n1\n15 10\n4\n1 10\n2 20\n3 100\n90 200\n0" ], "output": [ "OK 220\nOK 200\nOK 260\nOK 280\nNG 1\nNG 2\nNG 1\nOK 188" ] }
{ "input": [ "2\n10 100\n100 270\n2\n10 100\n100 280\n3\n100 150\n10 360\n40 450\n3\n100 150\n9 360\n40 440\n2\n100 10\n50 200\n2\n100 100\n50 110\n1\n15 10\n4\n1 10\n2 20\n3 100\n90 200\n0", "2\n10 100\n100 270\n2\n10 100\n110 280\n3\n100 150\n10 360\n40 450\n3\n100 150\n9 360\n40 440\n2\n100 10\n50 200\n2\n...
p01016 Password
Taro had his own personal computer and set a password for login. However, Taro inadvertently forgot the password. Then, remembering that there was a piece of paper with the password written down, Taro found the paper and was surprised to see it. The paper was cut and there were only fragments, and there were some stain...
{ "input": [], "output": [] }
{ "input": [ "KUSATSU\nKSATSU", "ABCABC\nACBA_B", "RUPCUAPC\n__PC", "AIZU\n_A", "ABCDE\nABC" ], "output": [ "No", "No", "Yes", "No", "Yes" ] }
{ "input": [ "KUSATSU\nLSATSU", "RUPCUAOC\n__PC", "ABC@BC\nACBA_B", "AI[U\n_A", "ABCDE\nCBA", "KUSATSU\nLSATRU", "CB@CBA\nACBA_B", "RUPCUAOC\n__OC", "U[IA\n_A", "AACDE\nCBA", "KUSATSU\nLRATSU", "CBACBA\nACBA_B", "RUPCUACO\n__OC", "U[IA\n^A", "AACDE\nBCA", ...
p01149 Blackjack
Brian Jones is an undergraduate student at Advanced College of Metropolitan. Recently he was given an assignment in his class of Computer Science to write a program that plays a dealer of blackjack. Blackjack is a game played with one or more decks of playing cards. The objective of each player is to have the score of...
{ "input": [], "output": [] }
{ "input": [ "4\n5 4\n9 2 8 3 7 4 6 5\nA J\nK Q J T 9 8 7 6\nT 4\n7 J A 6 Q T K 7\n2 2\n2 3 4 K 2 3 4 K" ], "output": [ "18\nblackjack\n21\nbust" ] }
{ "input": [ "4\n5 4\n9 2 8 3 9 4 6 5\nA J\nK Q J T 9 8 7 6\nT 4\n7 J A 6 Q T K 7\n2 2\n2 3 4 K 2 3 4 K", "4\n5 4\n9 2 3 3 9 4 9 5\nA J\nK Q J T 9 8 8 6\nT 7\n7 J A 6 Q T K 7\n2 2\n2 3 4 K 2 3 4 K", "4\n5 4\n9 2 8 3 7 4 6 5\nA J\nK Q J T 9 8 7 6\nT 5\n7 J A 6 Q T K 7\n2 2\n2 3 4 K 2 3 4 K", "4\n5 4\n9...
p01288 Marked Ancestor
You are given a tree T that consists of N nodes. Each node is numbered from 1 to N, and node 1 is always the root node of T. Consider the following two operations on T: * M v: (Mark) Mark node v. * Q v: (Query) Print the index of the nearest marked ancestor of node v which is nearest to it. Initially, only the root no...
{ "input": [], "output": [] }
{ "input": [ "6 3\n1\n1\n2\n3\n3\nQ 5\nM 3\nQ 5\n0 0" ], "output": [ "4" ] }
{ "input": [ "6 3\n2\n1\n2\n3\n3\nQ 5\nM 3\nQ 5\n0 0", "6 3\n1\n1\n2\n3\n3\nQ 5\nM 4\nQ 5\n0 0", "6 3\n0\n1\n2\n3\n3\nQ 5\nM 5\nQ 5\n0 0", "6 3\n0\n1\n2\n3\n1\nQ 5\nM 4\nQ 4\n0 0", "6 3\n1\n2\n2\n6\n3\nQ 1\nM 2\nQ 5\n0 0", "6 3\n1\n1\n3\n3\n3\nQ 5\nM 3\nQ 5\n0 0", "6 3\n1\n1\n0\n3\n3\nQ 5\...
p01457 Carpenters' Language
International Carpenters Professionals Company (ICPC) is a top construction company with a lot of expert carpenters. What makes ICPC a top company is their original language. The syntax of the language is simply given in CFG as follows: S -> SS | (S) | )S( | ε In other words, a right parenthesis can be closed by a...
{ "input": [], "output": [] }
{ "input": [ "3\n0 ( 10\n10 ) 20\n0 ( 10", "3\n0 ( 10\n10 ) 5\n10 ) 5", "3\n0 ) 10\n10 ( 5\n10 ( 5" ], "output": [ "No\nNo\nYes", "No\nNo\nYes", "No\nNo\nYes" ] }
{ "input": [ "3\n0 ( 10\n10 ) 5\n10 ( 5", "3\n-1 ( 10\n10 ) 5\n10 ) 5", "3\n-1 ( 9\n10 ) 9\n20 ( 4", "3\n-1 ) 0\n8 ( 19\n4 ' 2", "3\n-2 ) 0\n7 ) 0\n4 ( 11", "3\n-1 ( 0\n10 ) 4\n20 ( 4", "3\n0 ) 0\n7 * 0\n1 ( 0", "3\n0 ) 10\n10 ( 5\n10 ( 7", "3\n-1 ( 10\n10 ) 5\n10 ( 5", "3\n0 )...
p01608 1
1 Problem Statement There is a bit string of length n. When the i-th bit from the left is 1, the score is a_i points. The number of 1s within the distance w around the i-th bit from the left (= | \\ {j \ in \\ {1, ..., n \\} ∩ \\ {iw, ..., i + w \\} | When the jth bit from the left is 1 \\} |) is odd, the score is b...
{ "input": [], "output": [] }
{ "input": [ "4 1\n3 1 2 7\n13 8 25 9", "2 1\n1 1\n3 3" ], "output": [ "1001", "10" ] }
{ "input": [ "4 1\n3 2 2 7\n13 8 25 9", "2 1\n1 0\n3 3", "2 1\n0 0\n5 3", "3 1\n1 1\n6 8", "4 2\n0 4 1 0\n16 8 19 9", "1 1\n1 1\n6 14", "2 0\n1 1\n10 6", "3 1\n2 1\n6 14", "3 2\n0 4 1 0\n16 8 19 9", "4 0\n0 4 1 0\n16 8 0 9", "4 1\n1 4 0 2\n13 8 2 9", "7 1\n1 2 2 2\n13 2...
p01769 Hopping Hearts
Problem statement N-winged rabbit is on a balance beam of length L-1. The initial position of the i-th rabbit is the integer x_i, which satisfies 0 ≤ x_ {i} \ lt x_ {i + 1} ≤ L−1. The coordinates increase as you move to the right. Any i-th rabbit can jump to the right (ie, move from x_i to x_i + a_i) any number of tim...
{ "input": [], "output": [] }
{ "input": [ "1 3\n0\n1" ], "output": [ "3" ] }
{ "input": [ "1 6\n0\n1", "2 3\n0\n1", "1 6\n1\n1", "2 3\n0\n0", "1 3\n1\n1", "1 11\n0\n1", "1 15\n0\n1", "1 5\n2\n1", "1 8\n0\n1", "1 13\n0\n1", "1 8\n1\n1", "1 11\n1\n1", "1 15\n1\n1", "1 5\n1\n1", "1 9\n0\n1", "1 28\n1\n1", "1 13\n1\n1", "1 0\...
p01903 Overflow of Furo
F: Bath overflows --Overflow of Furo - story The hot spring inn Paro is passionate about the hot springs that it is proud of, and is attracting professional bathers. Bath professionals mainly manage the plumbing of hot springs, and manage and coordinate the complicated and intricate plumbing network that connects mul...
{ "input": [], "output": [] }
{ "input": [ "2 2 4\n1 3 4\n2 4 2\n0 3 3\n4 0 5" ], "output": [ "8" ] }
{ "input": [ "2 3 4\n1 3 4\n2 4 2\n0 3 3\n4 0 5", "3 3 4\n1 3 4\n2 4 3\n0 3 3\n4 0 5", "2 2 4\n1 3 4\n2 4 2\n0 3 2\n4 0 5", "2 3 7\n1 3 4\n2 4 1\n0 3 3\n5 0 5", "2 2 4\n1 3 7\n0 4 4\n0 3 2\n4 1 5", "2 2 4\n1 2 4\n2 4 2\n0 3 2\n4 0 5", "2 3 7\n2 3 3\n2 4 1\n0 3 3\n5 0 5", "2 3 7\n1 3 4\...
p02041 LISum
problem Given the sequence $ A $ of length $ N $. Find the maximum value of $ \ sum B_i $, where $ B $ is one of the longest increasing subsequences of the sequence $ A $. The longest increasing subsequence of the sequence $ A $ is the longest subsequence that satisfies $ A_i <A_j $ with all $ i <j $. output Outp...
{ "input": [], "output": [] }
{ "input": [ "4\n6 4 7 8" ], "output": [ "21" ] }
{ "input": [ "4\n7 4 7 8", "4\n7 4 1 8", "4\n7 4 2 9", "4\n7 4 2 6", "4\n7 4 0 10", "4\n7 8 0 10", "4\n14 8 0 10", "4\n14 15 0 10", "4\n3 9 0 10", "4\n6 4 3 8", "4\n7 5 7 8", "4\n6 4 3 3", "4\n7 8 2 15", "4\n13 4 3 9", "4\n7 4 0 16", "4\n7 14 0 14", ...
p02184 Canisar Cipher
C: Canisal cryptography problem Ebi-chan was given the string C obtained by encrypting a non-negative integer D with "canisal cipher". This cipher replaces each number in decimal notation with a fixed number (not necessarily different from the original). Different numbers will not be replaced with the same number, an...
{ "input": [], "output": [] }
{ "input": [ "2\n1000000007" ], "output": [ "1000000009" ] }
{ "input": [ "2\n1036219253", "2\n8", "2\n1612950356", "2\n2998753809", "2\n1978754927", "2\n2655259302", "2\n3155611415", "2\n1020631181", "2\n120033745", "2\n37469551", "2\n8809352", "2\n6981477", "2\n4234377", "2\n1585800", "2\n2930241", "2\n4423672",...
p02326 Largest Square
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s. Constraints * 1 ≤ H, W ≤ 1,400 Input H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the follo...
{ "input": [], "output": [] }
{ "input": [ "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 1 0\n0 0 0 1 0" ], "output": [ "4" ] }
{ "input": [ "4 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "1 5\n1 0 1 0 0\n1 0 0 0 0\n0 0 0 1 -1\n0 -1 0 1 0", "1 1\n1 0 0 0 0\n1 0 0 0 1\n0 -1 0 1 -1\n0 -1 0 2 0", "4 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 -1 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 -1 0 1 -1", "4 5\n0 0 1 0 0\n1...
p02471 Extended Euclid Algorithm
Extended Euclid Algorithm Given positive integers a and b, find the integer solution (x, y) to ax + by = gcd(a, b), where gcd(a, b) is the greatest common divisor of a and b. Constraints * 1 ≤ a, b ≤ 109 Input a b Two positive integers a and b are given separated by a space in a line. Output Print two inte...
{ "input": [], "output": [] }
{ "input": [ "3 8", "4 12" ], "output": [ "3 -1", "1 0" ] }
{ "input": [ "5 8", "5 15", "5 1", "5 2", "15 2", "55 2", "61 2", "47 2", "11 2", "6 8", "5 4", "2 15", "5 3", "55 3", "71 2", "11 3", "49 2", "93 2", "117 2", "8 3", "41 3", "80 3", "171 2", "230 4", "171 4", "171...
aou
For Turbo C++ Users : Read the following document before attempting the question : Problem Description Hank Pym is an aspiring student at IIITD. He has almost completed his work on Ultron, the ultimate artificial intelligence. However, one thing remains. He feels that Ultron should have a fail-safe code which can b...
{ "input": [], "output": [] }
{ "input": [ "4\n2\n9\n100\n17" ], "output": [ "1\n2\n4\n1" ] }
{ "input": [ "4\n2\n9\n100\n28", "4\n2\n9\n101\n17", "4\n2\n9\n001\n17", "4\n2\n9\n100\n16", "4\n2\n13\n101\n17", "4\n1\n14\n100\n28", "4\n1\n23\n100\n28", "4\n2\n12\n001\n37", "4\n4\n9\n100\n17", "4\n2\n9\n100\n43", "4\n2\n16\n101\n17", "4\n2\n16\n001\n17", "4\n2\n...
cielab
In Ciel's restaurant, a waiter is training. Since the waiter isn't good at arithmetic, sometimes he gives guests wrong change. Ciel gives him a simple problem. What is A-B (A minus B) ? Surprisingly, his answer is wrong. To be more precise, his answer has exactly one wrong digit. Can you imagine this? Can you make th...
{ "input": [], "output": [] }
{ "input": [ "5858 1234" ], "output": [ "1624\n" ] }
{ "input": [ "5858 2439", "5858 2389", "10125 2389", "15844 2389", "15844 3628", "15844 1015", "28937 1015", "28937 921", "28937 1598", "8374 1598", "8374 2729", "8374 4197", "7234 4197", "5858 2", "10125 1435", "7003 3628", "3642 1015", "47633 1...
etmx06
Common Integer Andy wants to prove his practical programming knowledge to his old pal. He will get two numbers both in the range 10 to 99. if there exists a comon integer in both the numbers, he has to write TRUE or else FALSE. For Example: if input numbers are 12 and 24, the output must be TRUE since the common in...
{ "input": [], "output": [] }
{ "input": [ "11 34", "12 24" ], "output": [ "FALSE", "TRUE" ] }
{ "input": [ "19 34", "19 90", "1 24", "19 56", "1 46", "2 46", "15 90", "1 48", "15 115", "0 48", "15 167", "0 8", "15 317", "15 385", "1 385", "2 385", "2 45", "3 45", "4 45", "8 45", "6 45", "6 58", "6 8", "10 8", "...
ladybug1
Mrs. Verma has decided to sell his car. N people have offered to buy the car. Instead of selling to the highest bidder, Mrs. Verma decides to sell his company to the Kth lowest bidder. How much money will Mrs. Verma get? Input The first line of the input contains 2 space-separated integers, N and K. The next line cont...
{ "input": [], "output": [] }
{ "input": [ "5 4\n1 2 1 3 3" ], "output": [ "3" ] }
{ "input": [], "output": [] }
pcsc2
Phillip has become fascinated with sequences lately. He looks for sequences all the time. His favorite sequence is the Fibonacci sequence, where any element is equal to the sum of the two previous elements. However, he isn't able to figure out the correct number for positions beyond 8 without writing it on paper. C...
{ "input": [], "output": [] }
{ "input": [ "1 5 7" ], "output": [ "45" ] }
{ "input": [], "output": [] }
start01
Problem Statement Write a program that accepts a number and outputs the same. Sample Input 123 Sample Output 123
{ "input": [], "output": [] }
{ "input": [ "123" ], "output": [ "123\n" ] }
{ "input": [ "191", "97", "162", "107", "190", "227", "357", "429", "404", "627", "889", "1047", "1652", "3133", "1313", "1107", "2085", "2863", "984", "265", "445", "173", "77", "33", "14", "11", "8", "9",...
1117_G. Recursive Queries
You are given a permutation p_1, p_2, ..., p_n. You should answer q queries. Each query is a pair (l_i, r_i), and you should calculate f(l_i, r_i). Let's denote m_{l, r} as the position of the maximum in subsegment p_l, p_{l+1}, ..., p_r. Then f(l, r) = (r - l + 1) + f(l, m_{l,r} - 1) + f(m_{l,r} + 1, r) if l ≤ r or ...
{ "input": [], "output": [] }
{ "input": [ "4 5\n3 1 4 2\n2 1 1 2 1\n2 3 4 4 1\n" ], "output": [ "1 6 8 5 1 \n" ] }
{ "input": [ "4 5\n3 1 4 2\n2 2 1 2 1\n2 3 4 4 1\n", "4 5\n3 1 4 2\n2 2 1 3 1\n2 3 4 4 1\n", "4 5\n3 1 4 2\n2 2 1 3 1\n2 4 4 4 1\n", "4 5\n3 1 4 2\n2 4 1 3 1\n2 4 4 4 1\n", "4 5\n3 1 4 2\n2 4 1 3 1\n2 4 4 4 2\n", "4 5\n3 1 4 2\n2 2 1 2 1\n2 3 4 4 2\n", "4 5\n3 1 4 2\n2 2 2 2 1\n2 3 4 4 2\n...
1431_J. Zero-XOR Array
You are given an array of integers a of size n. This array is non-decreasing, i. e. a_1 ≤ a_2 ≤ ... ≤ a_n. You have to find arrays of integers b of size 2n - 1, such that: * b_{2i-1} = a_i (1 ≤ i ≤ n); * array b is non-decreasing; * b_1 ⊕ b_2 ⊕ ... ⊕ b_{2n-1} = 0 (⊕ denotes bitwise XOR operation: <https://en....
{ "input": [], "output": [] }
{ "input": [ "3\n0 1 3\n", "4\n0 3 6 7\n", "5\n1 5 9 10 23\n", "10\n39 62 64 79 81 83 96 109 120 122\n" ], "output": [ "\n2\n", "\n6\n", "\n20\n", "\n678132\n" ] }
{ "input": [], "output": [] }
abc-string-61
Given an integer N,Find how many strings of length N are possible, consisting only of characters { 'A','B' and 'C' } with each character {'A','B' and 'C'} occurs at least once. Input: First line of each test case contains number of test cases T. Each test case contains a single integer N. Output: For each test ...
{ "input": [], "output": [] }
{ "input": [ "3\n2\n3\n4\n\nSAMPLE" ], "output": [ "0\n6\n36\n" ] }
{ "input": [ "3\n2\n2\n4\n\nSAMPLE", "3\n2\n3\n4\n\nS@MPLE", "3\n4\n2\n4\n\nSAMPKE", "3\n3\n2\n4\n\nSAMPKE", "3\n2\n2\n6\n\nEKPMAS", "3\n3\n2\n6\n\nSAMPKE", "3\n3\n3\n6\n\nSAMPKE", "3\n5\n1\n4\n\nSAMPLE", "3\n3\n3\n1\n\nSAMPKE", "3\n5\n3\n1\n\nPAMSKE", "3\n5\n1\n1\n\nPAMSKE...
bogo-sort-1
Given an array A of N integers, sort them in non-decreasing order. Input Format The first line of the input file contains a positive integer <N. Then, N lines follow, each containing a single integer Ai, which is the i^th element of A. Output Format The output must contain exactly N lines, each line containing a sin...
{ "input": [], "output": [] }
{ "input": [ "8\n567\n23\n-10982\n1000000\n-999999\n-3456\n1729\n65535\n\nSAMPLE" ], "output": [ "-999999\n-10982\n-3456\n23\n567\n1729\n65535\n1000000\n" ] }
{ "input": [ "8\n567\n40\n-10982\n1000000\n-999999\n-3456\n1729\n65535\n\nSAMPLE", "8\n1133\n40\n-10982\n1000000\n-999999\n-3456\n1729\n65535\n\nSAMPLE", "8\n1133\n40\n-10982\n1100000\n-999999\n-3456\n1729\n65535\n\nSAMPLE", "8\n1133\n40\n-10982\n1110000\n-999999\n-3456\n1729\n65535\n\nLAMPSE", "8...
fuck-this-problem
Problem Statement Unseen gang is the team of most wanted criminal. Unseen gang has planted bombs in different street and corner of the city. Gang members are sitting in the other part of the city, far away from the bomb site. They are controlling the bomb by sending the activation signal in the form of encrypted code....
{ "input": [], "output": [] }
{ "input": [ "Vhaveplanted bomb @allthe location intheCITY.\n8\n\nSAMPLE" ], "output": [ "Vhavepla\nnted bom\nb @allth\ne locati\non inthe\nCITY.\n\n" ] }
{ "input": [ "Vhaveplanted bpmb @allthe location intheCITY.\n8\n\nSAMPLE", "Vhaveplanted bpmb ehtlla@ location intheCITY.\n8\n\nRAMQLE", "Vhaveplanted bpmb dhtlla@ location intheCITY.\n8\n\nRAMQLE", "Vhaveplanted bpmb dhtlla@ location intheCITY/\n8\n\nRAMQLE", "Vhbveplanted bpmb dhtlla@ location i...
minimise-maximum-sum
You are given an array containing 2 \times n elements.You have to partition the numbers in to n pairs with the property that partition minimize the maximum sum of a pair. Input First line contains T number of test cases. Next line contain N number of pairs. Next line contain 2*N positive integers represent elemen...
{ "input": [], "output": [] }
{ "input": [ "1\n3\n5 6 2 3 9 8\n\nSAMPLE" ], "output": [ "11\n" ] }
{ "input": [ "1\n3\n0 6 2 3 9 8\n\nSAMPLE", "1\n3\n0 6 1 3 9 8\n\nSAMPLE", "1\n3\n0 6 1 3 9 11\n\nSAMPLE", "1\n3\n5 6 2 4 9 8\n\nSAMPLE", "1\n3\n5 6 2 4 9 16\n\nSAMPLE", "1\n3\n5 6 2 4 16 16\n\nSAMPLE", "1\n3\n5 6 2 4 19 16\n\nSAMPLE", "1\n3\n5 5 0 4 19 10\n\nSAMPLE", "1\n3\n0 6 1 ...
p02575 AtCoder Beginner Contest 177 - I hate Shortest Path Problem
There is a grid of squares with H+1 horizontal rows and W vertical columns. You will start at one of the squares in the top row and repeat moving one square right or down. However, for each integer i from 1 through H, you cannot move down from the A_i-th, (A_i + 1)-th, \ldots, B_i-th squares from the left in the i-th ...
{ "input": [], "output": [] }
{ "input": [ "4 4\n2 4\n1 1\n2 3\n2 4" ], "output": [ "1\n3\n6\n-1" ] }
{ "input": [ "4 7\n2 4\n1 1\n2 3\n2 4", "4 4\n2 4\n1 1\n2 0\n2 4", "4 4\n3 4\n1 1\n2 3\n2 4", "4 4\n2 4\n1 1\n2 0\n3 4", "4 4\n1 4\n1 1\n2 0\n3 4", "4 5\n0 4\n0 1\n4 5\n3 4", "4 7\n2 4\n0 1\n2 3\n5 7", "4 7\n1 3\n0 1\n4 1\n3 7", "4 7\n2 4\n0 1\n2 3\n2 4", "4 7\n2 4\n0 1\n4 3\n2...
p02706 AtCoder Beginner Contest 163 - Homework
Takahashi has N days of summer vacation. His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment. He cannot do multiple assignments on the same day, or hang out on a day he does an assignment. What is the maximum number of days Takahashi can hang out during the vacation if ...
{ "input": [], "output": [] }
{ "input": [ "10 2\n5 6", "314 15\n9 26 5 35 8 9 79 3 23 8 46 2 6 43 3", "41 2\n5 6", "11 2\n5 6" ], "output": [ "-1", "9", "30", "0" ] }
{ "input": [ "10 2\n6 6", "314 15\n9 24 5 35 8 9 79 3 23 8 46 2 6 43 3", "41 2\n9 6", "11 2\n5 2", "20 2\n5 2", "20 2\n7 4", "41 2\n5 12", "41 2\n9 9", "11 2\n5 0", "14 2\n3 6", "20 2\n3 2", "38 2\n7 2", "41 2\n5 0", "314 15\n9 24 5 35 8 9 79 3 23 8 46 4 6 43 0"...
p02835 AtCoder Beginner Contest 147 - Blackjack
Given are three integers A_1, A_2, and A_3. If A_1+A_2+A_3 is greater than or equal to 22, print `bust`; otherwise, print `win`. Constraints * 1 \leq A_i \leq 13 \ \ (i=1,2,3) * All values in input are integers. Input Input is given from Standard Input in the following format: A_1 A_2 A_3 Output If A_1+A_2+A_...
{ "input": [], "output": [] }
{ "input": [ "5 7 9", "13 7 2" ], "output": [ "win", "bust" ] }
{ "input": [ "5 7 4", "13 9 2", "5 1 4", "13 9 4", "5 1 0", "0 9 4", "5 1 1", "0 1 4", "6 1 1", "0 2 4", "6 1 2", "0 2 1", "6 2 1", "-1 2 1", "6 0 1", "-1 2 0", "9 0 1", "-1 1 0", "17 0 1", "-1 1 1", "17 0 2", "-2 1 1", "17 0 ...
p02972 AtCoder Beginner Contest 134 - Preparing Boxes
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following con...
{ "input": [], "output": [] }
{ "input": [ "5\n0 0 0 0 0", "3\n1 0 0" ], "output": [ "0", "1\n1" ] }
{ "input": [ "3\n1 0 1", "3\n1 1 0", "3\n0 0 0", "5\n1 0 0 0 0", "5\n1 0 0 0 1", "5\n1 1 0 1 0", "5\n1 0 1 0 0", "5\n1 1 0 0 0", "5\n1 0 0 0 0", "3\n0 0 0", "3\n1 1 0", "5\n1 0 0 0 1", "3\n1 0 1", "5\n1 1 0 0 0", "5\n1 0 1 0 0", "5\n1 1 0 1 0" ], "ou...
p03108 AtCoder Beginner Contest 120 - Decayed Bridges
There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to t...
{ "input": [], "output": [] }
{ "input": [ "6 5\n2 3\n1 2\n5 6\n3 4\n4 5", "4 5\n1 2\n3 4\n1 3\n2 3\n1 4", "2 1\n1 2" ], "output": [ "8\n9\n12\n14\n15", "0\n0\n4\n5\n6", "1" ] }
{ "input": [ "6 5\n3 3\n1 2\n5 6\n3 4\n4 5", "4 5\n1 2\n3 4\n1 3\n3 3\n1 4", "2 1\n2 2", "6 5\n3 3\n1 2\n5 6\n3 4\n2 5", "4 5\n1 2\n3 4\n1 3\n3 3\n1 1", "6 5\n2 3\n1 2\n5 6\n3 4\n4 3", "4 5\n1 0\n3 4\n1 3\n2 3\n1 4", "6 5\n3 3\n1 1\n5 6\n3 4\n4 5", "4 5\n1 2\n3 4\n1 3\n3 2\n1 1", ...
p03255 AtCoder Grand Contest 027 - Garbage Collector
Snuke has decided to use a robot to clean his room. There are N pieces of trash on a number line. The i-th piece from the left is at position x_i. We would like to put all of them in a trash bin at position 0. For the positions of the pieces of trash, 0 < x_1 < x_2 < ... < x_{N} \leq 10^{9} holds. The robot is initi...
{ "input": [], "output": [] }
{ "input": [ "5 1\n1 999999997 999999998 999999999 1000000000", "16 10\n1 7 12 27 52 75 731 13856 395504 534840 1276551 2356789 9384806 19108104 82684732 535447408", "2 100\n1 10", "10 8851025\n38 87 668 3175 22601 65499 90236 790604 4290609 4894746" ], "output": [ "19999999983", "32560177...
{ "input": [ "5 1\n1 1856513539 999999998 999999999 1000000000", "16 10\n1 7 12 27 52 75 731 13856 395504 534840 1276551 903860 9384806 19108104 82684732 535447408", "2 100\n1 13", "10 8851025\n38 87 668 4845 22601 65499 90236 790604 4290609 4894746", "16 10\n1 7 12 27 52 75 731 18298 395504 53484...