dataset stringclasses 1
value | question stringlengths 29 13k | exe_method stringclasses 1
value | solutions null | task_id int64 0 5.07k | test_time_limit int64 1 1 | example_input listlengths 0 5 | example_output listlengths 0 5 | test_input listlengths 1 10 | test_output listlengths 1 10 |
|---|---|---|---|---|---|---|---|---|---|
CodeContests | You found an old board game in your programming department's room. It looks interesting so I decided to play with it.
This game consists of M events and you must capture event i at time ti. However, at that time your strength must be si or better, and if you can't be si or better, the game is over. Your strength is 0 ... | stdin | null | 1,652 | 1 | [
"5 4\n3 3\n2 1\n1 5\n4 2\n2 6\n4 1\n8 2\n10 4\n12 30\n",
"5 4\n3 3\n2 1\n1 5\n4 2\n2 6\n4 1\n8 2\n10 4\n12 17\n"
] | [
"-1\n",
"2\n"
] | [
"5 4\n3 3\n2 1\n1 5\n4 2\n2 6\n4 1\n8 2\n10 4\n21 30\n",
"5 4\n3 6\n2 1\n1 5\n4 2\n2 6\n4 1\n8 2\n10 4\n21 30\n",
"5 3\n2 3\n2 1\n1 5\n4 2\n2 6\n4 1\n8 2\n10 4\n12 30\n",
"5 4\n3 6\n2 1\n1 5\n4 2\n2 6\n4 1\n8 2\n10 4\n21 13\n",
"5 3\n2 3\n2 1\n1 5\n4 2\n2 6\n4 1\n8 2\n8 4\n12 30\n",
"5 3\n0 3\n2 1\n0 5\n4... | [
"-1\n",
"9\n",
"6\n",
"15\n",
"4\n",
"8\n",
"16\n",
"3\n",
"7\n",
"0\n"
] |
CodeContests | There are many blue cards and red cards on the table. For each card, an integer number greater than 1 is printed on its face. The same number may be printed on several cards.
A blue card and a red card can be paired when both of the numbers printed on them have a common divisor greater than 1. There may be more than o... | stdin | null | 3,524 | 1 | [
"4 3\n2 6 6 15\n2 3 5\n2 3\n4 9\n8 16 32\n4 2\n4 9 11 13\n5 7\n5 5\n2 3 5 1001 1001\n7 11 13 30 30\n10 10\n2 3 5 7 9 11 13 15 17 29\n4 6 10 14 18 22 26 30 34 38\n20 20\n195 144 903 63 137 513 44 626 75 473\n876 421 568 519 755 840 374 368 570 872\n363 650 155 265 64 26 426 391 15 421\n373 984 564 54 823 477 565 866... | [
"3\n1\n0\n4\n9\n18\n85\n"
] | [
"4 3\n2 6 6 15\n2 3 5\n2 3\n4 9\n8 16 32\n4 2\n4 9 11 13\n5 7\n5 5\n2 3 5 1001 1001\n7 11 13 30 30\n10 10\n2 3 5 7 9 11 13 15 17 29\n4 6 10 14 18 22 26 30 34 38\n20 20\n195 144 903 63 137 513 44 626 75 473\n876 421 568 519 755 840 374 368 570 872\n363 650 155 265 64 26 426 391 15 421\n373 984 564 54 823 477 565 866... | [
"3\n1\n0\n4\n9\n18\n86\n",
"3\n1\n0\n4\n9\n18\n87\n",
"3\n1\n0\n4\n9\n18\n88\n",
"3\n1\n0\n4\n9\n18\n85\n",
"3\n1\n0\n3\n9\n18\n88\n",
"3\n1\n0\n4\n8\n18\n85\n",
"3\n1\n0\n4\n9\n17\n86\n",
"3\n1\n0\n4\n7\n18\n85\n",
"3\n1\n0\n5\n9\n17\n86\n",
"3\n1\n0\n4\n9\n17\n87\n"
] |
CodeContests | An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.
Given an integer N, determine whether it is a Harshad number.
Constraints
* 1?N?10^8
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output... | stdin | null | 4,074 | 1 | [
"148\n",
"57\n",
"12\n"
] | [
"No\n",
"No\n",
"Yes\n"
] | [
"112\n",
"28\n",
"21\n",
"30\n",
"224\n",
"1\n",
"295\n",
"2\n",
"56\n",
"358\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"Yes\n",
"No\n",
"No\n"
] |
CodeContests | The customer telephone support center of the computer sales company called JAG is now in- credibly confused. There are too many customers who request the support, and they call the support center all the time. So, the company wants to figure out how many operators needed to handle this situation.
For simplicity, let u... | stdin | null | 3,368 | 1 | [
"3 300\n100 50 150\n100 50 150\n100 50 150\n3 300\n100 50 150\n100 50 150\n200 50 150\n9 18\n3 1 1\n3 1 1\n3 1 1\n4 100 1\n5 100 1\n5 100 1\n10 5 3\n10 5 3\n1 7 1000\n10 18\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n5 6 7\n6 7 8\n7 8 9\n8 9 10\n9 10 11\n10 11 12\n0 0\n"
] | [
"2\n3\n3\n4\n"
] | [
"3 300\n100 46 150\n100 50 150\n100 50 150\n3 300\n100 50 150\n100 50 150\n200 50 150\n9 18\n3 1 1\n3 1 1\n3 1 1\n4 100 1\n5 100 1\n5 100 1\n10 5 3\n10 5 3\n1 7 1000\n10 18\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n5 6 7\n6 7 8\n7 8 9\n8 9 10\n9 10 11\n10 11 12\n0 0\n",
"3 300\n100 46 150\n100 50 150\n100 50 150\n3 300\n110 5... | [
"2\n3\n3\n4\n",
"2\n3\n9\n4\n",
"3\n3\n3\n4\n",
"2\n3\n4\n4\n",
"2\n3\n5\n4\n",
"3\n3\n3\n6\n",
"3\n3\n3\n5\n",
"2\n3\n9\n3\n",
"3\n3\n4\n4\n",
"2\n3\n3\n5\n"
] |
CodeContests | Milly and Pranjul are playing a game in which Pranjul will give an index of a chocolate. Then, Milly has to tell him the box number in which that chocolate is in. There are N such boxes and Ci chocolates are there in i^th the box. Description of index is given below :
Suppose there are A1, A2 … AN chocolates in 1^st, ... | stdin | null | 1,476 | 1 | [
"2\n2 3\n2\n2\n4\n\nSAMPLE\n"
] | [
"1\n2\n"
] | [
"2\n2 3\n2\n3\n4\n\nSAMPLE\n",
"2\n2 3\n2\n2\n1\n\nSAMPLE\n",
"2\n2 3\n1\n2\n4\n\nSAMPLE\n",
"2\n1 3\n1\n2\n4\n\nSAMPLE\n",
"2\n3 3\n2\n2\n4\n\nSAMPLE\n",
"2\n1 3\n2\n2\n1\n\nSEMOLA\n",
"2\n2 3\n2\n3\n4\n\nSAMQLE\n",
"2\n2 3\n2\n2\n1\n\nSEMPLA\n",
"2\n0 3\n2\n2\n1\n\nSEMPLA\n",
"2\n1 3\n1\n2\n4\n\... | [
"2\n2\n",
"1\n1\n",
"1\n",
"2\n",
"1\n2\n",
"2\n1\n",
"2\n2\n",
"1\n1\n",
"2\n2\n",
"2\n"
] |
CodeContests | Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure which movie he should watch.
There are n movies to watch during this weekend. Each movie can be characterize... | stdin | null | 3,377 | 1 | [
"2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 4 1 4\n"
] | [
"1\n2\n"
] | [
"2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 5 1 4\n",
"2\n2\n2 2\n2 1\n4\n2 1 4 1\n4 4 1 4\n",
"2\n2\n1 2\n2 1\n4\n1 1 4 1\n2 5 1 4\n",
"2\n2\n2 2\n2 1\n4\n2 1 4 1\n2 4 1 4\n",
"2\n2\n2 2\n2 1\n4\n2 1 4 1\n1 4 1 4\n",
"2\n2\n1 2\n2 1\n4\n1 1 1 1\n2 5 1 4\n",
"2\n2\n2 2\n2 1\n3\n2 1 4 1\n1 4 1 4\n",
"2\n2\n2 2\n2 1... | [
"1\n2\n",
"1\n1\n",
"1\n2\n",
"1\n2\n",
"1\n2\n",
"1\n2\n",
"1\n2\n",
"1\n1\n",
"1\n2\n",
"1\n2\n"
] |
CodeContests | You have been given a positive integer N. You need to find and print the Factorial of this number. The Factorial of a positive integer N refers to the product of all number in the range from 1 to N. You can read more about the factorial of a number here.
Input Format:
The first and only line of the input contains a s... | stdin | null | 3,222 | 1 | [
"2\n\nSAMPLE\n"
] | [
"2\n"
] | [
"2\n\nELPMAS\n",
"2\n\nEAPMLS\n",
"2\n\nEAPMLT\n",
"2\n\nEAMPLT\n",
"2\n\nDAMPLT\n",
"2\n\nTLPMAD\n",
"2\n\nTLPLAD\n",
"2\n\nTMPLAD\n",
"2\n\nLMPTAD\n",
"2\n\nDATPML\n"
] | [
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n"
] |
CodeContests | Your task in this problem is to create a program that finds the shortest path between two given locations on a given street map, which is represented as a collection of line segments on a plane.
<image>
Figure 4 is an example of a street map, where some line segments represent streets and the others are signs indicat... | stdin | null | 3,128 | 1 | [
"8\n1 1\n4 4\n1 1 4 1\n1 1 1 4\n3 1 3 4\n4 3 5 3\n2 4 3 5\n4 1 4 4\n3 3 2 2\n1 4 4 4\n9\n1 5\n5 1\n5 4 5 1\n1 5 1 1\n1 5 5 1\n2 3 2 4\n5 4 1 5\n3 2 2 1\n4 2 4 1\n1 1 5 1\n5 3 4 3\n11\n5 5\n1 0\n3 1 5 1\n4 3 4 2\n3 1 5 5\n2 3 2 2\n1 0 1 2\n1 2 3 4\n3 4 5 5\n1 0 5 2\n4 0 4 1\n5 5 5 1\n2 3 2 4\n0\n"
] | [
"1 1\n3 1\n3 4\n4 4\n0\n-1\n5 5\n5 2\n3 1\n1 0\n0\n"
] | [
"8\n1 1\n4 4\n1 1 4 1\n1 1 1 4\n3 1 3 4\n4 3 5 3\n2 4 3 5\n4 1 4 4\n3 3 2 2\n1 4 4 4\n9\n1 5\n5 1\n5 4 5 1\n1 5 1 1\n1 5 5 1\n2 3 2 4\n5 4 1 5\n1 2 2 1\n4 2 4 1\n1 1 5 1\n5 3 4 3\n11\n5 5\n1 0\n3 1 5 1\n4 3 4 2\n3 1 5 5\n2 3 2 2\n1 0 1 2\n1 2 3 4\n3 4 5 5\n1 0 5 2\n4 0 4 1\n5 5 5 1\n2 3 2 4\n0\n",
"8\n1 1\n4 4\n1... | [
"1 1\n3 1\n3 4\n4 4\n0\n1 5\n1 2\n2 1\n4 1\n5 1\n0\n5 5\n5 2\n3 1\n1 0\n0\n",
"1 1\n3 1\n3 4\n4 4\n0\n1 5\n1 2\n2 1\n4 1\n0\n5 5\n5 2\n3 1\n1 0\n0\n",
"1 1\n3 1\n3 4\n4 4\n0\n-1\n5 5\n5 2\n3 1\n1 0\n0\n",
"1 1\n3 1\n3 4\n4 4\n0\n1 5\n4 2\n5 1\n0\n5 5\n5 2\n3 1\n1 0\n0\n",
"1 1\n3 1\n3 4\n4 4\n0\n-1\n-1\n",
... |
CodeContests | Snuke built an online judge to hold a programming contest.
When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.)
Determine whether the judge can return the ... | stdin | null | 2,366 | 1 | [
"CABD\n",
"BACD\n",
"ACACA\n",
"ABCD\n",
"XX\n"
] | [
"No\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | [
"CBBD\n",
"ACABA\n",
"B@CD\n",
"BBCD\n",
"XW\n",
"DBBD\n",
"B@BD\n",
"ACBAA\n",
"DCBB\n",
"XV\n"
] | [
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n",
"No\n",
"No\n"
] |
CodeContests | Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`.
When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of th... | stdin | null | 4,427 | 1 | [
"100 5\n",
"10 2\n",
"1 1\n"
] | [
"608000\n",
"18400\n",
"3800\n"
] | [
"100 1\n",
"10 4\n",
"1 0\n",
"110 1\n",
"10 7\n",
"0 0\n",
"111 1\n",
"10 3\n",
"-1 0\n",
"101 1\n"
] | [
"23600\n",
"131200\n",
"100\n",
"25600\n",
"1740800\n",
"0\n",
"25800\n",
"51200\n",
"-100\n",
"23800\n"
] |
CodeContests | Chandu and Kundu are bored of dramatic games around. As they are very good friends and scholars they decided to discover a new game.
In total they had N number of marbles with value inscribed on each of them from 1 to N.
Chandu being from royal family has a treasure box. He emptied the box for the game to proceed. ... | stdin | null | 4,884 | 1 | [] | [] | [
"45\n14 13 2 4 6 5 7 22 8 9 11 18 3 10 17 21 20 16 12 1 19 15\n33\n28 10 9 14 15 20 27 22 21 4 13 30 17 18 6 2 1 5 8 12 3 26 11 24 23 19 25 16 29 7\n48\n21 38 16 23 32 5 27 19 9 28 17 35 30 20 43 11 42 15 39 8 22 31 36 34 18 29 25 1 6 24 44 2 26 33 37 14 3 13 10 40 7 4 41 12\n67\n5 2 4 8 1 3 7 6\n86\n29 26 21 36 16... | [
"-1\n-1\n-1\n-1\n-1\n-1\n-1\n\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\nCKCK\n-1\n-1\nCCKCCCKKKK\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\nCK\n-1\nCKCKCK\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\nCK\nCCCKCKCKKKCK\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\nCK\n-1\n\n-1\n-1\n-1\n-1\n\n-1\n-1\n-1\n\n-1\... |
CodeContests | Chintu and Mintu are good friends and they have so many coins of different amount so they decided to play a game using a stack consisting of N coins.
In this game, anyone can alternatively remove 1, 2 or 3 from the top, and the amount on the removed coins are added to their score.
Players have to play so that they o... | stdin | null | 3,822 | 1 | [
"2\n5\n58 952 23 0 12\n5\n0 1 1 1 999\n\nSAMPLE\n"
] | [
"1033\n999\n"
] | [
"2\n5\n58 1641 23 0 12\n5\n0 1 1 1 999\n\nSAMPLE\n",
"2\n5\n55 1641 23 0 12\n5\n0 1 1 1 999\n\nSAMPLE\n",
"2\n5\n55 2727 23 0 12\n5\n0 1 1 1 999\n\nSAMPLE\n",
"2\n5\n58 952 23 0 5\n5\n0 1 1 1 999\n\nSAMPLE\n",
"2\n5\n58 1641 8 0 12\n5\n0 1 1 1 999\n\nSAMPLE\n",
"2\n5\n55 2727 23 0 12\n5\n0 1 1 2 442\n\nSA... | [
"1722\n999\n",
"1719\n999\n",
"2805\n999\n",
"1033\n999\n",
"1707\n999\n",
"2805\n442\n",
"2827\n999\n",
"1707\n168\n",
"1719\n567\n",
"2798\n442\n"
] |
CodeContests | 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... | stdin | null | 339 | 1 | [
"10\n...*....**\n..........\n**....**..\n........*.\n..*.......\n..........\n.*........\n..........\n....*..***\n.*....*...\n10\n****.*****\n*..*.*....\n****.*....\n*....*....\n*....*****\n..........\n****.*****\n*..*...*..\n****...*..\n*..*...*..\n0\n"
] | [
"5\n3\n"
] | [
"10\n...*....**\n..........\n**....**..\n........*.\n..*.......\n..........\n.*........\n..........\n....*..***\n.*....*...\n10\n*****.****\n*..*.*....\n****.*....\n*....*....\n*....*****\n..........\n****.*****\n*..*...*..\n****...*..\n*..*...*..\n0\n",
"10\n...*....**\n..........\n**....**..\n*.........\n......... | [
"5\n3\n",
"4\n3\n",
"4\n2\n",
"5\n2\n",
"3\n3\n",
"4\n",
"3\n2\n",
"5\n",
"3\n",
"5\n3\n"
] |
CodeContests | Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.
Determine whether the arrangement of the poles is beautiful.
Constraints
* 1 \leq a,b,c \leq 10... | stdin | null | 4,546 | 1 | [
"2 5 6\n",
"3 2 1\n",
"2 4 6\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | [
"2 8 6\n",
"2 2 2\n",
"2 2 1\n",
"2 0 6\n",
"1 8 6\n",
"2 0 2\n",
"1 8 1\n",
"2 4 2\n",
"2 0 3\n",
"1 10 1\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n"
] |
CodeContests | Your company’s next product will be a new game, which is a three-dimensional variant of the classic game “Tic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and try to make a sequence of a certain length.
People believe that it is fun to play the game, but they still cannot fix the values of s... | stdin | null | 4,753 | 1 | [
"3 3 3\n1 1\n1 1\n1 1\n3 3 7\n2 2\n1 3\n1 1\n2 3\n2 1\n3 3\n3 1\n4 3 15\n1 1\n2 2\n1 1\n3 3\n3 3\n1 1\n3 3\n3 3\n4 4\n1 1\n4 4\n4 4\n4 4\n4 1\n2 2\n0 0 0\n"
] | [
"Draw\nWhite 6\nBlack 15\n"
] | [
"3 3 3\n1 1\n1 1\n1 1\n3 3 7\n2 2\n1 3\n1 1\n2 3\n2 1\n3 3\n3 1\n4 3 15\n1 1\n0 2\n1 1\n3 3\n3 3\n1 1\n3 3\n3 3\n4 4\n1 1\n4 4\n4 4\n4 4\n4 1\n2 2\n0 0 0\n",
"3 3 3\n1 1\n1 1\n1 1\n3 3 7\n3 2\n1 3\n1 1\n2 3\n2 1\n3 3\n3 1\n4 3 15\n1 1\n2 2\n1 1\n3 3\n3 3\n1 1\n3 3\n3 3\n4 4\n1 1\n4 4\n4 4\n4 4\n4 1\n2 2\n0 0 0\n"... | [
"Draw\nWhite 6\nDraw\n",
"Draw\nWhite 6\nBlack 15\n",
"Draw\nBlack 7\nBlack 15\n",
"Draw\nBlack 7\nDraw\n",
"Draw\nDraw\nDraw\n",
"Draw\nBlack 7\nWhite 14\n",
"Draw\nDraw\nBlack 15\n",
"Draw\nBlack 7\nBlack 13\n",
"Draw\nWhite 6\nBlack 13\n",
"Draw\nBlack 5\nBlack 13\n"
] |
CodeContests | John is playing a famous console game named 'Tales of Algorithmers.' Now he is facing the last dungeon called 'Blue Forest.' To find out the fastest path to run through the very complicated dungeon, he tried to draw up the dungeon map.
The dungeon consists of several floors. Each floor can be described as a connected ... | stdin | null | 985 | 1 | [
"2\n5\n0 0\n10 0\n20 0\n30 0\n30 10\n4\n1 2\n2 3\n3 4\n4 5\n2\n1 2 4\n3 2 2\n5\n-10 0\n0 0\n0 -10\n0 -20\n0 -30\n4\n1 2\n2 3\n3 4\n4 5\n1\n4 1 3\n1 1\n2 1\n4\n3\n4 3\n0 0\n5 0\n2\n1 2\n2 3\n0\n3\n0 0\n3 4\n0 5\n2\n1 2\n1 3\n1\n2 3 4\n4\n0 13\n0 0\n13 0\n13 13\n4\n1 2\n1 4\n2 3\n2 4\n0\n4\n5 12\n0 0\n-7 17\n-12 5\n4... | [
"10.0000000000\n41.3847763109\n-1.000000000\n"
] | [
"2\n5\n0 0\n10 0\n20 0\n30 0\n30 10\n4\n1 2\n2 3\n3 4\n4 5\n2\n1 2 4\n3 2 2\n5\n-10 0\n0 0\n0 -10\n0 -20\n0 -30\n4\n1 2\n2 3\n3 4\n4 5\n1\n4 1 3\n1 1\n2 1\n4\n3\n4 3\n0 0\n5 0\n2\n1 2\n2 3\n0\n3\n0 0\n3 4\n0 5\n2\n1 2\n1 3\n1\n2 3 4\n4\n0 13\n0 0\n13 0\n13 13\n4\n1 2\n1 4\n2 3\n2 4\n0\n4\n5 12\n0 0\n-7 17\n-12 5\n4... | [
"10.000000\n41.384776\n-1.000000\n",
"10.000000\n-1.000000\n-1.000000\n",
"10.049876\n-1.000000\n-1.000000\n",
"0.000000\n-1.000000\n-1.000000\n",
"-1.000000\n-1.000000\n-1.000000\n",
"10.000000\n36.384776\n-1.000000\n",
"20.000000\n-1.000000\n-1.000000\n",
"11.000000\n-1.000000\n-1.000000\n",
"10.0... |
CodeContests | Constraints
* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 9900
* -2 × 107 ≤ di ≤ 2 × 107
* There are no parallel edges
* There are no self-loops
Input
An edge-weighted graph G (V, E).
|V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1
|V| is the number of vertices and |E| is the number of edges in G. The graph vertices are named wi... | stdin | null | 831 | 1 | [
"4 6\n0 1 1\n0 2 -5\n1 2 2\n1 3 4\n2 3 1\n3 2 7\n",
"4 6\n0 1 1\n0 2 5\n1 2 2\n1 3 4\n2 3 1\n3 2 -7\n",
"4 6\n0 1 1\n0 2 5\n1 2 2\n1 3 4\n2 3 1\n3 2 7\n"
] | [
"0 1 -5 -4\nINF 0 2 3\nINF INF 0 1\nINF INF 7 0\n",
"NEGATIVE CYCLE\n",
"0 1 3 4\nINF 0 2 3\nINF INF 0 1\nINF INF 7 0\n"
] | [
"4 6\n0 1 1\n0 2 5\n1 2 2\n1 3 8\n2 3 1\n3 2 -7\n",
"4 6\n0 1 1\n0 3 -5\n1 2 2\n1 3 4\n2 3 1\n3 2 7\n",
"4 6\n0 1 1\n0 2 5\n1 2 3\n1 3 4\n2 3 1\n3 2 7\n",
"4 6\n0 1 1\n0 2 5\n1 2 2\n1 3 8\n0 3 1\n3 2 -7\n",
"4 6\n0 1 2\n0 2 5\n1 2 2\n1 3 8\n0 3 1\n3 2 -7\n",
"4 6\n0 1 2\n0 3 -5\n1 2 2\n1 3 4\n2 3 1\n3 2 7... | [
"NEGATIVE CYCLE\n",
"0 1 2 -5\nINF 0 2 3\nINF INF 0 1\nINF INF 7 0\n",
"0 1 4 5\nINF 0 3 4\nINF INF 0 1\nINF INF 7 0\n",
"0 1 -6 1\nINF 0 1 8\nINF INF 0 INF\nINF INF -7 0\n",
"0 2 -6 1\nINF 0 1 8\nINF INF 0 INF\nINF INF -7 0\n",
"0 2 2 -5\nINF 0 2 3\nINF INF 0 1\nINF INF 7 0\n",
"0 INF 2 -5\nINF 0 2 3\n... |
CodeContests | Takayuki and Kazuyuki are good twins, but their behavior is exactly the opposite. For example, if Takayuki goes west, Kazuyuki goes east, and if Kazuyuki goes north, Takayuki goes south. Currently the two are in a department store and are in different locations. How can two people who move in the opposite direction mee... | stdin | null | 2,135 | 1 | [
"6 6\n2 4\n6 2\n0 0 0 0 1 0\n0 1 0 0 0 0\n0 1 0 0 0 0\n0 0 0 1 0 0\n0 0 0 0 0 1\n0 0 0 0 0 0\n3 3\n1 1\n3 3\n0 0 0\n0 1 0\n0 0 0\n0 0\n"
] | [
"3\nNA\n"
] | [
"6 6\n2 4\n6 2\n0 0 0 0 1 0\n0 1 1 0 0 0\n0 1 0 0 0 0\n0 0 0 1 0 0\n0 0 0 0 0 1\n0 0 0 0 0 0\n3 3\n1 1\n3 3\n0 0 0\n0 1 0\n0 0 0\n0 0\n",
"6 6\n2 4\n6 2\n0 0 0 0 1 0\n0 1 1 0 0 0\n0 1 0 0 0 0\n0 0 0 1 1 0\n0 0 0 0 0 1\n0 0 0 0 0 0\n3 3\n1 2\n3 3\n0 0 0\n0 1 0\n0 0 0\n0 0\n",
"6 6\n2 3\n6 1\n0 0 0 0 1 0\n0 1 1 0... | [
"3\nNA\n",
"3\n4\n",
"4\n4\n",
"3\n6\n",
"4\nNA\n",
"3\n1\n",
"6\nNA\n",
"3\n3\n",
"7\n4\n",
"4\n3\n"
] |
CodeContests | Vampire
Mr. C is a vampire. If he is exposed to the sunlight directly, he turns into ash. Nevertheless, last night, he attended to the meeting of Immortal and Corpse Programmers Circle, and he has to go home in the near dawn. Fortunately, there are many tall buildings around Mr. C's home, and while the sunlight is blo... | stdin | null | 1,496 | 1 | [
"2 3\n-2 -1 3\n0 1 3\n2 3 3\n2 2\n-2 0 4\n0 2 3\n2 6\n-3 3 1\n-2 3 2\n-1 3 3\n0 3 4\n1 3 5\n2 3 6\n2 6\n-3 3 1\n-3 2 2\n-3 1 3\n-3 0 4\n-3 -1 5\n-3 -2 6\n0 0\n"
] | [
"0.0000\n3.0000\n2.2679\n2.2679\n"
] | [
"2 3\n-3 -1 3\n0 1 3\n2 3 3\n2 2\n-2 0 4\n0 2 3\n2 6\n-3 3 1\n-2 3 2\n-1 3 3\n0 3 4\n1 3 5\n2 3 6\n2 6\n-3 3 1\n-3 2 2\n-3 1 3\n-3 0 4\n-3 -1 5\n-3 -2 6\n0 0\n",
"2 3\n-3 -1 3\n0 1 3\n2 3 3\n2 2\n-2 0 4\n0 2 5\n2 6\n-3 3 1\n-2 3 2\n-1 3 3\n0 3 4\n1 3 5\n2 3 6\n2 6\n-3 3 1\n-3 2 2\n-3 1 3\n-3 0 4\n-3 -1 5\n-3 -2 6... | [
"0.000000\n3.000000\n2.267949\n2.267949\n",
"0.000000\n4.000000\n2.267949\n2.267949\n",
"0.000000\n5.000000\n2.267949\n2.267949\n",
"0.000000\n3.000000\n2.267949\n2.000000\n",
"0.000000\n3.000000\n2.267949\n1.763932\n",
"0.000000\n3.000000\n3.000000\n2.267949\n",
"0.000000\n5.000000\n4.000000\n2.267949\... |
CodeContests | You are given a sequence D_1, D_2, ..., D_N of length N. The values of D_i are all distinct. Does a tree with N vertices that satisfies the following conditions exist?
* The vertices are numbered 1,2,..., N.
* The edges are numbered 1,2,..., N-1, and Edge i connects Vertex u_i and v_i.
* For each vertex i, the sum of ... | stdin | null | 929 | 1 | [
"15\n57\n62\n47\n45\n42\n74\n90\n75\n54\n50\n66\n63\n77\n87\n51\n",
"2\n1\n2\n",
"7\n10\n15\n13\n18\n11\n14\n19\n"
] | [
"1 10\n1 11\n2 8\n2 15\n3 5\n3 9\n4 5\n4 10\n5 15\n6 12\n6 14\n7 13\n9 12\n11 13\n",
"-1\n",
"1 2\n1 3\n1 5\n3 4\n5 6\n6 7\n"
] | [
"15\n57\n62\n37\n45\n42\n74\n90\n75\n54\n50\n66\n63\n77\n87\n51\n",
"2\n0\n2\n",
"7\n10\n15\n13\n18\n11\n24\n19\n",
"15\n57\n62\n74\n45\n42\n74\n90\n75\n54\n50\n66\n63\n77\n87\n51\n",
"2\n-1\n2\n",
"7\n10\n15\n18\n18\n11\n24\n19\n",
"15\n57\n62\n74\n45\n42\n74\n90\n75\n54\n50\n66\n63\n77\n143\n51\n",
... | [
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n"
] |
CodeContests | In PIET's CS Deparment there is a contest of Geometry. In this contest students are told to find minimum angle between hour and minute hand.
Input:
The first line contains the number of test cases, T. T lines follow, each of which contains two integer Hour hand H and minute hand M .
Output:
Print the minimum angle be... | stdin | null | 3,421 | 1 | [
"2\n12 30\n06 00\n\nSAMPLE\n"
] | [
"165\n180\n"
] | [
"10\n11 12\n12 13\n12 02\n05 22\n02 18\n07 06\n07 55\n03 30\n08 5\n09 46\n",
"10\n01 56\n02 10\n03 33\n04 42\n05 55\n06 59\n07 06\n08 08\n09 18\n10 55\n",
"10\n12 04\n12 30\n03 37\n09 59\n00 59\n03 26\n00 00\n12 12\n02 3\n07 17\n",
"10\n11 13\n12 13\n12 02\n05 22\n02 18\n07 06\n07 55\n03 30\n08 5\n09 46\n",
... | [
"96\n72\n11\n29\n39\n177\n93\n75\n148\n17\n",
"82\n5\n92\n111\n153\n145\n177\n164\n171\n3\n",
"22\n165\n114\n55\n35\n53\n0\n66\n43\n116\n",
"102\n72\n11\n29\n39\n177\n93\n75\n148\n17\n",
"82\n5\n92\n111\n153\n145\n160\n164\n171\n3\n",
"22\n165\n114\n55\n35\n59\n0\n66\n43\n116\n",
"102\n72\n11\n29\n39\n1... |
CodeContests | There is a line with 1000 cells numbered from 1 to 1000 from left to right and N coins placed on it. Coin i is placed at cell Xi, and no two coins are placed at the same cell.
Bob would like to move the coins to the N leftmost cells of the line. To do this, he is allowed to take a coin from any cell T and move it to c... | stdin | null | 3,417 | 1 | [
"2\n3 2\n2 4 7\n5 3\n1 2 3 4 5\n"
] | [
"5\n0\n"
] | [
"2\n3 2\n2 4 7\n3 3\n1 2 3 4 5\n",
"2\n3 2\n2 4 7\n3 3\n1 2 3 4 9\n",
"2\n3 2\n2 4 7\n3 3\n1 2 3 4 7\n",
"2\n3 2\n2 4 10\n3 3\n1 2 3 4 7\n",
"2\n4 2\n1 4 7\n5 3\n1 2 3 4 9\n",
"2\n4 1\n1 4 7\n5 6\n1 2 5 6 9\n",
"2\n6 2\n2 4 7\n4 3\n1 2 3 4 12\n",
"2\n4 2\n1 4 5\n5 6\n1 2 3 4 9\n",
"2\n4 2\n1 4 11\n5... | [
"5\n0\n",
"5\n4\n",
"5\n2\n",
"8\n2\n",
"4\n4\n",
"6\n4\n",
"5\n7\n",
"2\n4\n",
"8\n4\n",
"8\n7\n"
] |
CodeContests | Let us compare two triples a = (xa, ya, za) and b = (xb, yb, zb) by a partial order ∠ defined as follows.
a ∠ b ⇔ xa < xb and ya < yb and za < zb
Your mission is to find, in the given set of triples, the longest ascending series a1 ∠ a2 ∠ ... ∠ ak.
Input
The input is a sequence of datasets, each specifying a set... | stdin | null | 3,646 | 1 | [
"6 0 1 1\n0 0 0\n0 2 2\n1 1 1\n2 0 2\n2 2 0\n2 2 2\n5 0 1 1\n0 0 0\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n10 0 1 1\n3 0 0\n2 1 0\n2 0 1\n1 2 0\n1 1 1\n1 0 2\n0 3 0\n0 2 1\n0 1 2\n0 0 3\n0 10 1 1\n0 0 0 0\n"
] | [
"3\n5\n1\n3\n"
] | [
"6 0 1 1\n0 0 0\n0 2 2\n1 1 1\n2 0 2\n2 2 0\n1 2 2\n5 0 1 1\n0 0 0\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n10 0 1 1\n3 0 0\n2 1 0\n2 0 1\n1 2 0\n1 1 1\n1 0 2\n0 3 0\n0 2 1\n0 1 2\n0 0 3\n0 10 1 1\n0 0 0 0\n",
"6 0 1 1\n0 0 0\n0 2 2\n1 1 1\n2 0 2\n2 2 0\n1 2 2\n5 0 1 1\n0 0 0\n1 1 1\n2 0 2\n3 3 3\n4 4 4\n10 0 1 1\n3 0 0\n2 1... | [
"2\n5\n1\n3\n",
"2\n4\n1\n3\n",
"3\n5\n1\n3\n",
"2\n3\n1\n3\n",
"3\n4\n1\n3\n",
"2\n4\n2\n3\n",
"2\n2\n1\n3\n",
"2\n3\n2\n3\n",
"3\n3\n1\n3\n",
"3\n4\n2\n3\n"
] |
CodeContests | For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment con... | stdin | null | 79 | 1 | [
"5\n0 0\n2 0\n1 1\n2 2\n0 2\n",
"4\n0 0\n3 1\n2 3\n0 3\n"
] | [
"0\n",
"1\n"
] | [
"5\n0 0\n2 1\n1 1\n2 2\n0 2\n",
"4\n0 0\n3 0\n2 1\n0 3\n",
"4\n0 0\n3 1\n2 1\n0 3\n",
"5\n0 0\n3 1\n1 1\n2 2\n0 2\n",
"5\n0 0\n3 1\n1 1\n3 2\n0 2\n",
"4\n0 0\n3 0\n2 0\n0 3\n",
"5\n0 0\n3 1\n1 1\n3 2\n1 2\n",
"4\n0 0\n3 1\n2 0\n0 3\n",
"5\n0 0\n3 1\n1 1\n5 2\n1 2\n",
"4\n0 0\n3 1\n2 1\n0 2\n"
] | [
"0\n",
"1\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n"
] |
CodeContests | Given a set of $N$ axis-aligned rectangles in the plane, find the area of regions which are covered by at least one rectangle.
Constraints
* $ 1 \leq N \leq 2000 $
* $ −10^9 \leq x1_i < x2_i\leq 10^9 $
* $ −10^9 \leq y1_i < y2_i\leq 10^9 $
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ ... | stdin | null | 3,976 | 1 | [
"4\n0 0 3 1\n0 0 1 3\n0 2 3 3\n2 0 3 3\n",
"3\n1 1 2 5\n2 1 5 2\n1 2 2 5\n",
"2\n0 0 3 4\n1 2 4 3\n"
] | [
"8\n",
"7\n",
"13\n"
] | [
"4\n0 0 3 1\n0 0 1 3\n0 2 4 3\n2 0 3 3\n",
"3\n1 1 2 5\n2 1 5 3\n1 2 2 5\n",
"3\n1 1 3 5\n2 1 5 3\n1 2 2 5\n",
"2\n1 0 3 6\n1 2 4 3\n",
"3\n1 1 3 10\n2 1 5 3\n1 2 2 5\n",
"2\n1 0 3 6\n1 2 4 6\n",
"3\n1 1 3 20\n2 1 5 3\n1 2 2 5\n",
"2\n1 0 3 6\n1 4 4 6\n",
"2\n1 0 3 6\n1 4 7 6\n",
"3\n1 1 3 20\n3 1... | [
"9\n",
"10\n",
"12\n",
"13\n",
"22\n",
"16\n",
"42\n",
"14\n",
"20\n",
"44\n"
] |
CodeContests | Given an array A1,A2...AN, you have to print the size of the largest contiguous subarray such that
GCD of all integers in that subarray is 1.
Formally, For a subarray Ai,Ai+1...Aj where 1 ≤ i < j ≤ N to be valid: GCD(Ai,Ai+1...Aj) should be 1. You have to print the size of the largest valid subarray.
If no valid subarr... | stdin | null | 2,231 | 1 | [
"2\n2\n7 2\n3\n2 2 4\n"
] | [
"2\n-1\n"
] | [
"2\n2\n7 2\n3\n3 2 4\n",
"2\n2\n7 2\n3\n6 2 4\n",
"2\n2\n6 2\n3\n2 2 4\n",
"2\n2\n6 2\n3\n2 3 4\n",
"2\n2\n7 2\n2\n6 2 4\n",
"2\n2\n7 1\n2\n6 2 4\n",
"2\n2\n7 4\n3\n6 2 4\n",
"2\n2\n7 2\n1\n6 2 4\n",
"2\n1\n6 2\n3\n2 3 4\n",
"2\n1\n6 2\n3\n2 4 4\n"
] | [
"2\n3\n",
"2\n-1\n",
"-1\n-1\n",
"-1\n3\n",
"2\n-1\n",
"2\n-1\n",
"2\n-1\n",
"2\n-1\n",
"-1\n3\n",
"-1\n-1\n"
] |
CodeContests | Problem
KND is a student programmer at the University of Aizu. His neighbor is known to be very annoying. Neighbors find out that he is a sweet tooth and plan to add more sweetness than necessary to make him fat. To that end, your neighbor, you, was introduced to a sweets shop by a friend.
However, the way products a... | stdin | null | 1,858 | 1 | [
"3 3 100\n2\n5 20 3 10\n2\n10 50 12 60\n2\n8 30 22 100\n0 1 2\n\n1 1 30\n1\n13 8\n0\n"
] | [
"23 100\n13 8\n"
] | [
"3 3 100\n2\n5 20 3 10\n2\n10 50 16 60\n2\n8 30 22 100\n0 1 2\n\n1 1 30\n1\n13 8\n0\n",
"3 3 100\n2\n5 20 3 10\n2\n13 50 16 60\n2\n0 30 22 100\n0 1 2\n\n1 1 30\n1\n13 8\n0\n",
"3 3 100\n2\n5 20 3 10\n2\n13 50 16 60\n2\n0 30 22 100\n0 0 2\n\n1 1 30\n1\n13 8\n0\n",
"3 3 100\n2\n5 20 3 10\n2\n10 50 12 60\n2\n8 3... | [
"27 100\n13 8\n",
"24 90\n13 8\n",
"22 100\n13 8\n",
"23 100\n13 3\n",
"23 100\n13 8\n",
"27 100\n13 16\n",
"26 90\n13 8\n",
"22 100\n13 3\n",
"34 96\n13 8\n",
"26 83\n13 8\n"
] |
CodeContests | Given is a string S of length N-1. Each character in S is `<` or `>`.
A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \leq i \leq N-1):
* If S_i= `<`: a_i<a_{i+1}
* If S_i= `>`: a_i>a_{i+1}
Find the minimum possible sum of the ele... | stdin | null | 3,673 | 1 | [
"<>>><<><<<<<>>><\n",
"<>>\n"
] | [
"28\n",
"3\n"
] | [
">><\n",
"<>>><<<<<><<>>><\n",
"><>\n",
"<>>>><<<<><<<>><\n",
"<>><<<><<<<>>>><\n",
"<<>><<><<<<>>>><\n",
"<>>>><<<<><<>><<\n",
"<>>>>><<<><<<><<\n",
"<>>><>><<><<<><<\n",
"<<><<<><<>><>>><\n"
] | [
"4\n",
"29\n",
"2\n",
"28\n",
"26\n",
"24\n",
"27\n",
"30\n",
"21\n",
"20\n"
] |
CodeContests | Are you fond of collecting some kind of stuff? Mike is crazy about collecting stamps. He is an active member of Stamp Collecting Сommunity(SCC).
SCC consists of N members which are fond of philately. A few days ago Mike argued with the others from SCC. Mike told them that all stamps of the members could be divided in... | stdin | null | 3,498 | 1 | [
"5\n7 4 1 1 2\n",
"5\n1 1 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | [
"5\n13 4 1 1 2\n",
"5\n13 1 1 1 -1\n",
"5\n1 1 1 1 0\n",
"5\n13 4 1 1 0\n",
"5\n1 2 1 1 0\n",
"5\n13 1 1 1 0\n",
"5\n0 2 1 1 0\n",
"5\n0 3 1 1 0\n",
"5\n13 0 1 1 -1\n",
"5\n0 3 1 0 0\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n"
] |
CodeContests | You have been given a set of N strings S1, S2, .... SN. Consider any non-empty string S (S need not belong to the given set of N strings). Suppose S occurs (as a substring) in K out of the N given strings in the set. Your job is to choose S such that the value of K is maximized. If there are many such strings, choose t... | stdin | null | 408 | 1 | [
"1\n1\nshades\n\nSAMPLE\n"
] | [
"a\n"
] | [
"2\n20\nengagfwhxalwaaucqieavxyutinrmtd\nnxhehybspixeykxillunrhswxskfrzkljeigxwaumrlfqlrrjlngxcyddtunll\nhcqpdelycqspbqrorpslpqwy\nzzjclluwfsyzxvzldjvdpfshbghqcepchuepklddqgtalcbupgexclfdjzjkctlnayuhgrvcsqyxatokefjwbnzvu\nfuxfecjlwilndrijri\naykqwypnriohkyizfvihjkyanijciyqxjslpqdjjjilvekfyphsyqwfshboilbimhp\nhqifzw... | [
"r\ng\n",
"a\n",
"b\ng\n",
"n\ng\n",
"e\ng\n",
"r\na\n",
"r\ne\n",
"b\na\n",
"b\nn\n",
"r\ng\n"
] |
CodeContests | The Wingman gains the attention of a prospective partner for their friend, by tapping them on the shoulder, and then stating only the line "Haaaaave you met Ted?" (substituting the name of "Ted", the main protagonist of the show, with the name of the single person), and then walking away, leaving the newly acquainted p... | stdin | null | 2,312 | 1 | [
"2\n3\n1 2 3\n7\n1 2 3 4 5 6 7 \n\n\nSAMPLE\n"
] | [
"1\n1\n"
] | [
"2\n3\n1 2 3\n7\n1 2 3 4 5 6 9 \n\n\nSAMPLE\n",
"2\n3\n1 2 3\n7\n1 2 3 4 5 6 9 \n\n\nSAMQLE\n",
"2\n3\n1 2 4\n7\n1 2 3 4 5 6 9 \n\n\nSAMPLE\n",
"2\n3\n1 2 3\n7\n1 2 3 4 5 6 13 \n\n\nSAMPLE\n",
"2\n3\n1 2 3\n7\n1 2 3 4 5 6 13 \n\n\nSBMPLE\n",
"2\n3\n1 2 3\n7\n1 2 3 4 5 6 13 \n\n\nELPMBS\n",
"2\n3\n1 2 3\... | [
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n"
] |
CodeContests | Find the number of sequences of N non-negative integers A_1, A_2, ..., A_N that satisfy the following conditions:
* L \leq A_1 + A_2 + ... + A_N \leq R
* When the N elements are sorted in non-increasing order, the M-th and (M+1)-th elements are equal.
Since the answer can be enormous, print it modulo 10^9+7.
Const... | stdin | null | 2,997 | 1 | [
"4 2 3 7\n",
"141592 6535 89793 238462\n",
"2 1 4 8\n"
] | [
"105\n",
"933832916\n",
"3\n"
] | [
"3 2 3 7\n",
"141592 6535 140953 238462\n",
"2 1 1 8\n",
"3 2 3 9\n",
"3 4 3 9\n",
"3 2 6 9\n",
"141592 9415 89793 238462\n",
"3 4 3 7\n",
"194528 6535 140953 238462\n",
"2 1 1 3\n"
] | [
"32\n",
"628292974\n",
"4\n",
"51\n",
"210\n",
"35\n",
"52516436\n",
"110\n",
"582800722\n",
"1\n"
] |
CodeContests | Witua is a little student from the University of Lviv. He enjoys studying math. Witua knows a lot of famous mathematicians like Eratosthenes, Pythagoras, Fermat, Diophantus, Furko, Gauss and so on. However, his favorite one is Euler. The only thing Witua likes more than Euler is Euler’s totient function φ. He is explor... | stdin | null | 3,419 | 1 | [
"3\n2\n3\n4\n"
] | [
"2\n3\n3\n"
] | [
"3\n4\n3\n4\n",
"3\n4\n2\n4\n",
"3\n6\n2\n3\n",
"3\n6\n2\n7\n",
"3\n12\n2\n7\n",
"3\n14\n2\n7\n",
"3\n2\n2\n4\n",
"3\n6\n4\n3\n",
"3\n14\n3\n7\n",
"3\n4\n2\n7\n"
] | [
"3\n3\n3\n",
"3\n2\n3\n",
"5\n2\n3\n",
"5\n2\n7\n",
"11\n2\n7\n",
"13\n2\n7\n",
"2\n2\n3\n",
"5\n3\n3\n",
"13\n3\n7\n",
"3\n2\n7\n"
] |
CodeContests | There are N piles of stones. The i-th pile has A_i stones.
Aoki and Takahashi are about to use them to play the following game:
* Starting with Aoki, the two players alternately do the following operation:
* Operation: Choose one pile of stones, and remove one or more stones from it.
* When a player is unable to do t... | stdin | null | 3,471 | 1 | [
"2\n3 5\n",
"3\n4294967297 8589934593 12884901890\n",
"8\n10 9 8 7 6 5 4 3\n",
"2\n5 3\n",
"3\n1 1 2\n"
] | [
"-1\n",
"1\n",
"3\n",
"1\n",
"-1\n"
] | [
"2\n3 6\n",
"2\n5 5\n",
"2\n7 5\n",
"8\n10 9 8 8 6 9 7 3\n",
"2\n5 1\n",
"2\n11 1\n",
"2\n21 1\n",
"2\n19 1\n",
"2\n7 -1\n",
"3\n869 1 534\n"
] | [
"-1\n",
"0\n",
"1\n",
"3\n",
"2\n",
"5\n",
"10\n",
"9\n",
"4\n",
"167\n"
] |
CodeContests | 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... | stdin | null | 550 | 1 | [
"1 3\n0\n1\n"
] | [
"3\n"
] | [
"1 6\n0\n1\n",
"2 3\n0\n1\n",
"1 6\n1\n1\n",
"2 3\n0\n0\n",
"1 3\n1\n1\n",
"1 11\n0\n1\n",
"1 15\n0\n1\n",
"1 5\n2\n1\n",
"1 8\n0\n1\n",
"1 13\n0\n1\n"
] | [
"6\n",
"1\n",
"5\n",
"0\n",
"2\n",
"11\n",
"15\n",
"3\n",
"8\n",
"13\n"
] |
CodeContests | In 1936, a dictator Hiedler who aimed at world domination had a deep obsession with the Lost Ark. A person with this ark would gain mystic power according to legend. To break the ambition of the dictator, ACM (the Alliance of Crusaders against Mazis) entrusted a secret task to an archeologist Indiana Johns. Indiana ste... | stdin | null | 3,609 | 1 | [
"33 40\n57 144\n0 0\n"
] | [
"22\n94\n"
] | [
"66 40\n57 144\n0 0\n",
"66 40\n57 41\n0 0\n",
"66 40\n108 41\n0 0\n",
"66 65\n108 41\n0 0\n",
"132 65\n108 41\n0 0\n",
"77 65\n108 41\n0 0\n",
"33 39\n57 144\n0 0\n",
"66 40\n52 144\n0 0\n",
"66 40\n57 51\n0 0\n",
"104 40\n108 41\n0 0\n"
] | [
"14\n94\n",
"14\n744\n",
"14\n698\n",
"30\n698\n",
"38\n698\n",
"24\n698\n",
"68\n94\n",
"14\n50\n",
"14\n200\n",
"29\n698\n"
] |
CodeContests | A string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like.
Constraints
* S is a string of length 6 consisting of lowercase English l... | stdin | null | 3,552 | 1 | [
"coffee\n",
"sippuu\n",
"iphone\n"
] | [
"Yes\n",
"Yes\n",
"No\n"
] | [
"cofgee\n",
"sjppvv\n",
"uuppis\n",
"ephoni\n",
"cofgef\n",
"uvppis\n",
"eohoni\n",
"fegfoc\n",
"sippvu\n",
"inohoe\n"
] | [
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n"
] |
CodeContests | Consider a tic-tac-toe on a 3x3 board. Tic-tac-toe is a two-player battle game. Decide the first attack and the second attack, one hits Kuroishi and one hits Shiraishi. The winner is the person who puts stones one by one on the board alternately and arranges three of his own stones first in either the vertical, horizon... | stdin | null | 1,651 | 1 | [
"bbw\nwbw\n+b+\nbwb\nwbw\nwbw\n0\n"
] | [
"b\nNA\n"
] | [
"bbw\nwbw\n+b+\nbwb\nwbx\nwbw\n0\n",
"bbw\nbww\n+b+\nbwb\nwbx\nwbw\n0\n",
"bbw\nwwb\n+a+\nbwb\nxbw\nwvb\n0\n",
"bbw\nwbw\n+b+\nbbw\nwcw\nbww\n0\n",
"bbw\nwcw\n+c+\nwbb\nwcw\nwwb\n0\n",
"cwb\nwwb\n++b\nbwb\nwbw\nxyb\n0\n",
"bbw\nwbw\n+b+\nbwb\nwcw\nwbw\n0\n",
"cbw\nwbw\n+b+\nbwb\nwbx\nwbw\n0\n",
"cbw... | [
"b\nNA\n",
"NA\nNA\n",
"NA\nb\n",
"b\nw\n",
"NA\nw\n",
"b\nb\n",
"b\nNA\n",
"b\nNA\n",
"b\nNA\n",
"NA\nNA\n"
] |
CodeContests | Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Ai... | stdin | null | 2,450 | 1 | [
"16\n10 8\n2 2\n2 5\n2 7\n3 3\n3 8\n4 2\n4 5\n4 8\n6 4\n6 7\n7 5\n7 8\n8 1\n8 4\n9 6\n10 3\n4 3\n8\n6 4\n1 2\n2 1\n2 4\n3 4\n4 2\n5 3\n6 1\n6 2\n3 2\n0\n"
] | [
"4\n3\n"
] | [
"16\n10 8\n2 2\n2 5\n2 7\n3 3\n3 8\n4 2\n4 5\n4 8\n6 4\n6 7\n7 5\n7 8\n8 1\n8 4\n9 6\n10 3\n4 3\n8\n6 4\n1 2\n2 1\n2 4\n3 4\n4 2\n5 3\n6 1\n3 2\n3 2\n0\n",
"16\n10 8\n2 2\n2 5\n2 7\n3 3\n3 8\n4 2\n4 5\n4 8\n6 4\n6 7\n7 5\n7 8\n8 1\n8 4\n9 6\n10 3\n4 3\n8\n6 4\n1 2\n2 1\n2 4\n3 4\n4 2\n5 3\n1 1\n3 2\n3 2\n0\n",
... | [
"4\n3\n",
"4\n4\n",
"5\n4\n",
"5\n3\n",
"3\n3\n",
"6\n4\n",
"6\n3\n",
"7\n4\n",
"4\n2\n",
"3\n4\n"
] |
CodeContests | Little Jhool is still out of his mind - exploring all his happy childhood memories. And one of his favorite memory is when he found a magical ghost, who promised to fulfill one of Little Jhool's wish.
Now, Little Jhool was a kid back then, and so he failed to understand what all could he have asked for from the ghost... | stdin | null | 4,810 | 1 | [
"2\nrrrruubbbyy\nrubrubrubrubrubrubrubrubrubrubrubrubrubrb\n\nSAMPLE\n"
] | [
"2\n0\n"
] | [
"73\naclnbkbzqtvjvtvxdahhimirlsk\nxdcraywfygqxzctmtqsxqmsnbrswwvazwrhgzjo\nxwikhrbybfbvmzbildlhjidjhuoukqxxgadscimzfeiwnzhfeaxkgtehfjslrowxyvjbn\nyvlhmfqxvhbhnwixluolzwflqsvnoqsgpcgxjrxpanofgnhevk\nwpykolkxskhjhryenwliuscqdevoutaknwnjwyaj\naeswrxzrngwdttkwhbcvbcsqxggeezmwenvcpiunnwspxqwcviswpwcrmwczeqjphs\ncfurseij... | [
"0\n0\n2\n1\n0\n0\n1\n1\n1\n1\n1\n0\n0\n2\n1\n0\n0\n1\n0\n0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n1\n0\n1\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n0\n2\n1\n0\n1\n1\n0\n1\n0\n0\n0\n1\n0\n1\n1\n1\n0\n",
"2\n0\n",
"1\n0\n",
"0\n0\n",
"0\n0\n2\n1\n0\n0\n1\n1\n1\n1\n1\n0\n0\n2\n1\n0\n0\n1\n... |
CodeContests | Contest T-shirts
Segtree has $ M $ contest T-shirts.
He decided to spend $ N $ days on the contest T-shirt alone, and told $ i = 1, 2, 3, \ dots, N $ "$ A_i $ T-shirt on the $ i $ day." I made a plan for $ N $ to wear.
However, if you keep the current plan, you may not be able to do the laundry in time, so I would l... | stdin | null | 3,975 | 1 | [
"2 3\n2 2 1\n"
] | [
"1\n"
] | [
"2 0\n2 2 1\n",
"-2 2\n2 2 1\n",
"2 0\n2 0 1\n",
"2 0\n2 0 0\n",
"2 0\n1 0 0\n",
"4 0\n1 0 0\n",
"0 0\n2 2 1\n",
"2 1\n2 0 1\n",
"3 0\n2 0 0\n",
"2 1\n1 0 0\n"
] | [
"0\n",
"1\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n"
] |
CodeContests | Mysterious button
You decide to earn coins in a dungeon on the outskirts of town. There are N rooms in this dungeon, numbered from 1 to N. In addition, there are mysterious buttons called "coin button", "escape button", and "warp button" in the dungeon. The details of each button are as follows.
* There is exactly on... | stdin | null | 3,099 | 1 | [
"4 9\n1 2 1\n1 2 2\n1 3 1\n1 3 2\n1 3 3\n2 3 1\n2 3 2\n1 4 1\n3 4 2\n8\n1 5\n2 5\n3 5\n4 5\n1 1234567\n2 1234567\n3 1234567\n4 1234567\n4 8\n1 2 1\n1 2 1\n1 2 3\n3 4 3\n1 4 2\n2 4 1\n2 4 3\n2 4 3\n8\n1 3\n2 6\n3 8\n4 12\n1 31415926\n2 53589793\n3 23846\n4 26433832\n0 0\n"
] | [
"1\n9\n37\n21\n1\n2469133\n307629943\n60012504\n1\n16\n0\n424\n1\n160769377\n0\n43581113\n"
] | [
"4 9\n1 2 1\n1 2 2\n1 3 1\n1 3 2\n1 3 3\n2 3 1\n2 3 2\n1 4 1\n3 4 2\n8\n1 5\n2 5\n3 5\n4 5\n1 1234567\n2 1234567\n3 1234567\n4 1234567\n4 8\n1 2 1\n1 2 1\n1 2 3\n3 4 4\n1 4 2\n2 4 1\n2 4 3\n2 4 3\n8\n1 3\n2 6\n3 8\n4 12\n1 31415926\n2 53589793\n3 23846\n4 26433832\n0 0\n",
"4 9\n1 2 1\n1 2 2\n1 3 1\n1 3 2\n1 3 3\... | [
"1\n9\n37\n21\n1\n2469133\n307629943\n60012504\n1\n16\n0\n424\n1\n160769377\n0\n43581113\n",
"1\n9\n37\n21\n1\n2495931\n307629943\n60012504\n1\n16\n0\n424\n1\n160769377\n0\n43581113\n",
"1\n9\n37\n21\n1\n2495931\n307629943\n60012504\n1\n16\n0\n358\n1\n160769377\n0\n805676674\n",
"1\n9\n37\n21\n1\n2469133\n307... |
CodeContests | You finally got a magic pot, an alchemy pot. You can create a new item by putting multiple items in the alchemy pot. Newly created items can also be placed in alchemy pots to make other items. A list of items needed to make an item will be called an alchemy recipe. The following three are examples of alchemy recipes.
... | stdin | null | 4,196 | 1 | [
"8\nwood 3000\nstring 800\nrice 36\nwater 0\nracket 5000\nmicrophone 9800\nonigiri 140\nguitar 98000\n3\nracket 2 wood string\nonigiri 2 rice water\nguitar 3 racket microphone onigiri\nguitar\n1\ncomputer 300000\n0\ncomputer\n0\n"
] | [
"13636\n300000\n"
] | [
"8\nwood 3000\nstring 800\nrice 36\nwater 0\nracket 5000\nmicrophone 4961\nonigiri 140\nguitar 98000\n3\nracket 2 wood string\nonigiri 2 rice water\nguitar 3 racket microphone onigiri\nguitar\n1\ncomputer 300000\n0\ncomputer\n0\n",
"8\nwood 5003\nstring 800\nrice 36\nwater 0\nracket 5000\nmicrophone 4961\nonigiri... | [
"8797\n300000\n",
"9997\n300000\n",
"9997\n112750\n",
"8762\n300000\n",
"4997\n112750\n",
"3801\n300000\n",
"36\n112750\n",
"5193\n112750\n",
"0\n112750\n",
"232\n112750\n"
] |
CodeContests | 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... | stdin | null | 555 | 1 | [
"3 8\n",
"4 12\n"
] | [
"3 -1\n",
"1 0\n"
] | [
"5 8\n",
"5 15\n",
"5 1\n",
"5 2\n",
"15 2\n",
"55 2\n",
"61 2\n",
"47 2\n",
"11 2\n",
"6 8\n"
] | [
"-3 2\n",
"1 0\n",
"0 1\n",
"1 -2\n",
"1 -7\n",
"1 -27\n",
"1 -30\n",
"1 -23\n",
"1 -5\n",
"-1 1\n"
] |
CodeContests | We have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\cdots, N and 1, 2, \cdots, N-1. Edge i connects Vertex u_i and v_i.
For integers L, R (1 \leq L \leq R \leq N), let us define a function f(L, R) as follows:
* Let S be the set of the vertices numbered L through R. f(L, R) represents the number ... | stdin | null | 1,721 | 1 | [
"2\n1 2\n",
"10\n5 3\n5 7\n8 9\n1 9\n9 10\n8 4\n7 4\n6 10\n7 2\n",
"3\n1 3\n2 3\n"
] | [
"3\n",
"113\n",
"7\n"
] | [
"2\n0 2\n",
"10\n5 3\n5 7\n8 9\n0 9\n9 10\n8 4\n7 4\n6 10\n7 2\n",
"3\n1 3\n0 3\n",
"10\n5 3\n5 7\n8 9\n0 9\n12 10\n8 4\n7 4\n6 10\n7 2\n",
"2\n-1 1\n",
"10\n5 3\n5 7\n8 9\n0 9\n12 10\n4 4\n7 4\n6 10\n7 2\n",
"2\n-1 2\n",
"3\n1 0\n0 6\n",
"10\n5 3\n5 7\n0 9\n0 9\n12 10\n4 7\n7 4\n6 10\n7 2\n",
"10... | [
"4\n",
"115\n",
"9\n",
"134\n",
"6\n",
"118\n",
"5\n",
"10\n",
"146\n",
"148\n"
] |
CodeContests | Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it.
The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer).... | stdin | null | 4,661 | 1 | [
"1001\n",
"1079\n",
"432\n"
] | [
"927\n",
":(\n",
"400\n"
] | [
"1011\n",
"239\n",
"442\n",
"0001\n",
"452\n",
"192\n",
"661\n",
"322\n",
"84\n",
"18\n"
] | [
"937\n",
"222\n",
"410\n",
"1\n",
"419\n",
"178\n",
":(\n",
"299\n",
"78\n",
"17\n"
] |
CodeContests | We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.
We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this ... | stdin | null | 4,069 | 1 | [
"5 3\n1 2 2 4 5\n",
"10 4\n17 13 13 12 15 20 10 13 17 11\n",
"4 1\n6 6 6 6\n"
] | [
"7.000000000000\n",
"32.000000000000\n",
"3.500000000000\n"
] | [
"10 4\n17 21 13 12 15 20 10 13 17 11\n",
"3 1\n6 6 6 6\n",
"10 4\n15 21 13 12 15 20 10 13 17 11\n",
"3 1\n11 6 6 6\n",
"1 1\n15 6 6 6\n",
"10 4\n17 13 13 14 15 20 10 13 17 11\n",
"3 0\n6 6 6 6\n",
"10 4\n15 21 13 12 15 29 10 13 17 11\n",
"10 4\n27 13 13 14 15 20 10 13 17 11\n",
"10 4\n15 21 13 12 ... | [
"33.5000000000\n",
"3.5000000000\n",
"32.5000000000\n",
"6.0000000000\n",
"8.0000000000\n",
"33.0000000000\n",
"0.0000000000\n",
"36.5000000000\n",
"35.5000000000\n",
"39.0000000000\n"
] |
CodeContests | Mani wants to eat chocolates, but her brother Pane does not give her the chocolates easily. Pane being a mathematician wants to teach Mani an important concept. Pane makes Mani stand on an infinite straight line. He marks all integers at equal divisions on the line and places chocolates on the integer X.
Initially Man... | stdin | null | 2,872 | 1 | [
"3\n2 10\n15758 29586685\n1000 1000000000\n\nSAMPLE\n"
] | [
"0.956092\n0.839450\n0.999716\n"
] | [
"3\n1 10\n15758 29586685\n1000 1000000000\n\nSAMPLE\n",
"3\n2 10\n15758 34034811\n1000 1000000000\n\nSAMPLE\n",
"3\n2 10\n15758 2047890\n1000 1000000000\n\nSAMPLE\n",
"3\n2 4\n15758 2047890\n1000 1000000000\n\nSAMPLE\n",
"3\n2 4\n13327 2047890\n1000 1000000000\n\nSAMPLE\n",
"3\n2 4\n1755 2047890\n1000 100... | [
"0.869573\n0.839450\n0.999716\n",
"0.956092\n0.839450\n0.999716\n",
"0.956092\n0.954879\n0.999716\n",
"0.942406\n0.954879\n0.999716\n",
"0.942406\n0.839450\n0.999716\n",
"0.942406\n0.877149\n0.999716\n",
"0.942406\n0.839450\n0.963018\n",
"0.954879\n0.839450\n0.963018\n",
"0.954879\n0.839450\n0.98312... |
CodeContests | In the year 2020, a race of atomically energized cars will be held. Unlike today’s car races, fueling is not a concern of racing teams. Cars can run throughout the course without any refueling. Instead, the critical factor is tire (tyre). Teams should carefully plan where to change tires of their cars.
The race is a r... | stdin | null | 3,284 | 1 | [
"2\n2 3\n1.0\n1 1.0 0.1 0.3\n5\n5 10 15 20 25\n0.15\n1 1.0 0.04 0.5\n10\n1783 3640 3991 4623 5465 5481 6369 6533 6865 8425\n4.172\n72 59.4705 0.0052834 0.0611224\n0\n"
] | [
"3.5397\n31.9249\n168.6682\n"
] | [
"2\n2 3\n1.0\n1 1.0 0.1 0.3\n5\n5 10 15 20 25\n0.15\n1 1.0 0.04 0.5\n10\n1783 3640 3991 4623 5465 5481 6369 6533 6865 8425\n4.172\n72 59.4705 0.0052834 0.12728810127294996\n0\n",
"2\n2 4\n1.0\n1 1.0 0.1 0.3\n5\n5 10 15 20 25\n0.15\n1 1.0 0.04 0.5\n10\n1783 3640 3991 4623 5465 5481 6369 6533 6865 8425\n4.172\n72 5... | [
"3.539682539683\n31.924934123847\n168.899607025648\n",
"4.789682539683\n31.924934123847\n168.668165496644\n",
"3.539682539683\n31.924934123847\n168.948345560095\n",
"2.048707139896\n31.924934123847\n168.948345560095\n",
"2.048707139896\n31.924934123847\n8.685979469746\n",
"2.048707139896\n31.924934123847\... |
CodeContests | There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, p... | stdin | null | 1,532 | 1 | [
"9 20\n.....***....***.....\n....*...*..*...*....\n...*.....**.....*...\n...*.....*......*...\n....*.....*....*....\n.....**..*...**.....\n.......*..*.*.......\n........**.*........\n.........**.........\n",
"2 2\n*.\n.*\n",
"1 4\n***.\n"
] | [
".....***....***.....\n.....***....***.....\n....*...*..*...*....\n....*...*..*...*....\n...*.....**.....*...\n...*.....**.....*...\n...*.....*......*...\n...*.....*......*...\n....*.....*....*....\n....*.....*....*....\n.....**..*...**.....\n.....**..*...**.....\n.......*..*.*.......\n.......*..*.*.......\n.......... | [
"9 20\n.....***....***.....\n....*...*..*...*....\n...*.....**.....*...\n...*.....*......*...\n....*.....*....*....\n.....**..*...**.....\n.......*.*..*.......\n........**.*........\n.........**.........\n",
"2 2\n*.\n*.\n",
"1 4\n**).\n",
"9 20\n.....***....***.....\n....*...*..*...*....\n...*.....**.....*..... | [
".....***....***.....\n.....***....***.....\n....*...*..*...*....\n....*...*..*...*....\n...*.....**.....*...\n...*.....**.....*...\n...*.....*......*...\n...*.....*......*...\n....*.....*....*....\n....*.....*....*....\n.....**..*...**.....\n.....**..*...**.....\n.......*.*..*.......\n.......*.*..*.......\n.......... |
CodeContests | There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet.
He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square:
* Let M and m be the m... | stdin | null | 610 | 1 | [
"31415 9265 3589\n",
"2 30 15\n",
"2 2 1\n"
] | [
"312069529\n",
"94182806\n",
"6\n"
] | [
"31415 9265 4472\n",
"2 30 23\n",
"60899 9265 4472\n",
"2 30 9\n",
"60899 6796 4472\n",
"2 30 14\n",
"60899 6796 8504\n",
"2 22 14\n",
"118261 6796 8504\n",
"2 22 26\n"
] | [
"202565394\n",
"268153196\n",
"254199232\n",
"225084266\n",
"114280907\n",
"961523759\n",
"277729457\n",
"92755836\n",
"331359071\n",
"92960636\n"
] |
CodeContests | Chain Disappearance Puzzle
We are playing a puzzle. An upright board with H rows by 5 columns of cells, as shown in the figure below, is used in this puzzle. A stone engraved with a digit, one of 1 through 9, is placed in each of the cells. When three or more stones in horizontally adjacent cells are engraved with the... | stdin | null | 3,965 | 1 | [
"1\n6 9 9 9 9\n5\n5 9 5 5 9\n5 5 6 9 9\n4 6 3 6 9\n3 3 2 9 9\n2 2 1 1 1\n10\n3 5 6 5 6\n2 2 2 8 3\n6 2 5 9 2\n7 7 7 6 1\n4 6 6 4 9\n8 9 1 1 8\n5 6 1 8 1\n6 8 2 1 2\n9 6 3 3 5\n5 3 8 8 8\n5\n1 2 3 4 5\n6 7 8 9 1\n2 3 4 5 6\n7 8 9 1 2\n3 4 5 6 7\n3\n2 2 8 7 4\n6 5 7 7 7\n8 8 9 9 9\n0\n"
] | [
"36\n38\n99\n0\n72\n"
] | [
"1\n6 9 9 9 9\n5\n5 9 5 2 9\n5 5 6 9 9\n4 6 3 6 9\n3 3 2 9 9\n2 2 1 1 1\n10\n3 5 6 5 6\n2 2 2 8 3\n6 2 5 9 2\n7 7 7 6 1\n4 6 6 4 9\n8 9 1 1 8\n5 6 1 8 1\n6 8 2 1 2\n9 6 3 3 5\n5 3 8 8 8\n5\n1 2 3 4 5\n6 7 8 9 1\n2 3 4 5 6\n7 8 9 1 2\n3 4 5 6 7\n3\n2 2 8 7 4\n6 5 7 7 7\n8 8 9 9 9\n0\n",
"1\n6 9 9 9 9\n5\n5 9 5 2 9... | [
"36\n33\n99\n0\n72\n",
"36\n42\n99\n0\n72\n",
"36\n42\n81\n0\n72\n",
"36\n42\n81\n0\n48\n",
"36\n24\n81\n0\n48\n",
"36\n24\n60\n0\n48\n",
"36\n38\n81\n0\n72\n",
"36\n42\n60\n0\n72\n",
"36\n9\n60\n0\n48\n",
"36\n38\n81\n0\n48\n"
] |
CodeContests | You have been given a String S. You need to find and print whether this string is a palindrome or not. If yes, print "YES" (without quotes), else print "NO" (without quotes).
Input Format
The first and only line of input contains the String S. The String shall consist of lowercase English alphabets only.
Output Form... | stdin | null | 2,553 | 1 | [
"aba\n\nSAMPLE\n"
] | [
"YES\n"
] | [
"nsulseywoisclqklapgbgzodlhwrlzoyqmkothalkoculthnarpxkwxjxhfrayjwollljptxyyydcjuaejoyjhdsdjqjigggbvoe\n",
"aba\n\nSAPMLE\n",
"fnjzxnxnjplfwzowfdrhrvheglmoncbkembjoudteqchjwqfzlofyflkmxnooasxulwofjzknthqqxgshvwxdvhdnlzjzdjdiifg\n",
"eovbgggijqjdsdhjyojeaujcdyyyxtpjlklowjyarfhxjxwkxpranhtlucoklahtokmqyozlrwhldo... | [
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n"
] |
CodeContests | 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... | stdin | null | 356 | 1 | [
"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\n"
] | [
"0\n1\n2\n"
] | [
"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\n",
"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\n",
"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... | [
"0\n1\n1\n",
"0\n1\n2\n",
"0\n1\n3\n",
"0\n0\n2\n",
"0\n0\n3\n",
"0\n0\n1\n",
"1\n1\n3\n",
"0\n1\n4\n",
"0\n0\n0\n",
"0\n1\n0\n"
] |
CodeContests | Champernowne constant is an irrational number. Its decimal representation starts with "0.", followed by concatenation of all positive integers in the increasing order.
You will be given a sequence S which consists of decimal digits. Your task is to write a program which computes the position of the first occurrence of... | stdin | null | 4,125 | 1 | [
"45678\n67891011\n21\n314159265358979\n",
"45678\n67891011\n21\n314159265358979\n#\n"
] | [
"4\n6\n15\n2012778692735799\n",
"4\n6\n15\n2012778692735799\n"
] | [
"45678\n67891011\n28\n314159265358979\n",
"45678\n67891011\n9\n314159265358979\n",
"45678\n67891011\n9\n438894300035810\n",
"45678\n48782446\n9\n438894300035810\n",
"45678\n48782446\n9\n625210440910086\n",
"45678\n91285515\n9\n625210440910086\n",
"45678\n135768712\n9\n625210440910086\n",
"45678\n13576... | [
"4\n6\n46\n2012778692735799\n",
"4\n6\n9\n2012778692735799\n",
"4\n6\n9\n1454723033894262\n",
"4\n184607918\n9\n1454723033894262\n",
"4\n184607918\n9\n130096418350620\n",
"4\n91730089\n9\n130096418350620\n",
"4\n275038585\n9\n130096418350620\n",
"4\n275038585\n9\n1743139959995792\n",
"4\n8095923\n9\... |
CodeContests | There are N people standing in a queue from west to east.
Given is a string S of length N representing the directions of the people. The i-th person from the west is facing west if the i-th character of S is `L`, and east if that character of S is `R`.
A person is happy if the person in front of him/her is facing the... | stdin | null | 647 | 1 | [
"6 1\nLRLRRL\n",
"9 2\nRRRLRLRLL\n",
"13 3\nLRRLRLRRLRLLR\n",
"10 1\nLLLLLRRRRR\n"
] | [
"3\n",
"7\n",
"9\n",
"9\n"
] | [
"6 2\nLRLRRL\n",
"9 3\nRRRLRLRLL\n",
"9 0\nRRRLRLRLL\n",
"6 0\nLRRLRL\n",
"9 1\nRRRRLLRLL\n",
"9 1\nRLRRLLLRR\n",
"6 1\nRRLLRL\n",
"10 2\nLLLLLRRRRR\n",
"13 4\nLRRLRLRRLRLLR\n",
"13 8\nLRRLRLRRLRLLR\n"
] | [
"5\n",
"8\n",
"3\n",
"1\n",
"7\n",
"6\n",
"4\n",
"9\n",
"11\n",
"12\n"
] |
CodeContests | Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.
Given an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print `Yes`; if it cannot, print `No`.
Constraints
* 1 \leq N \leq 100
* N is an int... | stdin | null | 2,641 | 1 | [
"10\n",
"81\n",
"50\n"
] | [
"Yes\n",
"Yes\n",
"No\n"
] | [
"2\n",
"84\n",
"83\n",
"1\n",
"107\n",
"92\n",
"0\n",
"100\n",
"64\n",
"-1\n"
] | [
"Yes\n",
"No\n",
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n",
"No\n"
] |
CodeContests | Problem Statement
As they say, small is cute and beautiful.
Given N distinct positive integers, find the smallest number that can be formed by concatenating all of them.
Input Format
The first line of the input file contains a positive integer N. Then N lines follow.
Each line contains a single positive integer K.
Ou... | stdin | null | 3,589 | 1 | [
"5\n14\n66\n907\n1234567890\n9876543210\n\nSAMPLE\n"
] | [
"123456789014669079876543210\n"
] | [
"5\n345\n999\n34562\n345621\n345627\n",
"5\n14\n66\n907\n1234567890\n4232624373\n\nSAMPLE\n",
"5\n72\n999\n34562\n345621\n345627\n",
"5\n14\n66\n907\n2460108572\n4232624373\n\nSAMPLE\n",
"5\n72\n999\n34562\n48287\n345627\n",
"5\n14\n66\n1444\n2460108572\n4232624373\n\nSAMPLE\n",
"5\n60\n999\n34562\n4828... | [
"34534562134562345627999\n",
"123456789014423262437366907\n",
"3456213456234562772999\n",
"142460108572423262437366907\n",
"345623456274828772999\n",
"1414442460108572423262437366\n",
"345623456274828760999\n",
"144424601085724232624373668\n",
"345623456274249060999\n",
"345623456276070050999\n"
] |
CodeContests | Yae joins a journey plan, in which parties will be held several times during the itinerary. She wants to participate in all of them and will carry several dresses with her. But the number of dresses she can carry with her may be smaller than that of the party opportunities. In that case, she has to wear some of her dre... | stdin | null | 1,097 | 1 | [
"25 10\n",
"3 5\n"
] | [
"1\n",
"2\n"
] | [
"10 10\n",
"3 9\n",
"3 15\n",
"3 26\n",
"1 26\n",
"1 43\n",
"1 65\n",
"1 18\n",
"2 8\n",
"2 3\n"
] | [
"1\n",
"3\n",
"5\n",
"9\n",
"26\n",
"43\n",
"65\n",
"18\n",
"4\n",
"2\n"
] |
CodeContests | Takahashi is going to buy N items one by one.
The price of the i-th item he buys is A_i yen (the currency of Japan).
He has M discount tickets, and he can use any number of them when buying an item.
If Y tickets are used when buying an item priced X yen, he can get the item for \frac{X}{2^Y} (rounded down to the nea... | stdin | null | 1,243 | 1 | [
"1 100000\n1000000000\n",
"10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"4 4\n1 9 3 5\n",
"3 3\n2 13 8\n"
] | [
"0\n",
"9500000000\n",
"6\n",
"9\n"
] | [
"1 101000\n1000000000\n",
"10 1\n1000000000 1001000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"3 3\n2 13 3\n",
"10 1\n1000000000 1001000000 1000000000 1000000000 1000000000 1000000000 1000000000 1010000000 1000000000 1000000000\n",
"3 2\n2 13 3\n",
"10 ... | [
"0\n",
"9500500000\n",
"6\n",
"9506000000\n",
"8\n",
"9506005000\n",
"7\n",
"9516005000\n",
"9571010000\n",
"9671010000\n"
] |
CodeContests | An arithmetic pipeline is designed to process more than one task simultaneously in an overlapping manner. It includes function units and data paths among them. Tasks are processed by pipelining: at each clock, one or more units are dedicated to a task and the output produced for the task at the clock is cascading to th... | stdin | null | 1,695 | 1 | [
"7\nX...XX.\n.X.....\n..X....\n...X...\n......X\n0\n"
] | [
"34\n"
] | [
"7\nX...XX.\n.X.....\n..X/...\n...X...\n......X\n0\n",
"7\nX...XX.\n.X.....\n..X/...\n...X...\n.-....X\n0\n",
"7\nX...XX.\n.X.....\n..X...-\n...X...\n......X\n0\n",
"7\nX...XX.\n.X.....\n..X/...\n./.X...\n......X\n0\n",
"7\nX...XX.\n.X.....\n..X...-\n..-X...\n......X\n0\n",
"7\nX...XX.\n.X.....\n..X...-\n... | [
"34\n",
"34\n",
"34\n",
"34\n",
"34\n",
"34\n",
"34\n",
"34\n",
"34\n",
"34\n"
] |
CodeContests | problem
You are in charge of quality control at a machine manufacturing plant. This machine requires a power supply, a motor, and a cable as parts. The manufacturing plant has a power supply, b motors, and c cables, numbered from 1 to a, a + 1 to a + b, and a + b + 1 to a + b + c, respectively. attached. The trouble i... | stdin | null | 2,967 | 1 | [
"2 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 5 1\n0 0 0\n"
] | [
"2\n1\n1\n0\n1\n0\n"
] | [
"2 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 2 1\n0 0 0\n",
"2 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 2 0\n0 0 0\n",
"3 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 5 1\n0 0 0\n",
"2 2 2\n4\n3 4 5 0\n2 3 6 0\n1 4 4 1\n2 3 2 0\n0 0 0\n",
"2 2 2\n4\n2 4 5 0\n1 3 6 0\n1 4 5 0\n2 3 2 1\n0 0 0\n",
"3 2 2\n4\n2 4 5 0\n2... | [
"2\n1\n1\n2\n2\n0\n",
"2\n2\n2\n2\n2\n2\n",
"2\n1\n1\n0\n1\n0\n2\n",
"1\n2\n2\n1\n2\n2\n",
"2\n1\n1\n2\n2\n2\n",
"2\n1\n1\n0\n1\n2\n2\n",
"0\n0\n1\n1\n1\n2\n2\n",
"2\n2\n2\n2\n2\n2\n2\n2\n",
"2\n2\n2\n2\n2\n2\n2\n",
"1\n2\n1\n0\n1\n2\n"
] |
CodeContests | Professor Matsuzaki is a scientist studying the truth of the universe. Life, the universe, all the answers are said to be 42, but Professor Matsuzaki thinks that this alone is not enough to elucidate the truth of the universe. Professor Matsuzaki believes that the truth of the universe is represented by a function cons... | stdin | null | 4,282 | 1 | [
"0 55\n0 1\n0 2\n0 3\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n11 1\n11 2\n11 3\n100000 100\n-1 -1\n"
] | [
"42\n4\n5\n6\n22\n24\n26\n28\n30\n30\n26\n30\n32\n200274\n"
] | [
"0 55\n0 1\n0 2\n0 3\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n11 1\n11 2\n11 3\n100001 100\n-1 -1\n",
"0 55\n0 1\n0 2\n0 3\n10 1\n10 2\n10 3\n10 4\n10 5\n10 1\n11 1\n11 2\n11 3\n100001 100\n-1 -1\n",
"0 55\n0 1\n0 2\n0 3\n10 1\n10 2\n10 3\n10 4\n10 5\n19 6\n11 1\n11 2\n11 3\n100000 100\n-1 -1\n",
"0 55\n0 1\n0 2\... | [
"42\n4\n5\n6\n22\n24\n26\n28\n30\n30\n26\n30\n32\n200274\n",
"42\n4\n5\n6\n22\n24\n26\n28\n30\n22\n26\n30\n32\n200274\n",
"42\n4\n5\n6\n22\n24\n26\n28\n30\n60\n26\n30\n32\n200274\n",
"42\n4\n5\n6\n22\n24\n26\n28\n30\n22\n22\n30\n32\n200274\n",
"42\n4\n5\n6\n22\n24\n26\n28\n30\n22\n22\n42\n32\n200274\n",
"... |
CodeContests | There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square.
Snuke cast Q spells to move the golems.
The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke ca... | stdin | null | 413 | 1 | [
"10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nS L\n",
"3 4\nABC\nA L\nB L\nB R\nA R\n",
"8 3\nAABCBDBA\nA L\nB R\nA R\n"
] | [
"3\n",
"2\n",
"5\n"
] | [
"10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nR L\n",
"3 4\nACB\nA L\nB L\nB R\nA R\n",
"8 3\nAABBBDBA\nA L\nB R\nA R\n",
"3 3\nACB\nB L\nB L\nA R\n@ S\n",
"3 3\nBCA\nB L\nB L\nA R\n@ S\n",
"8 0\nAABCBDBA\nA L\nB R\n@ S\n",
"8 3\nAABCBDBA\nC L\nB R\nA R\n",
... | [
"7\n",
"2\n",
"5\n",
"3\n",
"1\n",
"8\n",
"6\n",
"9\n",
"10\n",
"0\n"
] |
CodeContests | Takahashi has a string S of length N consisting of digits from `0` through `9`.
He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S - there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten.
Here substrings starting with a `0`... | stdin | null | 3,472 | 1 | [
"4 3\n3543\n",
"20 11\n33883322005544116655\n",
"4 2\n2020\n"
] | [
"6\n",
"68\n",
"10\n"
] | [
"20 8\n33883322005544116655\n",
"20 5\n33883322005544116655\n",
"20 5\n35091597582718018558\n",
"20 3\n35091597582718018558\n",
"20 5\n34713145004890865366\n",
"20 5\n63523169932268849551\n",
"20 2\n33883322005544116655\n",
"20 5\n39199232665812066366\n",
"20 1\n33883322005544116655\n",
"20 5\n475... | [
"171\n",
"81\n",
"72\n",
"66\n",
"58\n",
"40\n",
"103\n",
"26\n",
"210\n",
"60\n"
] |
CodeContests | A: Find the difference
problem
Given rectangular boards A and B with N squares vertically and M squares horizontally. For each board, each square is painted white or black.
The color of the square in the i-th row and j-th column of the board X is written as C (i, j, X).
Count how many pairs of integers (i, j) meet ... | stdin | null | 3,534 | 1 | [
"2 3\n..#\n##.\n.##\n#..\n"
] | [
"2\n"
] | [
"2 3\n..\"\n##.\n.##\n#..\n",
"2 3\n..\"\n.##\n.##\n#..\n",
"2 3\n..#\n#\".\n.##\n$./\n",
"2 1\n..\"\n.##\n.##\n#./\n",
"2 3\n..#\n#\".\n##.\n$./\n",
"0 3\n..#\n.\"#\n##.\n$./\n",
"3 3\n#..\n.#\"\n##.\n$./\n",
"2 3\n.#.\n##.\n##.\n#..\n",
"4 3\n..\"\n##.\n.##\n..#\n",
"3 3\n..#\n\"\".\n.#\"\n%-/\n... | [
"3\n",
"5\n",
"4\n",
"1\n",
"6\n",
"0\n",
"8\n",
"2\n",
"12\n",
"9\n"
] |
CodeContests | Santa is going to pack gifts into a bag for a family. There are $N$ kinds of gifts. The size and the price of the $i$-th gift ($1 \leq i \leq N$) are $s_i$ and $p_i$, respectively. The size of the bag is $C$, thus Santa can pack gifts so that the total size of the gifts does not exceed $C$. Children are unhappy if they... | stdin | null | 1,464 | 1 | [
"1 1 2\n1 1\n",
"6 3 2\n1 2\n2 10\n3 5\n",
"2 2 2\n1 1\n2 100\n",
"200 5 5\n31 41\n59 26\n53 58\n97 93\n23 84\n"
] | [
"1\n0\n",
"17\n24\n",
"100\n2\n",
"235\n284\n375\n336\n420\n"
] | [
"1 1 2\n2 1\n",
"2 2 2\n2 1\n2 100\n",
"18 5 5\n31 41\n59 26\n53 58\n97 93\n23 84\n",
"18 5 9\n59 41\n59 26\n53 58\n97 93\n23 84\n",
"18 5 9\n7 41\n59 26\n53 58\n97 93\n23 84\n",
"30 10 9\n7 41\n59 26\n37 58\n97 93\n23 84\n",
"30 10 9\n0 41\n59 26\n37 5\n97 93\n20 84\n",
"31 16 9\n0 8\n59 26\n65 5\n97... | [
"0\n0\n",
"100\n0\n",
"0\n0\n0\n0\n0\n",
"0\n0\n0\n0\n0\n0\n0\n0\n0\n",
"41\n82\n0\n0\n0\n0\n0\n0\n0\n",
"125\n82\n123\n164\n0\n0\n0\n0\n0\n",
"125\n82\n123\n164\n205\n246\n287\n328\n369\n",
"92\n16\n24\n32\n40\n48\n56\n64\n72\n",
"0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n",
"0\n0\n0\n0\n0\... |
CodeContests | Campus Ambassador has organized a Coding Contest in his college. Contest has multiple rounds, in each round a participant may gain or lose few points. At the end, there is only one participant with the maximum points. In the course of the contest, the number of points is written in the line as
"name points", where nam... | stdin | null | 2,834 | 1 | [
"3\nmini 3\nrini 5\nmini 2\n\nSAMPLE\n"
] | [
"rini\n"
] | [
"10\nmahi 3\nmahi 2\nvicky 5\nankit 5\npooja 4\nramesh 4\nankita 4\nmanisha 3\nmanisha 3\nkejal 5\n",
"15\nmahi 3\nmahi 2\nvicky 5\nankit 5\npooja 4\nramesh 4\nankita 2\nmanisha 3\nmanisha 3\nkejal 7\ndarshit 2\nrahul 4\nmahi 2\nvicky 1\nmanisha 1\n",
"3\nmini 1\nrini 5\nmini 2\n\nSAMPLE\n",
"3\nmini 1\nirni ... | [
"manisha\n",
"kejal\n",
"rini\n",
"irni\n",
"ramesh\n",
"vicky\n",
"minj\n",
"pooaj\n",
"rbmesh\n",
"rbmhse\n"
] |
CodeContests | problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color w... | stdin | null | 4,363 | 1 | [
"8 2\n23 61 57 13 91 41 79 41\n"
] | [
"170\n"
] | [
"8 2\n23 85 57 13 91 41 79 41\n",
"8 2\n23 94 57 13 91 41 79 41\n",
"8 2\n23 70 57 13 91 41 79 41\n",
"8 2\n23 70 57 13 91 41 79 43\n",
"8 2\n46 70 57 13 91 41 79 43\n",
"8 4\n46 70 57 13 91 41 79 43\n",
"8 4\n46 70 57 10 91 41 79 43\n",
"8 4\n46 70 57 10 91 41 130 43\n",
"8 4\n46 70 57 10 174 41 13... | [
"194\n",
"203\n",
"179\n",
"177\n",
"154\n",
"107\n",
"110\n",
"149\n",
"193\n",
"201\n"
] |
CodeContests | Chef Ash and Chef Elsh invented a new hash function! Their hash function will map a binary string consisting of characters 'A' and 'E' into an integer called the hash value of the string.
The pseudocode of the hash function is as below. hash(S) is the hash value of a binary string S. |S| denotes the length of S.
funct... | stdin | null | 3,578 | 1 | [
"4\n0 0 0\n1 0 1\n3 2 6\n4 2 8\n"
] | [
"1\n1\n3\n4\n"
] | [
"4\n0 0 0\n1 0 1\n3 2 12\n4 2 8\n",
"4\n0 0 0\n1 1 1\n-1 2 12\n4 2 8\n",
"4\n0 0 0\n1 1 1\n-1 2 12\n2 2 8\n",
"4\n0 0 0\n1 1 1\n-1 2 12\n3 2 8\n",
"4\n0 0 0\n1 1 2\n-1 2 12\n3 -1 7\n",
"4\n0 0 0\n1 0 1\n3 2 6\n6 2 8\n",
"4\n-1 0 0\n1 0 1\n3 2 12\n4 2 8\n",
"4\n0 0 0\n1 0 1\n0 2 12\n4 2 9\n",
"4\n0 0... | [
"1\n1\n0\n4\n",
"1\n0\n0\n4\n",
"1\n0\n0\n0\n",
"1\n0\n0\n2\n",
"1\n2\n0\n0\n",
"1\n1\n3\n0\n",
"0\n1\n0\n4\n",
"1\n1\n0\n5\n",
"0\n0\n0\n0\n",
"1\n1\n1\n4\n"
] |
CodeContests | H - Rings
Problem Statement
There are two circles with radius 1 in 3D space. Please check two circles are connected as chained rings.
Input
The input is formatted as follows.
{c_x}_1 {c_y}_1 {c_z}_1
{v_x}_{1,1} {v_y}_{1,1} {v_z}_{1,1} {v_x}_{1,2} {v_y}_{1,2} {v_z}_{1,2}
{c_x}_2 {c_y}_2 {c_z}_2
{v_x}_{2,1} {v_y}_{... | stdin | null | 2,619 | 1 | [
"0.0 0.0 0.0\n1.0 0.0 0.0 0.0 1.0 0.0\n1.0 0.0 0.5\n1.0 0.0 0.0 0.0 0.0 1.0\n"
] | [
"YES\n"
] | [
"0.0 0.0 0.0\n1.3851474630540055 0.0 0.0 0.0 1.0 0.0\n1.0 0.0 0.5\n1.0 0.0 0.0 0.0 0.0 1.0\n",
"0.9153144643366036 0.0 0.0\n1.3851474630540055 0.0 0.0 0.0 1.0 0.0\n1.0 0.0 0.5\n1.0 0.0 0.0 0.0 0.0 1.0\n",
"0.0 0.0 0.0\n1.0 0.0 0.0 0.0 1.0 0.0\n1.0 0.0 0.5\n1.2038717327869979 0.0 0.0 0.0 0.0 1.0\n",
"0.0 0.0 0... | [
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n"
] |
CodeContests | Tax Rate Changed
VAT (value-added tax) is a tax imposed at a certain rate proportional to the sale price.
Our store uses the following rules to calculate the after-tax prices.
* When the VAT rate is x%, for an item with the before-tax price of p yen, its after-tax price of the item is p (100+x) / 100 yen, fractions ... | stdin | null | 2,969 | 1 | [
"5 8 105\n8 5 105\n1 2 24\n99 98 24\n12 13 26\n1 22 23\n1 13 201\n13 16 112\n2 24 50\n1 82 61\n1 84 125\n1 99 999\n99 1 999\n98 99 999\n1 99 11\n99 1 12\n0 0 0\n"
] | [
"109\n103\n24\n24\n26\n27\n225\n116\n62\n111\n230\n1972\n508\n1004\n20\n7\n"
] | [
"5 8 105\n8 5 105\n1 2 24\n4 98 24\n12 13 26\n1 22 23\n1 13 201\n13 16 112\n2 24 50\n1 82 61\n1 84 125\n1 99 999\n99 1 999\n98 99 999\n1 99 11\n99 1 12\n0 0 0\n",
"5 8 105\n8 5 105\n1 2 24\n4 98 24\n12 5 26\n1 22 23\n1 13 201\n13 16 112\n2 24 50\n1 82 61\n1 84 125\n1 99 999\n99 1 999\n98 99 999\n1 99 11\n99 1 12\... | [
"109\n103\n24\n46\n26\n27\n225\n116\n62\n111\n230\n1972\n508\n1004\n20\n7\n",
"109\n103\n24\n46\n25\n27\n225\n116\n62\n111\n230\n1972\n508\n1004\n20\n7\n",
"109\n103\n24\n24\n26\n27\n237\n116\n62\n111\n230\n1972\n508\n1004\n20\n7\n",
"109\n103\n24\n46\n25\n27\n225\n112\n62\n111\n230\n1972\n508\n1004\n20\n7\n"... |
CodeContests | There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
Constraints
* 1 \leq S \leq 100
* 1 \leq W \leq 100
Input
Input is given from Standard Input in the fol... | stdin | null | 1,482 | 1 | [
"4 5\n",
"100 2\n",
"10 10\n"
] | [
"unsafe\n",
"safe\n",
"unsafe\n"
] | [
"1 5\n",
"101 2\n",
"5 10\n",
"1 6\n",
"111 2\n",
"8 10\n",
"0 6\n",
"111 0\n",
"11 10\n",
"-1 6\n"
] | [
"unsafe\n",
"safe\n",
"unsafe\n",
"unsafe\n",
"safe\n",
"unsafe\n",
"unsafe\n",
"safe\n",
"safe\n",
"unsafe\n"
] |
CodeContests | Everyone knows that chotu likes palindromic strings. One day, he found 2 ordinary strings s1 and s2. Now he wonders if he could make a palindrome by concatenating s1 and s2 in any order. i.e if s1s2 or s2s1 is a palindrome.
Input
First line of input contains T, denoting number of test cases.
Each test case contains t... | stdin | null | 1,795 | 1 | [
"2\naba\nbaba\nxy\nzw\n\nSAMPLE\n"
] | [
"YES\nNO\n"
] | [
"2\naba\nbaba\nxy\nzw\n\nELPMAS\n",
"2\naba\nbaaa\nxy\nwz\n\nELPMAS\n",
"2\naca\nbaab\nwy\nyw\n\nSQAMLE\n",
"2\naba\nbaba\nxy\nwz\n\nELPMAS\n",
"2\naba\nbaaa\nxy\nwz\n\nSAMPLE\n",
"2\naba\nbaaa\nxy\nwy\n\nSAMPLE\n",
"2\naba\naaaa\nxy\nwy\n\nSAMPLE\n",
"2\naca\naaaa\nxy\nwy\n\nSAMPLE\n",
"2\naca\naaa... | [
"YES\nNO\n",
"NO\nNO\n",
"NO\nYES\n",
"YES\nNO\n",
"NO\nNO\n",
"NO\nNO\n",
"NO\nNO\n",
"NO\nNO\n",
"NO\nNO\n",
"NO\nNO\n"
] |
CodeContests | Steve runs a small restaurant in a city. Also, as he is the only cook in his restaurant, he cooks everything ordered by customers.
Basically he attends to orders by first-come-first-served principle. He takes some prescribed time to prepare each dish. As a customer can order more than one dish at a time, Steve starts ... | stdin | null | 1,698 | 1 | [
"5 4\nRamen 3 10\nChahan 5 5\nGyoza 5 10\nRice 1 1\nSoup 1 1\n5 2 Ramen Gyoza\n10 6 Chahan Gyoza Soup Ramen Gyoza Rice\n20 1 Chahan\n25 1 Ramen\n0 0\n"
] | [
"25\n42\n40\n35\n"
] | [
"5 4\nRamen 3 10\nChahan 5 5\nGyoza 5 10\nRice 1 1\nSoup 1 1\n0 2 Ramen Gyoza\n10 6 Chahan Gyoza Soup Ramen Gyoza Rice\n20 1 Chahan\n25 1 Ramen\n0 0\n",
"5 4\nRamen 3 10\nChahan 5 5\nGyoza 5 10\nRice 1 2\nSoup 1 1\n0 2 Ramen Gyoza\n10 6 Chahan Gyoza Soup Ramen Gyoza Rice\n20 1 Chahan\n25 1 Ramen\n0 0\n",
"5 4\n... | [
"20\n37\n35\n47\n",
"20\n38\n35\n48\n",
"24\n41\n39\n51\n",
"20\n39\n35\n49\n",
"20\n57\n55\n67\n",
"24\n40\n39\n50\n",
"20\n43\n39\n53\n",
"20\n47\n45\n57\n",
"14\n31\n29\n41\n",
"20\n35\n35\n45\n"
] |
CodeContests | Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is a... | stdin | null | 4,007 | 1 | [
"5\n1 2 3 3 4 5 7 7 7\nR R R R R R G G G\n1 2 2 3 4 4 4 4 5\nR R R R R R R R R\n1 2 3 4 4 4 5 5 5\nR R B R R R R R R\n1 1 1 3 4 5 6 6 6\nR R B G G G R R R\n2 2 2 3 3 3 1 1 1\nR G B R G B R G B\n"
] | [
"1\n0\n0\n0\n1\n"
] | [
"5\n1 2 3 3 4 5 7 7 7\nR R R R R R G G G\n1 2 2 3 4 4 4 4 5\nR R R R R R R R R\n1 2 3 4 4 4 5 5 5\nR R B R R R R R R\n1 1 1 3 4 5 6 6 6\nR R B G G G R R R\n2 2 2 3 3 3 1 1 2\nR G B R G B R G B\n",
"5\n1 2 3 3 4 5 7 7 7\nR R R R R R G G G\n1 2 2 3 4 4 4 4 5\nR R R R R R R R R\n1 2 3 4 4 4 5 5 5\nR R B R R R R R R\... | [
"1\n0\n0\n0\n0\n",
"1\n0\n0\n0\n1\n",
"0\n0\n0\n0\n0\n",
"0\n0\n0\n0\n1\n",
"0\n1\n0\n0\n0\n",
"1\n0\n0\n0\n0\n",
"1\n0\n0\n0\n0\n",
"1\n0\n0\n0\n0\n",
"1\n0\n0\n0\n0\n",
"1\n0\n0\n0\n0\n"
] |
CodeContests | The arrival times of N trains are given in the format hours : minutes : seconds. However for the sake of simplicity the time is considered only in seconds format i.e., 3600hours + 60minutes + seconds (Let's say this x). Now if x is a prime number, the halt for the train at the station is 5 minutes, if it's an odd numbe... | stdin | null | 1,636 | 1 | [
"5\n11 57 9\n20 25 53\n8 41 3\n16 58 30\n21 47 8\n\nSAMPLE\n"
] | [
"1\n"
] | [
"100\n1 20 0\n3 13 7\n4 0 58\n22 43 19\n5 12 8\n20 3 11\n12 19 55\n2 25 22\n11 28 33\n13 57 11\n21 57 46\n14 57 35\n2 55 50\n13 6 58\n5 14 57\n20 25 42\n15 13 30\n8 27 55\n16 0 13\n13 11 12\n15 50 49\n12 17 38\n11 8 40\n17 58 34\n23 47 11\n16 30 44\n17 0 28\n20 47 31\n13 0 43\n4 4 23\n18 45 0\n0 23 19\n0 55 43\n22 ... | [
"4\n",
"1\n",
"3\n",
"5\n",
"2\n",
"6\n",
"4\n",
"1\n",
"4\n",
"1\n"
] |
CodeContests | Printf{}, Pappu Bhujia, mon_ki_onkh are playing Counter Strike 1.6 . Printf{} and Pappu Bhujia are in the same team (Counter Terrorists) and mon_ki_onkh is in the opposite team (Terrorists). It is a 2 on 1 round. The players playing have enough guns and bullets to fight.
Some Facts to be known :
The number of bullets ... | stdin | null | 1,595 | 1 | [
"6\n2\n3\n4\n5\n6\n7\n\nSAMPLE\n"
] | [
"Printf{}\nPrintf{}\nPrintf{}\nPrintf{}\nPappu Bhujia\nPrintf{}\n"
] | [
"49\n663097\n388111\n671150\n554555\n1520\n761945\n21398\n808929\n365213\n620626\n55553\n253333\n316221\n619260\n51426\n618462\n366801\n808365\n947305\n759616\n740902\n548182\n703319\n971726\n140673\n970631\n522995\n677526\n512891\n44689\n527801\n626569\n825751\n44150\n424499\n677002\n359365\n996242\n556889\n997415... | [
"Printf{}\nPrintf{}\nPrintf{}\nPrintf{}\nPrintf{}\nPappu Bhujia\nPrintf{}\nPrintf{}\nPrintf{}\nPappu Bhujia\nPappu Bhujia\nPappu Bhujia\nPappu Bhujia\nPrintf{}\nPrintf{}\nPrintf{}\nPappu Bhujia\nPrintf{}\nPrintf{}\nPrintf{}\nPappu Bhujia\nPappu Bhujia\nPappu Bhujia\nPappu Bhujia\nPrintf{}\nPappu Bhujia\nPappu Bhuji... |
CodeContests | We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \... | stdin | null | 687 | 1 | [
"12 3\n1 1\n1 1\n1 1\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n",
"4 5\n0 5\n-2 4\n3 4\n4 -4\n",
"20 100000\n14309 -32939\n-56855 100340\n151364 25430\n103789 -113141\n147404 -136977\n-37006 -30929\n188810 -49557\n13419 70401\n-88280 165170\n-196399 137941\n-176527 -61904\n46659 115261\n-153551 114185\n9878... | [
"7\n",
"3\n",
"6\n"
] | [
"12 3\n1 1\n1 1\n1 1\n1 1\n0 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n",
"4 5\n0 5\n-2 4\n3 4\n4 -2\n",
"20 100000\n14309 -32939\n-56855 100340\n151364 25430\n103789 -113141\n147404 -136977\n-37006 -30929\n191679 -49557\n13419 70401\n-88280 165170\n-196399 137941\n-176527 -61904\n46659 115261\n-153551 114185\n9878... | [
"7\n",
"4\n",
"6\n",
"3\n",
"2\n",
"5\n",
"12\n",
"0\n",
"8\n",
"1\n"
] |
CodeContests | Mathematical expressions appearing in old papers and old technical articles are printed with typewriter in several lines, where a fixed-width or monospaced font is required to print characters (digits, symbols and spaces). Let us consider the following mathematical expression.
<image>
It is printed in the following f... | stdin | null | 4,514 | 1 | [
"4\n........4...2..........\n(.1.-.----.)..*.-.5.+.6\n........2..............\n.......3...............\n3\n...3.\n-.---\n...4.\n4\n.3.+.4.*.-.2.\n-------------\n..........2..\n...-.1.-.2...\n2\n...2..3\n(.4..).\n1\n2.+.3.*.5.-.7.+.9\n1\n(.2.+.3.).*.(.5.-.7.).+.9\n3\n.2....3.\n4..+.---\n......5.\n3\n.2......-.-.3.\n... | [
"501\n502\n1\n74\n19\n2010\n821\n821\n1646\n148\n81\n1933\n"
] | [
"4\n........4...2..........\n(.1.-.----.)..*.-.5.+.6\n........2..............\n.......3...............\n3\n...3.\n-.---\n...4.\n4\n.3.+.4.*.-.2.\n-------------\n..........2..\n...-.1.-.2...\n2\n...2..3\n(.4..).\n1\n2.+.3.*.5.-.7.+.9\n1\n(.2.+.3.).*.(.5.-.7.).+.9\n3\n.2....3.\n4..+.---\n......5.\n3\n.2......-.-.3.\n... | [
"501\n502\n1\n74\n19\n2010\n821\n821\n1646\n148\n81\n1933\n",
"501\n502\n1\n74\n19\n2010\n821\n",
"1\n502\n1\n74\n19\n2010\n821\n",
"501\n502\n1\n74\n19\n",
"501\n502\n",
"1793\n502\n",
"501\n502\n1\n74\n19\n2010\n1223\n",
"501\n502\n1\n3\n19\n2010\n821\n",
"229\n502\n",
"501\n"
] |
CodeContests | Anchored Balloon
A balloon placed on the ground is connected to one or more anchors on the ground with ropes. Each rope is long enough to connect the balloon and the anchor. No two ropes cross each other. Figure E-1 shows such a situation.
<image>
Figure E-1: A balloon and ropes on the ground
Now the balloon takes o... | stdin | null | 2,296 | 1 | [
"3\n10 10 20\n10 -10 20\n-10 10 120\n1\n10 10 16\n2\n10 10 20\n10 -10 20\n2\n100 0 101\n-90 0 91\n2\n0 0 53\n30 40 102\n3\n10 10 20\n10 -10 20\n-10 -10 20\n3\n1 5 13\n5 -3 13\n-3 -3 13\n3\n98 97 168\n-82 -80 193\n-99 -96 211\n4\n90 -100 160\n-80 -80 150\n90 80 150\n80 80 245\n4\n85 -90 290\n-80 -80 220\n-85 90 145\... | [
"17.3205081\n16.0000000\n17.3205081\n13.8011200\n53.0000000\n14.1421356\n12.0000000\n128.3928757\n94.1879092\n131.1240816\n4.0000000\n72.2251798\n"
] | [
"3\n10 10 20\n10 -10 20\n-10 10 120\n1\n10 10 16\n2\n10 10 20\n10 -10 20\n2\n100 0 101\n-90 0 91\n2\n0 0 53\n30 40 102\n3\n10 10 20\n10 -10 20\n-10 -10 20\n3\n1 5 13\n5 -3 13\n-3 -2 13\n3\n98 97 168\n-82 -80 193\n-99 -96 211\n4\n90 -100 160\n-80 -80 150\n90 80 150\n80 80 245\n4\n85 -90 290\n-80 -80 220\n-85 90 145\... | [
"17.32050807\n16.00000000\n17.32050807\n13.80112003\n53.00000000\n14.14213562\n12.06348945\n128.39287570\n94.18790921\n131.12408158\n4.00000000\n72.22517983\n",
"17.32050807\n16.00000000\n17.32050807\n13.80112003\n53.00000000\n14.14213562\n12.06348945\n128.39287570\n94.18790921\n131.12408158\n4.00000000\n82.06219... |
CodeContests | A new lord assumed the position by the death of the previous lord in a Far Eastern province.
The new greedy lord hates concave polygons, because he believes they need much wasted area to be drawn on paper. He always wants to modify them to convex ones.
His castle is currently surrounded by a wall forming a concave po... | stdin | null | 3,287 | 1 | [
"5 4\n0 0\n4 0\n4 4\n2 2\n0 4\n8 80\n45 41\n70 31\n86 61\n72 64\n80 79\n40 80\n8 94\n28 22\n0 0\n"
] | [
"case 1: 16.0\ncase 2: 3375.0\n"
] | [
"5 4\n0 0\n4 0\n4 4\n2 1\n0 4\n8 80\n45 41\n70 31\n86 61\n72 64\n80 79\n40 80\n8 94\n28 22\n0 0\n",
"5 4\n0 0\n4 0\n4 4\n0 1\n0 4\n8 80\n53 41\n70 31\n86 61\n72 64\n80 79\n40 80\n8 166\n28 22\n0 0\n",
"5 4\n0 0\n4 0\n4 4\n0 1\n0 4\n8 80\n53 6\n70 31\n86 61\n72 64\n80 79\n40 80\n8 166\n28 22\n0 0\n",
"5 4\n0 0... | [
"case 1: 16.0\ncase 2: 3375.0\n",
"case 1: 16.0\ncase 2: 3807.0\n",
"case 1: 16.0\ncase 2: 4255.5\n",
"case 1: 16.0\ncase 2: 3668.0\n",
"case 1: 16.0\ncase 2: 3532.5\n",
"case 1: 16.0\ncase 2: 3678.0\n",
"case 1: 16.0\ncase 2: 3762.0\n",
"case 1: 16.0\ncase 2: 4511.5\n",
"case 1: 10.0\ncase 2: 3678.... |
CodeContests | Your task is to write a program of a simple dictionary which implements the following instructions:
* insert str: insert a string str in to the dictionary
* find str: if the distionary contains str, then print 'yes', otherwise print 'no'
Notes
Template in C
Constraints
* A string consists of 'A', 'C', 'G', or 'T'
... | stdin | null | 4,994 | 1 | [
"5\ninsert A\ninsert T\ninsert C\nfind G\nfind A\n",
"13\ninsert AAA\ninsert AAC\ninsert AGA\ninsert AGG\ninsert TTT\nfind AAA\nfind CCC\nfind CCC\ninsert CCC\nfind CCC\ninsert T\nfind TTT\nfind T\n"
] | [
"no\nyes\n",
"yes\nno\nno\nyes\nyes\nyes\n"
] | [
"5\ninsert A\ninsert U\ninsert C\nfind G\nfind A\n",
"13\ninsert AAA\ninsert AAC\ninsert AGA\ninsert AGF\ninsert TTT\nfind AAA\nfind CCC\nfind CCC\ninsert CCC\nfind CCC\ninsert T\nfind TTT\nfind T\n",
"5\ninsert B\ninsert T\ninsert C\nfind G\nfind A\n",
"13\ninsert AAA\ninsert AAC\ninsert AGA\ninsert AGG\nins... | [
"no\nyes\n",
"yes\nno\nno\nyes\nyes\nyes\n",
"no\nno\n",
"yes\nno\nno\nno\nyes\nyes\n",
"yes\nno\nno\nyes\nno\nyes\n",
"yes\nno\nno\nyes\nyes\nno\n",
"yes\nno\nno\nyes\nno\nno\n",
"no\nno\nno\nyes\nno\nyes\n",
"no\nno\nno\nyes\nno\nno\n",
"no\nno\nno\nyes\nyes\nyes\n"
] |
CodeContests | Problem:
Black and White are playing a game of chess on a chess board of n X n dimensions. The game is nearing its end. White has his King and a Pawn left. Black has only his King left. So, definitely Black cannot win the game. However, Black can drag the game towards a draw, and, he can do this only if he captures Wh... | stdin | null | 4,177 | 1 | [
"2\n10 6 2 10 2 0\n10 5 2 1 3 0\n\nSAMPLE\n"
] | [
"Draw\nWhite Wins\n"
] | [
"74\n91067775 71255122 18194899 62367436 74115007 1\n99093340 48587865 95435070 67015442 3128293 1\n2922855 1630432 1544104 1232067 1421531 0\n67524517 10766661 66503602 39587680 12998452 1\n8279429 3204235 5988141 6186463 4066341 0\n39710069 1024462 29571981 9933696 23866424 0\n851374 474011 833042 157145 234395 0... | [
"White Wins\nWhite Wins\nWhite Wins\nDraw\nDraw\nDraw\nWhite Wins\nWhite Wins\nDraw\nWhite Wins\nDraw\nDraw\nWhite Wins\nDraw\nWhite Wins\nDraw\nWhite Wins\nDraw\nWhite Wins\nWhite Wins\nDraw\nWhite Wins\nWhite Wins\nWhite Wins\nWhite Wins\nWhite Wins\nDraw\nDraw\nWhite Wins\nWhite Wins\nDraw\nDraw\nWhite Wins\nWhi... |
CodeContests | You were the master craftsman in the stone age, and you devoted your life to carving many varieties of tools out of natural stones. Your works have ever been displayed respectfully in many museums, even in 2006 A.D. However, most people visiting the museums do not spend so much time to look at your works. Seeing the si... | stdin | null | 3,093 | 1 | [
"3\ngu 20 pa 10\nci 20 gu 10\npa 20 ci 10\n2\ntool 20 tool 10\nproduct 1000 tool 10\n8\nfishhook 21 disk 3\nmill 14 axe 7\nboomerang 56 sundial 28\nflint 35 fishhook 5\naxe 35 flint 14\ndisk 42 disk 2\nsundial 14 disk 7\nhammer 28 mill 7\n0\n"
] | [
"40\n30\n113\n"
] | [
"3\ngu 20 pa 10\nci 20 gu 7\npa 20 ci 10\n2\ntool 20 tool 10\nproduct 1000 tool 10\n8\nfishhook 21 disk 3\nmill 14 axe 7\nboomerang 56 sundial 28\nflint 35 fishhook 5\naxe 35 flint 14\ndisk 42 disk 2\nsundial 14 disk 7\nhammer 28 mill 7\n0\n",
"3\ngu 20 pa 10\nci 2... | [
"37\n30\n113\n",
"37\n10\n113\n",
"37\n10\n112\n",
"40\n30\n113\n",
"33\n10\n113\n",
"40\n40\n113\n",
"40\n40\n103\n",
"24\n10\n113\n",
"40\n40\n114\n",
"40\n55\n103\n"
] |
CodeContests | Marut loves good strings. According to him, good strings are those which contain either all alphabets of uppercase or lowercase.
While he is preparing for his exams, he finds many bad strings in his book and wants to convert them to good strings.
But he wants to do this in minimum number of operations.
In one operatio... | stdin | null | 1,079 | 1 | [] | [] | [
"1\nabcc\nabCD\n",
"1\n1021\n",
"1\nbacc\nabCD\n",
"1\n1694\n",
"1\nbacb\nabCD\n",
"1\n1223\n",
"1\nbacb\nabCC\n",
"1\n1735\n",
"1\nbacc\nabCC\n",
"1\n2032\n"
] | [
"0\n",
"Invalid Input\n",
"0\n",
"Invalid Input\n",
"0\n",
"Invalid Input\n",
"0\n",
"Invalid Input\n",
"0\n",
"Invalid Input\n"
] |
CodeContests | Today's Random Number
E869120 You ran a campaign called "Today's Random Numbers" for N days. This is a project to generate a random number once a day and post the value on Twitter.
The "random numbers of the day" on day $ 1, 2, 3, \ dots, N $ were $ A_1, A_2, A_3, \ dots, A_N $, respectively.
E869120 You would be ha... | stdin | null | 4,523 | 1 | [
"5\n8 6 9 1 20\n"
] | [
"2\n"
] | [
"5\n8 0 9 1 20\n",
"5\n10 -2 3 1 0\n",
"5\n3 -2 1 2 4\n",
"5\n1 1 0 0 0\n",
"5\n8 0 11 1 20\n",
"5\n12 0 11 1 20\n",
"5\n15 0 11 1 20\n",
"5\n15 0 21 1 20\n",
"5\n15 0 21 0 20\n",
"5\n15 -1 21 0 20\n"
] | [
"2\n",
"1\n",
"3\n",
"0\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n"
] |
CodeContests | There is a grid of size W × H surrounded by walls. Some cells in the grid are occupied by slimes. The slimes want to unite with each other and become a "King Slime".
In each move, a slime can move to east, west, south and north direction until it enters a cell occupied by another slime or hit the surrounding wall. If ... | stdin | null | 746 | 1 | [
"2 3 3\n2 2\n3 3\n",
"4 3 3\n1 1\n1 3\n3 1\n3 3\n",
"2 4 4\n2 2\n3 3\n",
"2 4 4\n2 2\n2 3\n"
] | [
"2\n",
"3\n",
"3\n",
"1\n"
] | [
"2 3 3\n2 4\n3 3\n",
"4 3 3\n1 1\n0 3\n3 1\n3 3\n",
"2 4 6\n2 2\n2 3\n",
"1 4 4\n2 2\n3 3\n",
"4 3 3\n1 1\n1 3\n6 1\n3 2\n",
"2 4 6\n2 2\n0 3\n",
"4 3 3\n1 1\n1 3\n3 1\n3 6\n",
"4 6 3\n1 1\n0 3\n3 1\n3 3\n",
"2 4 3\n2 2\n2 3\n",
"4 3 3\n1 1\n1 3\n3 1\n3 2\n"
] | [
"2\n",
"3\n",
"1\n",
"0\n",
"4\n",
"3\n",
"3\n",
"3\n",
"1\n",
"3\n"
] |
CodeContests | Big P has become a Physical Education teacher at Hack International School.
Today, the students of class XII have been very undisciplined and he decides to punish them all.
He makes all of the N student (numbered 1 to N ) to stand in a line and asks them to sit down on their knees.
Students know that Big P is a very... | stdin | null | 2,829 | 1 | [
"1\n3 2 1\n1 2\n2 3\n2\n\nSAMPLE\n"
] | [
"2\n"
] | [
"1\n6 2 1\n1 2\n2 3\n2\n\nSAMPLE\n",
"1\n6 2 1\n1 2\n4 3\n2\n\nSAMPLD\n",
"1\n6 2 0\n1 2\n4 3\n2\n\nSAMPLD\n",
"1\n6 2 1\n1 4\n4 2\n1\n\nDLPSAM\n",
"1\n6 2 1\n1 2\n2 3\n2\n\nSAMPLD\n",
"1\n6 2 1\n1 3\n2 3\n2\n\nSAMPLD\n",
"1\n6 2 1\n1 2\n4 3\n2\n\nMASPLD\n",
"1\n3 2 1\n2 2\n2 3\n2\n\nSAMPLE\n",
"1\n... | [
"2\n",
"1\n",
"0\n",
"3\n",
"2\n",
"2\n",
"1\n",
"2\n",
"1\n",
"2\n"
] |
CodeContests | Problem statement
AOR Ika got a cabbage with $ N $ leaves. The leaves of this cabbage are numbered $ 1, \ ldots, N $ in order from the outside, and the dirtiness of the $ i $ th leaf is $ D_i $. The larger this value is, the worse the degree of dirt is. AOR Ika-chan decided to use the cabbage leaves for cooking, so sh... | stdin | null | 4,480 | 1 | [
"5 3 6 9\n9 7 5 3 1\n"
] | [
"2\n"
] | [
"5 3 6 9\n9 1 5 3 1\n",
"21 10 0 4\n5 2 13 -1 0\n",
"21 7 1 4\n0 2 23 -1 2\n",
"9 3 1 9\n22 2 6 2 0\n",
"21 14 1 4\n2 2 0 -1 2\n",
"5 3 6 9\n9 1 6 3 1\n",
"8 3 6 9\n9 1 6 3 1\n",
"8 3 6 9\n15 1 6 3 1\n",
"8 3 6 9\n15 0 6 3 1\n",
"8 3 6 9\n22 0 6 3 1\n"
] | [
"1\n",
"3\n",
"0\n",
"4\n",
"2\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n"
] |
CodeContests | 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 ... | stdin | null | 369 | 1 | [
"2020 530\n",
"2 5\n"
] | [
"823277409\n",
"352\n"
] | [
"3829 530\n",
"3 5\n",
"6 5\n",
"2777 530\n",
"1 5\n",
"4536 530\n",
"3 4\n",
"6 9\n",
"1722 530\n",
"4536 629\n"
] | [
"504838279\n",
"3032\n",
"1145992\n",
"903395601\n",
"32\n",
"684068625\n",
"844\n",
"843174656\n",
"896852858\n",
"649169901\n"
] |
CodeContests | Aizuwakamatsu City is known as the "City of History". About 400 years ago, the skeleton of the castle town was created by Gamo Ujisato, but after that, it became the central city of the Aizu clan 230,000 stones, whose ancestor was Hoshina Masayuki, the half-brother of Tokugawa's third shogun Iemitsu. Developed. Many to... | stdin | null | 3,123 | 1 | [
"4\n4\n0,1,1500\n0,2,2000\n1,2,600\n1,3,500\n0\n"
] | [
"23\n"
] | [
"4\n4\n0,1,1500\n0,2,2000\n1,2,600\n2,3,500\n0\n",
"4\n4\n0,1,1500\n0,2,2000\n1,2,600\n2,3,400\n0\n",
"4\n4\n0,1,0500\n0,2,2000\n0,2,600\n2,3,400\n0\n",
"4\n4\n0,1,0400\n0002,2,0\n0,2,600\n2,3,400\n0\n",
"4\n4\n0,1,1500\n0,2,2000\n1,2,600\n2,3,600\n0\n",
"4\n4\n0,1,0600\n0,2,2000\n0,2,600\n2,3,400\n0\n",
... | [
"23\n",
"22\n",
"12\n",
"11\n",
"24\n",
"13\n",
"37\n",
"10\n",
"29\n",
"32\n"
] |
CodeContests | quiz
You are the director of a quiz show. N people will appear in the quiz show as answerers, each numbered from 1 to N.
Questions will be M + 1 questions, and each question is numbered from 1 to M + 1. Questions are given in numerical order, and points are given only to the person who answers correctly first by pres... | stdin | null | 1,504 | 1 | [
"3 2\n5 2 1 3\n8 2 2 3\n2 3\n8 2 1 2\n3 1 1\n5 1 2\n2 5\n100 1 1\n100 1 1\n100 1 1\n100 1 1\n100 1 1\n3 4\n5 1 1\n5 1 2\n100 2 1 3\n100 2 2 3\n0 0\n"
] | [
"14\n11\n501\n196\n"
] | [
"3 2\n5 2 1 3\n8 2 2 3\n2 3\n8 2 1 2\n3 1 1\n5 1 2\n2 5\n100 1 1\n000 1 1\n100 1 1\n100 1 1\n100 1 1\n3 4\n5 1 1\n5 1 2\n100 2 1 3\n100 2 2 3\n0 0\n",
"3 2\n5 2 1 3\n8 2 2 3\n2 3\n8 2 1 2\n3 1 1\n5 1 2\n2 5\n100 1 1\n000 1 1\n100 1 1\n100 1 1\n100 1 1\n3 4\n5 1 1\n5 1 2\n101 2 1 3\n100 2 2 3\n0 0\n",
"3 2\n5 2 ... | [
"14\n11\n401\n196\n",
"14\n11\n401\n197\n",
"14\n17\n501\n196\n",
"11\n11\n501\n196\n",
"14\n11\n401\n206\n",
"14\n11\n201\n197\n",
"14\n17\n301\n196\n",
"11\n11\n501\n199\n",
"14\n11\n401\n216\n",
"14\n19\n401\n197\n"
] |
CodeContests | Bob loves sorting very much. He is always thinking of new ways to sort an array.His friend Ram gives him a challenging task.He gives Bob an array and an integer K .The challenge is to produce the lexicographical minimal array after at most K-swaps.Only consecutive pairs of elements can be swapped.Help Bob in returning ... | stdin | null | 449 | 1 | [
"2\n3 2\n5 3 1\n5 3\n8 9 11 2 1\n\nSAMPLE\n"
] | [
"1 5 3\n2 8 9 11 1\n"
] | [
"7\n929 320\n25908 624 13924 20094 9600 20729 20932 18348 14154 1502 19845 31067 22191 8352 20405 17322 11359 3061 10689 15785 4412 8975 22688 1214 12324 7201 21838 6984 31242 31776 18812 6787 8268 30663 31878 15276 2368 26077 3237 31845 29456 9914 18534 25178 14537 9480 15450 8741 28078 21447 18703 11631 17106 198... | [
"9 419 624 1502 9600 13924 20094 25908 20729 20932 18348 14154 19845 31067 22191 8352 20405 17322 11359 3061 10689 15785 4412 8975 22688 1214 12324 7201 21838 6984 31242 31776 18812 6787 8268 30663 31878 15276 2368 26077 3237 31845 29456 9914 18534 25178 14537 9480 15450 8741 28078 21447 18703 11631 17106 19859 218... |
CodeContests | Let's think about verbal arithmetic.
The material of this puzzle is a summation of non-negative integers represented in a decimal format, for example, as follows.
905 + 125 = 1030
In verbal arithmetic, every digit appearing in the equation is masked with an alphabetic character. A problem which has the above equa... | stdin | null | 4,239 | 1 | [
"3\nACM\nIBM\nICPC\n3\nGAME\nBEST\nGAMER\n4\nA\nB\nC\nAB\n3\nA\nB\nCD\n3\nONE\nTWO\nTHREE\n3\nTWO\nTHREE\nFIVE\n3\nMOV\nPOP\nDIV\n9\nA\nB\nC\nD\nE\nF\nG\nH\nIJ\n0\n"
] | [
"4\n1\n8\n30\n0\n0\n0\n40320\n"
] | [
"3\nACM\nIBM\nICPC\n3\nGAME\nBEST\nGAMER\n4\nA\nB\nC\nAB\n3\nA\nB\nCD\n3\nONE\nTWO\nTHREE\n3\nTWO\nTHREE\nFIVE\n3\nMOV\nPOP\nDIV\n9\nA\nB\nC\nD\nE\nF\nG\nG\nIJ\n0\n",
"3\nACM\nIBM\nICPC\n3\nGAME\nBEST\nGAMER\n4\nA\nB\nC\nAB\n3\nA\nB\nCD\n3\nONE\nTWO\nTHREE\n3\nTOW\nTHREE\nFIVE\n3\nMOV\nPOP\nDIV\n9\nA\nB\nC\nD\nE\... | [
"4\n1\n8\n30\n0\n0\n0\n32400\n",
"4\n1\n8\n30\n0\n0\n0\n40320\n",
"4\n0\n8\n30\n0\n0\n0\n32400\n",
"4\n0\n1\n30\n0\n0\n0\n32400\n",
"4\n1\n8\n30\n0\n0\n0\n19200\n",
"4\n1\n8\n30\n0\n0\n0\n16512\n",
"4\n1\n8\n30\n0\n0\n0\n5712\n",
"0\n1\n8\n30\n0\n0\n0\n5712\n",
"0\n1\n8\n30\n0\n0\n0\n32400\n",
"4\... |
CodeContests | Problem statement
There is a town with a size of H in the north-south direction and W in the east-west direction. In the town, square plots with a side length of 1 are maintained without gaps, and one house is built in each plot.
A typhoon broke out over a section of the town, causing damage and then changing to an e... | stdin | null | 273 | 1 | [
"7 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\n0 2 2 2 0\n0 1 1 1 0\n0 0 0 0 0\n"
] | [
"4 2 2 2\n"
] | [
"14 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\n0 2 2 2 0\n0 1 1 1 0\n0 0 0 0 0\n",
"10 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\n0 2 2 2 0\n0 1 1 1 0\n0 0 0 0 0\n",
"18 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\n0 2 2 2 0\n0 1 1 1 0\n0 0 0 0 0\n",
"6 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\... | [
"4 2 2 2\n",
"4 2 2 2\n",
"4 2 2 2\n",
"4 2 2 2\n",
"4 2 2 2\n",
"4 2 2 2\n",
"4 2 2 2\n",
"4 2 2 2\n",
"4 2 2 2\n",
"4 2 2 2\n"
] |
CodeContests | King Mercer is the king of ACM kingdom. There are one capital and some cities in his kingdom. Amazingly, there are no roads in the kingdom now. Recently, he planned to construct roads between the capital and the cities, but it turned out that the construction cost of his plan is much higher than expected.
In order to ... | stdin | null | 4,835 | 1 | [
"3 3\n1 2 1 2\n2 3 2 1\n3 1 3 2\n5 5\n1 2 2 2\n2 3 1 1\n1 4 1 1\n4 5 1 1\n5 3 1 1\n5 10\n1 2 32 10\n1 3 43 43\n1 4 12 52\n1 5 84 23\n2 3 58 42\n2 4 86 99\n2 5 57 83\n3 4 11 32\n3 5 75 21\n4 5 23 43\n5 10\n1 2 1 53\n1 3 1 65\n1 4 1 24\n1 5 1 76\n2 3 1 19\n2 4 1 46\n2 5 1 25\n3 4 1 13\n3 5 1 65\n4 5 1 34\n0 0\n"
] | [
"3\n5\n137\n218\n"
] | [
"3 3\n1 2 1 2\n2 3 2 1\n3 1 3 2\n5 5\n1 2 2 2\n2 3 1 1\n1 4 1 1\n4 5 1 1\n5 3 1 1\n5 10\n1 2 32 10\n1 3 43 43\n1 4 12 52\n1 5 84 23\n2 3 58 42\n2 4 86 99\n2 5 57 83\n3 4 11 32\n3 5 75 21\n4 5 23 43\n5 10\n1 2 1 53\n1 3 1 65\n1 4 1 24\n1 5 1 76\n2 3 2 19\n2 4 1 46\n2 5 1 25\n3 4 1 13\n3 5 1 65\n4 5 1 34\n0 0\n",
"... | [
"3\n5\n137\n218\n",
"3\n5\n162\n218\n",
"3\n5\n162\n207\n",
"4\n5\n137\n218\n",
"3\n5\n162\n190\n",
"3\n6\n162\n207\n",
"5\n5\n162\n207\n",
"3\n6\n168\n207\n",
"3\n5\n162\n173\n",
"6\n5\n162\n207\n"
] |
CodeContests | You are given a grid of N rows and M columns. The square at the i-th row and j-th column will be denoted as (i,j). Some of the squares contain an object. All the remaining squares are empty. The state of the grid is represented by strings S_1,S_2,\cdots,S_N. The square (i,j) contains an object if S_{i,j}= `#` and is em... | stdin | null | 2,201 | 1 | [
"3 3\n#..\n..#\n...\n",
"3 3\n..\n..#\n...\n"
] | [
"3\n#><\nvv#\n^^.\n",
"3\n><\nvv#\n^^.\n"
] | [
"4 3\n#..\n..#\n...\n",
"3 5\n..\n..#\n...\n",
"4 3\n#..\n.#.\n...\n",
"4 3\n#..\n.#.\n../\n",
"3 1\n#..\n..#\n...\n",
"3 1\n..#\n..#\n...\n",
"3 1\n..$\n..#\n...\n",
"6 13\n..\n..#\n...\n",
"6 13\n..\n..#\n../\n",
"6 3\n#..\n..#\n...\n"
] | [
"3\n#><\nvv#\n^^.\n",
"3\nvv\n^^#\n><.\n",
"3\n#><\nv#v\n^.^\n",
"2\n#><\nv#.\n^./\n",
"1\n#..\nv.#\n^..\n",
"1\nv.#\n^.#\n...\n",
"1\nv.$\n^.#\n...\n",
"3\nvv\n^^#\n><.\n",
"3\nvv\n^^#\n></\n",
"3\n#><\nvv#\n^^.\n"
] |
CodeContests | You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the follo... | stdin | null | 2,085 | 1 | [
"25\n",
"30\n"
] | [
"No\n",
"Yes\n"
] | [
"20\n",
"44\n",
"37\n",
"78\n",
"47\n",
"91\n",
"61\n",
"26\n",
"35\n",
"23\n"
] | [
"No\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"Yes\n",
"No\n"
] |
CodeContests | There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be a... | stdin | null | 4,746 | 1 | [
"6\n",
"11\n",
"2\n"
] | [
"3\n",
"5\n",
"2\n"
] | [
"12\n",
"4\n",
"19\n",
"24\n",
"10\n",
"1\n",
"3\n",
"40\n",
"50\n",
"29\n"
] | [
"5\n",
"3\n",
"6\n",
"7\n",
"4\n",
"1\n",
"2\n",
"9\n",
"10\n",
"8\n"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.