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 are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order.
Constraints
* 1 \leq N \leq 500,000
* 1 \leq M \leq 500,000
* 0 \leq a_i,... | stdin | null | 2,281 | 1 | [
"6 7\n1 4\n5 2\n3 0\n5 5\n4 1\n0 3\n4 2\n"
] | [
"4\n1 5\n2 4 1\n1 2\n2 3 0\n"
] | [
"6 7\n0 4\n5 2\n3 0\n5 5\n4 1\n0 3\n4 2\n",
"6 7\n1 4\n5 2\n5 0\n5 5\n4 1\n0 3\n4 2\n",
"6 7\n0 4\n5 2\n3 0\n5 5\n0 1\n0 3\n4 2\n",
"6 5\n0 4\n5 2\n3 0\n5 5\n0 1\n0 3\n4 2\n",
"6 7\n1 5\n5 2\n3 0\n5 5\n4 1\n0 3\n4 2\n",
"6 7\n0 4\n5 2\n5 0\n5 5\n4 1\n0 3\n4 2\n",
"6 7\n1 1\n5 2\n5 0\n5 5\n4 1\n0 3\n4 2\... | [
"5\n1 5 \n2 0 3 \n1 4 \n1 2 \n1 1\n",
"5\n1 5 \n2 1 4 \n1 2 \n1 0 \n1 3\n",
"5\n1 5 \n2 0 3 \n1 1 \n1 4 \n1 2\n",
"6\n1 5 \n1 3 \n1 2 \n1 0 \n1 1 \n1 4\n",
"5\n1 4 \n1 1 \n1 5 \n1 2 \n2 0 3\n",
"6\n1 5 \n1 0 \n1 3 \n1 4 \n1 2 \n1 1\n",
"6\n1 5 \n1 4 \n1 2 \n1 1 \n1 0 \n1 3\n",
"5\n1 5 \n1 4 \n2 0 3 \n... |
CodeContests | problem
In one river, there is a slightly dangerous game of jumping from one shore to the other on a stone.
<image>
Now, as shown in Figure 4-1 we consider the stone to be above the squares. The number of rows is n. In Figure 4-1 we have n = 5.
In this game, you start with one shore and make a normal jump or a on... | stdin | null | 3,643 | 1 | [
"5 1\n2 1 3 2 2\n1 3 2\n1 1 7\n1 2 1\n1 4 4\n5 0\n2 1 3 2 2\n1 3 2\n1 1 7\n1 2 1\n1 4 4\n0 0\n"
] | [
"17\n40\n"
] | [
"5 1\n2 1 3 2 2\n1 3 2\n1 1 7\n1 2 1\n1 4 4\n5 0\n2 1 3 0 2\n1 3 2\n1 1 7\n1 2 1\n1 4 4\n0 0\n",
"5 1\n2 1 3 2 2\n1 3 2\n1 1 7\n1 2 1\n1 4 4\n5 0\n2 1 3 2 2\n1 4 2\n1 1 7\n1 2 1\n1 4 4\n0 0\n",
"5 1\n2 1 3 2 2\n1 3 2\n1 1 7\n1 2 1\n1 4 4\n5 0\n2 1 3 0 2\n1 3 2\n1 1 1\n1 2 1\n1 4 4\n0 0\n",
"5 1\n2 1 4 2 2\n1 ... | [
"17\n46\n",
"17\n53\n",
"17\n28\n",
"17\n23\n",
"15\n23\n",
"18\n40\n",
"27\n46\n",
"18\n53\n",
"17\n32\n",
"37\n23\n"
] |
CodeContests | From the FAQ:
What am I allowed to post as a comment for a problem?
Do NOT post code.
Do NOT post a comment asking why your solution is wrong.
Do NOT post a comment asking if you can be given the test case your program fails on.
Do NOT post a comment asking how your solution can be improved.
Do NOT post a comment g... | stdin | null | 3,336 | 1 | [
"7\n1\n?\n2\n?0\n10\n79259?087\n2\n??\n3\n0?1\n4\n?????\n3\n012\n"
] | [
"0\n10\nNO\n01\n021\n01012\n012\n"
] | [
"7\n1\n?\n2\n?0\n10\n79259?087\n2\n??\n3\n0?1\n4\n?????\n3\n13\n",
"7\n1\n?\n2\n?0\n10\n79259?087\n2\n??\n3\n0?1\n4\n?????\n3\n0\n",
"7\n1\n?\n2\n?0\n10\n79259?087\n2\n??\n2\n0?1\n4\n?????\n3\n13\n",
"7\n1\n?\n2\n?0\n10\n79259?087\n2\n??\n2\n0?1\n4\n?????\n3\n0\n",
"7\n1\n?\n2\n?0\n10\n79259?087\n2\n??\n2\n... | [
"0\n10\nNO\n01\n021\n01012\n13\n",
"0\n10\nNO\n01\n021\n01012\n0\n",
"0\n10\nNO\n01\nNO\n01012\n13\n",
"0\n10\nNO\n01\nNO\n01012\n0\n",
"0\n10\nNO\n01\nNO\n01012\nNO\n",
"0\n10\nNO\n01\nNO\n01012\n1\n",
"0\nNO\nNO\n01\n021\n01012\n012\n",
"0\n10\nNO\n01\n0>1\n01012\n13\n",
"0\n10\nNO\n01\n021\n01012... |
CodeContests | For a rooted tree, find the lowest common ancestor of two nodes u and v.
The given tree consists of n nodes and every node has a unique ID from 0 to n-1 where 0 is the root.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
Input
n
k0 c1 c2 ... ck0
k1 c1 c2 ... ck1
:
kn-1 c1 c2 ... ckn-1
q
u1 v1
u2 v2
:
uq vq
The f... | stdin | null | 4,685 | 1 | [
"8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n4 6\n4 7\n4 3\n5 2\n"
] | [
"1\n1\n0\n0\n"
] | [
"8\n3 1 2 3\n2 4 5\n0\n0\n-1\n2 6 7\n0\n0\n4\n4 6\n4 7\n4 3\n5 2\n",
"8\n3 1 2 3\n2 4 5\n0\n0\n-2\n2 6 7\n0\n0\n4\n4 6\n4 7\n4 3\n5 1\n",
"8\n3 1 2 3\n2 4 5\n0\n0\n-2\n2 6 7\n0\n0\n4\n4 6\n4 7\n4 4\n5 2\n",
"8\n3 1 2 3\n2 4 5\n0\n0\n-2\n2 6 7\n0\n0\n4\n4 6\n3 7\n4 3\n5 1\n",
"8\n3 1 2 3\n2 4 5\n0\n0\n-2\n2 ... | [
"1\n1\n0\n0\n",
"1\n1\n0\n1\n",
"1\n1\n4\n0\n",
"1\n0\n0\n1\n",
"1\n1\n",
"1\n0\n0\n0\n",
"0\n1\n0\n0\n",
"5\n1\n0\n0\n",
"1\n1\n0\n3\n",
"6\n1\n0\n0\n"
] |
CodeContests | Masa Kita, who entered the University of Tokyo, joined a circle called TSG (University of Tokyo Super Gamers).
This circle exhibits games at the Komaba Festival every year, and Masa Kita decided to create and display the games as well.
The game created by Kitamasa is a common falling block puzzle game such as the fol... | stdin | null | 4,597 | 1 | [
"3\n......\n......\n......\n......\n......\n......\n......\n......\n.RGB..\nRGOP..\nRGBPB.\nRGBPP.\nGBRGYP\nGBRRYP\nBGGRBB\nBPRGYY\nGGPRRY\nBYPPRB\nYGGGPB\nGYYYPR\nYRBRBR\nYBRBRB\nBRBRBR\nBRBRBR\n......\n......\n......\n......\n......\n......\n......\n......\n......\n......\n..OO..\n..OO..\n"
] | [
"3\n18\n0\n"
] | [
"3\n......\n......\n......\n......\n......\n......\n......\n......\n.RGB..\nRGOP..\nRGBPB.\nRGBPP.\nGBRGYP\nGBRRYP\nBGGRBB\nBPRGYY\nGGPRRY\nBYPPRB\nYGGGPB\nRPYYYG\nYRBRBR\nYBRBRB\nBRBRBR\nBRBRBR\n......\n......\n......\n......\n......\n......\n......\n......\n......\n......\n..OO..\n..OO..\n",
"3\n......\n......\... | [
"3\n8\n0\n",
"3\n18\n0\n",
"3\n5\n0\n",
"3\n0\n0\n",
"3\n2\n0\n",
"3\n3\n0\n",
"2\n5\n0\n",
"3\n1\n0\n",
"3\n4\n0\n",
"0\n1\n0\n"
] |
CodeContests | A museum exhibits N jewels, Jewel 1, 2, ..., N. The coordinates of Jewel i are (x_i, y_i) (the museum can be regarded as a two-dimensional plane), and the value of that jewel is v_i.
Snuke the thief will steal some of these jewels.
There are M conditions, Condition 1, 2, ..., M, that must be met when stealing jewels,... | stdin | null | 3,954 | 1 | [
"10\n66 47 71040136000\n65 77 74799603000\n80 53 91192869000\n24 34 24931901000\n91 78 49867703000\n68 71 46108236000\n46 73 74799603000\n56 63 93122668000\n32 51 71030136000\n51 26 70912345000\n21\nL 51 1\nL 7 0\nU 47 4\nR 92 0\nR 91 1\nD 53 2\nR 65 3\nD 13 0\nU 63 3\nL 68 3\nD 47 1\nL 91 5\nR 32 4\nL 66 2\nL 80 4... | [
"305223377000\n",
"0\n",
"13\n",
"36\n"
] | [
"10\n66 47 71040136000\n65 55 74799603000\n80 53 91192869000\n24 34 24931901000\n91 78 49867703000\n68 71 46108236000\n46 73 74799603000\n56 63 93122668000\n32 51 71030136000\n51 26 70912345000\n21\nL 51 1\nL 7 0\nU 47 4\nR 92 0\nR 91 1\nD 53 2\nR 65 3\nD 13 0\nU 63 3\nL 68 3\nD 47 1\nL 91 5\nR 32 4\nL 66 2\nL 80 4... | [
"308982843000\n",
"37\n",
"184315537000\n",
"308557794736\n",
"13\n",
"10\n",
"301870369587\n",
"0\n",
"32\n",
"234183240000\n"
] |
CodeContests | N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The struct... | stdin | null | 3,160 | 1 | [
"7\n1\n2\n1\n3\n1\n4\n",
"4\n4\n4\n1\n",
"5\n1\n1\n2\n4\n"
] | [
"3\n",
"3\n",
"3\n"
] | [
"7\n1\n2\n2\n3\n1\n4\n",
"5\n1\n1\n1\n4\n",
"5\n1\n0\n1\n3\n",
"7\n1\n4\n2\n3\n1\n3\n",
"5\n0\n0\n1\n3\n",
"4\n3\n4\n0\n",
"7\n1\n4\n2\n3\n1\n4\n",
"5\n1\n1\n1\n3\n",
"7\n1\n4\n2\n3\n1\n7\n",
"7\n1\n2\n1\n3\n1\n0\n"
] | [
"4\n",
"3\n",
"2\n",
"5\n",
"1\n",
"0\n",
"4\n",
"3\n",
"4\n",
"3\n"
] |
CodeContests | You are given an integer sequence x of length N. Determine if there exists an integer sequence a that satisfies all of the following conditions, and if it exists, construct an instance of a.
* a is N^2 in length, containing N copies of each of the integers 1, 2, ..., N.
* For each 1 ≤ i ≤ N, the i-th occurrence of the... | stdin | null | 3,238 | 1 | [
"2\n4 1\n",
"3\n1 5 9\n"
] | [
"No\n",
"Yes\n1 1 1 2 2 2 3 3 3\n"
] | [
"2\n4 2\n",
"2\n3 2\n",
"3\n1 5 7\n",
"2\n1 3\n",
"3\n1 7 9\n",
"2\n1 4\n",
"2\n2 4\n",
"2\n2 3\n",
"3\n1 8 7\n",
"3\n1 3 7\n"
] | [
"No\n",
"Yes\n2 2 1 1\n",
"Yes\n1 2 3 3 2 1 3 1 2\n",
"Yes\n1 2 2 1\n",
"Yes\n1 2 3 3 1 1 2 2 3\n",
"Yes\n1 2 1 2\n",
"Yes\n2 1 1 2\n",
"Yes\n2 1 2 1\n",
"Yes\n1 3 3 2 1 1 3 2 2\n",
"Yes\n1 2 2 3 3 1 3 1 2\n"
] |
CodeContests | Caesar Cipher is one of the earliest and simplest encryption technique.
To encrypt a message, we shift the alphabets of the message by a fixed position or key.
For example, if message is ABC , and we shift each character by 3 characters, we will get DEF. Here key is 3.
Given a message and key , compute its Caesar C... | stdin | null | 1,754 | 1 | [
"3\n2\nx\n3\noXyh\n2\nnn\n\nSAMPLE\n"
] | [
"z\nrAbk\npp\n"
] | [
"3\n2\nx\n3\noXyh\n4\nnn\n\nSAMPLE\n",
"3\n2\nx\n3\noXyh\n4\nmn\n\nSAMPLE\n",
"3\n2\nx\n3\noXyh\n1\nmn\n\nSAMPLE\n",
"3\n2\nx\n3\noXxh\n1\nmn\n\nSAMPLE\n",
"3\n2\nx\n3\noXxh\n0\nmn\n\nSAMPLE\n",
"3\n2\nx\n3\noYxh\n0\nmn\n\nSAMPLE\n",
"3\n2\nx\n3\noYxh\n1\nmn\n\nSAMPLE\n",
"3\n3\nx\n3\noYxh\n1\nmn\n\nS... | [
"z\nrAbk\nrr\n",
"z\nrAbk\nqr\n",
"z\nrAbk\nno\n",
"z\nrAak\nno\n",
"z\nrAak\nmn\n",
"z\nrBak\nmn\n",
"z\nrBak\nno\n",
"a\nrBak\nno\n",
"c\nrBak\nno\n",
"w\nrBak\nno\n"
] |
CodeContests | Kate has finally calmed down and decides to forgive Little Deepu, but she won't forgive him just like that. She agrees to forgive him on the grounds that he can solve a mathematical question for her.
She gives Deepu a large number N and a prime number P and asks him to calculate ((3*N)! / (3!^N) )%P.Your task is to he... | stdin | null | 1,915 | 1 | [
"2\n3 11\n2 11\n\nSAMPLE\n"
] | [
"8\n9\n"
] | [
"2\n3 11\n2 11\n\nSALPLE\n",
"2\n3 11\n2 2\n\nSALPLE\n",
"2\n3 13\n2 11\n\nSALPLE\n",
"2\n3 11\n2 7\n\nSAMPME\n",
"2\n4 13\n2 11\n\nSALPLE\n",
"2\n3 11\n2 13\n\nSAMPME\n",
"2\n0 11\n2 13\n\nSAMPME\n",
"2\n1 11\n2 11\n\nSAMPLE\n",
"2\n5 11\n2 11\n\nSALPLE\n",
"2\n1 11\n2 2\n\nSALPLE\n"
] | [
"8\n9\n",
"8\n0\n",
"3\n9\n",
"8\n6\n",
"10\n9\n",
"8\n7\n",
"1\n7\n",
"1\n9\n",
"0\n9\n",
"1\n0\n"
] |
CodeContests | Taro is playing with a puzzle that places numbers 1-9 in 9x9 squares. In this puzzle, you have to arrange the numbers according to the following rules.
* One number appears exactly once in the same column
* A number appears exactly once on the same line
* In each of the 3x3 ranges separated by double lines, a number a... | stdin | null | 1,614 | 1 | [
"2\n2 1 3 4 5 6 7 8 9\n4 5 6 7 8 9 1 2 3\n7 8 9 1 2 3 4 5 6\n2 3 4 5 6 7 8 9 1\n5 6 7 8 9 1 2 3 4\n8 9 1 2 3 4 5 6 7\n3 4 5 6 7 8 9 1 2\n6 7 8 9 1 2 3 4 5\n9 1 2 3 4 5 6 7 8\n2 1 3 4 5 6 7 8 9\n4 5 6 7 8 9 1 2 3\n7 8 9 1 2 3 4 5 6\n2 3 4 5 6 7 8 9 1\n5 6 7 8 9 1 2 3 4\n8 9 1 2 3 4 5 6 7\n3 4 5 6 7 8 9 1 2\n6 7 8 9 ... | [
"*2*1 3 4 5 6 7 8 9\n 4 5 6 7 8 9 1 2 3\n 7 8 9 1 2 3 4 5 6\n*2 3 4 5 6 7 8 9 1\n 5 6 7 8 9 1 2 3 4\n 8 9 1 2 3 4 5 6 7\n 3 4 5 6 7 8 9 1 2\n 6 7 8 9 1 2 3 4 5\n 9*1 2 3 4 5 6 7 8\n\n*2*1 3 4 5 6 7 8 9\n 4 5 6 7 8 9 1 2 3\n 7 8 9 1 2 3 4 5 6\n*2 3 4 5 6 7 8 9 1\n 5 6 7 8 9 1 2 3 4\n 8 9 1 2 3 4 5 6 7\n 3 4 5 6 7 8 ... | [
"2\n2 1 3 4 5 6 7 8 9\n4 5 6 7 8 9 1 2 3\n7 8 9 1 2 3 4 5 6\n2 3 4 5 6 7 8 9 1\n5 6 7 8 9 0 2 3 4\n8 9 1 2 3 4 5 6 7\n3 4 5 6 7 8 9 1 2\n6 7 8 9 1 2 3 4 5\n9 1 2 3 4 5 6 7 8\n2 1 3 4 5 6 7 8 9\n4 5 6 7 8 9 1 2 3\n7 8 9 1 2 3 4 5 6\n2 3 4 5 6 7 8 9 1\n5 6 7 8 9 1 2 3 4\n8 9 1 2 3 4 5 6 7\n3 4 5 6 7 8 9 1 2\n6 7 8 9 ... | [
"*2*1 3 4 5 6 7 8 9\n 4 5 6 7 8 9 1 2 3\n 7 8 9 1 2 3 4 5 6\n*2 3 4 5 6 7 8 9 1\n 5 6 7 8 9 0 2 3 4\n 8 9 1 2 3 4 5 6 7\n 3 4 5 6 7 8 9 1 2\n 6 7 8 9 1 2 3 4 5\n 9*1 2 3 4 5 6 7 8\n\n*2*1 3 4 5 6 7 8 9\n 4 5 6 7 8 9 1 2 3\n 7 8 9 1 2 3 4 5 6\n*2 3 4 5 6 7 8 9 1\n 5 6 7 8 9 1 2 3 4\n 8 9 1 2 3 4 5 6 7\n 3 4 5 6 7 8 ... |
CodeContests | For an n \times n grid, let (r, c) denote the square at the (r+1)-th row from the top and the (c+1)-th column from the left. A good coloring of this grid using K colors is a coloring that satisfies the following:
* Each square is painted in one of the K colors.
* Each of the K colors is used for some squares.
* Let us... | stdin | null | 4,189 | 1 | [
"9\n",
"2\n"
] | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"3\n1 1 1\n1 1 1\n2 2 2\n"
] | [
"4\n",
"0\n",
"7\n",
"3\n",
"6\n",
"10\n",
"8\n",
"19\n",
"5\n",
"13\n"
] | [
"2\n1 2 \n4 3\n",
"0\n",
"4\n1 2 3 4 \n6 7 4 5 \n3 4 1 2 \n4 5 6 7\n",
"2\n1 2 \n2 3\n",
"4\n1 2 3 4 \n6 3 4 5 \n3 4 1 2 \n4 5 6 3\n",
"6\n1 2 3 4 5 6 \n8 9 10 5 6 7 \n3 4 5 6 1 2 \n10 5 6 7 8 9 \n5 6 1 2 3 4 \n6 7 8 9 10 5\n",
"4\n1 2 3 4 \n6 7 8 5 \n3 4 1 2 \n8 5 6 7\n",
"10\n1 2 3 4 5 6 7 8 9 10 \n... |
CodeContests | In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to ... | stdin | null | 3,557 | 1 | [
"8 10\n",
"3 7\n",
"123456 234567\n",
"8 3\n",
"2 4\n"
] | [
"46\n",
"57\n",
"857617983\n",
"0\n",
"7\n"
] | [
"8 5\n",
"0 7\n",
"25732 234567\n",
"0 5\n",
"3 4\n",
"0 11\n",
"29001 234567\n",
"4 7\n",
"2 5\n",
"4 8\n"
] | [
"0\n",
"64\n",
"80550073\n",
"16\n",
"4\n",
"1024\n",
"246712986\n",
"42\n",
"15\n",
"99\n"
] |
CodeContests | Snuke is introducing a robot arm with the following properties to his factory:
* The robot arm consists of m sections and m+1 joints. The sections are numbered 1, 2, ..., m, and the joints are numbered 0, 1, ..., m. Section i connects Joint i-1 and Joint i. The length of Section i is d_i.
* For each section, its mode ... | stdin | null | 3,955 | 1 | [
"2\n1 1\n1 1\n",
"5\n0 0\n1 0\n2 0\n3 0\n4 0\n",
"3\n-7 -3\n7 3\n-3 -7\n",
"3\n-1 0\n0 3\n2 -1\n"
] | [
"2\n1 1\nRU\nUR\n",
"-1\n",
"5\n3 1 4 1 5\nLRDUL\nRDULR\nDULRD\n",
"2\n1 2\nRL\nUU\nDR\n"
] | [
"2\n2 1\n1 1\n",
"2\n2 1\n1 0\n",
"3\n-8 -4\n7 3\n-3 -7\n",
"3\n-8 -4\n13 3\n-3 -7\n",
"3\n0 0\n0 0\n2 0\n",
"2\n2 2\n1 -1\n",
"3\n0 0\n0 0\n4 0\n",
"2\n2 1\n2 -1\n",
"3\n1 -1\n0 0\n4 0\n",
"2\n0 1\n2 -1\n"
] | [
"-1\n",
"31\n1073741824 536870912 268435456 134217728 67108864 33554432 16777216 8388608 4194304 2097152 1048576 524288 262144 131072 65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1\nRLLLLLLLLLLLLLLLLLLLLLLLLLLLLLU\nRLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\n",
"32\n1 1073741824 536870912 268435456 134... |
CodeContests | Ferb purchased some colors to decorate his backyard fence. The fence is big (it has to be, as the backyard once hosted a circus, and a roller coaster ride !) and he had to buy multiple boxes of same color. He has a design in mind to paint, its simple and colorful too.
Ferb is planning to color every wood of the fence ... | stdin | null | 2,870 | 1 | [
"2\n5\n1 3 1 3 1\n6\n1 3 1 3 1 1\n\nSAMPLE\n"
] | [
"can do\nbad luck\n"
] | [
"5\n1\n666\n4\n1 2 1 3\n10\n1 2 3 4 5 6 7 8 9 10\n50\n1 4 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10\n20\n1 2 1 3 1 2 1 3 1 2 1 3 1 2 1 1 1 1 2 2\n",
"6\n5\n1 3 1 3 1\n6\n1 3 1 3 1 1\n100\n1 3 1 3 1 1 3 1 3 1 1 3 1 3 1 1 3 1 3 1 1 3 1 3 1... | [
"can do\ncan do\ncan do\ncan do\nbad luck\n",
"can do\nbad luck\nbad luck\nbad luck\ncan do\nbad luck\n",
"can do\nbad luck\n",
"can do\ncan do\ncan do\ncan do\nbad luck\n",
"can do\nbad luck\nbad luck\nbad luck\ncan do\nbad luck\n",
"can do\nbad luck\nbad luck\nbad luck\ncan do\nbad luck\n",
"can do\nb... |
CodeContests | Shil has an array of N elements A1 , A2, ... ,AN . He also has an integer K. He wants to find out value of Square Sum for every i from 1 to N-K+1.
The value of Square Sum for certain i is defined as Σ1≤ j ≤ K (j^2 Ai+j-1).
Input:
First line of input consists of two integers N and K. Next line consists of N integers A... | stdin | null | 2,992 | 1 | [
"6 3\n6 9 10 10 4 6 \n\nSAMPLE\n"
] | [
"132 139 86 80\n"
] | [
"1000 20\n4 7 6 6 9 4 6 2 6 2 7 7 6 2 4 4 3 6 8 8 10 10 1 4 8 1 9 3 3 10 3 6 9 6 8 5 2 7 4 10 4 5 4 10 10 2 3 10 3 2 7 3 1 9 5 2 4 4 8 5 3 3 10 5 1 2 4 7 6 5 4 7 9 10 4 5 4 2 9 7 5 6 2 9 4 9 2 10 5 1 3 6 2 4 7 1 10 3 9 2 6 3 9 8 6 1 10 5 6 8 7 8 2 3 3 9 7 1 1 2 10 8 9 10 3 4 6 1 5 9 8 2 6 4 10 10 10 7 5 10 7 4 7 4 ... | [
"15743 17604 19285 17195 16492 17449 15503 16930 15810 14787 16659 15551 15747 17122 17158 17982 17522 15903 16445 15748 17529 16746 16435 15745 17514 19111 17344 16136 17842 16583 15046 15663 14630 12908 14566 14479 13207 12864 12569 13921 13961 13208 12536 14742 14750 13161 12121 11981 13062 13642 13761 13465 143... |
CodeContests | Given a string S of length N consisting of only lower-case English alphabets, you will be asked to process Q queries over it . In each query you will be given two lower case characters X and Y. Your task is to find out the number of such substrings of the the string S which have the characters X and Y on either of its... | stdin | null | 2,944 | 1 | [
"5\naacbb\n2\na c\na b\n\nSAMPLE\n"
] | [
"2\n4\n"
] | [
"5\naacbb\n2\nb c\na b\n\nSAMPLE\n",
"5\naacbb\n2\na b\na b\n\nSAMPLE\n",
"5\naacbb\n2\nb c\na c\n\nSEMPLA\n",
"5\naacbb\n2\na a\na b\n\nELOLAS\n",
"5\naacbc\n2\na c\na b\n\nSAMPLE\n",
"5\naacbb\n2\nc c\na b\n\nSEMPLA\n",
"5\naacba\n2\nb c\na b\n\nSAMPLE\n",
"5\naacbb\n2\nb d\na c\n\nSEMPLA\n",
"5\n... | [
"2\n4\n",
"4\n4\n",
"2\n2\n",
"1\n4\n",
"4\n2\n",
"0\n4\n",
"1\n3\n",
"0\n2\n",
"1\n1\n",
"1\n"
] |
CodeContests | Consider a sequence of n numbers using integers from 0 to 9 k1, k2, ..., kn. Read the positive integers n and s,
k1 + 2 x k2 + 3 x k3 + ... + n x kn = s
Create a program that outputs how many rows of n numbers such as. However, the same number does not appear more than once in one "n sequence of numbers".
Input
T... | stdin | null | 1,251 | 1 | [
"3 10\n3 1\n"
] | [
"8\n0\n"
] | [
"4 10\n3 1\n",
"6 10\n3 1\n",
"2 14\n3 1\n",
"2 25\n10 0\n",
"2 4\n10 0\n",
"3 10\n0 1\n",
"3 14\n10 3\n",
"3 10\n2 1\n",
"2 9\n3 1\n",
"2 14\n2 1\n"
] | [
"1\n0\n",
"0\n0\n",
"5\n0\n",
"2\n0\n",
"3\n0\n",
"8\n0\n",
"14\n0\n",
"8\n1\n",
"4\n0\n",
"5\n1\n"
] |
CodeContests | ICPC World Finals Day 6
Russian Constructivism is an art movement in the Soviet Union that began in the mid-1910s. Inspired by such things, Tee, who had been in Country R for a long time, decided to create a cool design despite the rehearsal of the ICPC World Finals. Mr. Tee says: "A circle and a line segment are enou... | stdin | null | 826 | 1 | [
"n k\na\n"
] | [
"2\n"
] | [
"o k\na\n",
"m k\na\n",
"n k\n`\n",
"o k\n`\n",
"o j\n`\n",
"p j\n`\n",
"p i\n`\n",
"p i\na\n",
"o i\na\n",
"p j\na\n"
] | [
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n"
] |
CodeContests | This problem of Oz is very straight forward. You are given N distinct prime integers i.e p1, p2,..., pN and an interval [L,R]. Calculate number of integers in this interval that are divisible by at least one of the given primes.
Input :
First line of input contain an integer T — the number of test cases. T tests foll... | stdin | null | 2,832 | 1 | [
"2\n1 1 10\n3\n2 1 10\n2 3\n\nSAMPLE\n"
] | [
"3\n7\n"
] | [
"10\n1 1 1000000000000000000\n3\n1 1000000000000000000 1000000000000000000\n3\n10 1 1000000000000000000\n3 2 7 5 13 11 19 17 29 23\n5 42 18509\n97 67 13 31 83\n5 26501 45670\n89 61 11 83 53\n3 11479 40837\n83 42 11\n1 24465 30170\n37\n2 23282 40109\n43 41\n3 492 3487\n47 37 7\n2 4828 10264\n61 17\n",
"2\n1 1 10\n... | [
"333333333333333333\n0\n842052776898047765\n2580\n2738\n3619\n154\n793\n550\n404\n",
"10\n7\n",
"333333333333333333\n0\n842052776898047765\n2580\n2738\n3619\n154\n793\n538\n404\n",
"333333333333333333\n0\n842052776898047765\n2580\n3509\n3619\n154\n793\n538\n404\n",
"333333333333333333\n0\n842052776898047765... |
CodeContests | Given the value of n, print the n'th prime number.
Input : A single integer n.
Output : A single number which is the n'th prime number.
Constraints :
1 ≤ n ≤ 1000
SAMPLE INPUT
2
SAMPLE OUTPUT
3
Explanation
The first few prime numbers are:
2,3,5,7. So, the answer is 3. | stdin | null | 165 | 1 | [
"2\n\nSAMPLE\n"
] | [
"3\n"
] | [
"2\n\nSBMPLE\n",
"2\n\nSBPMLE\n",
"2\n\nELMPBS\n",
"2\n\nELMPAS\n",
"2\n\nSAPMLE\n",
"2\n\nSAQMLE\n",
"2\n\nELMQAS\n",
"2\n\nELMQBS\n",
"2\n\nELLQBS\n",
"2\n\nEMLQBS\n"
] | [
"3\n",
"3\n",
"3\n",
"3\n",
"3\n",
"3\n",
"3\n",
"3\n",
"3\n",
"3\n"
] |
CodeContests | Karakuri Doll
Karakuri doll
English text is not available in this practice contest.
After many years of research, Karakuri puppeteer JAG has succeeded in developing a wonderful tea-drawing doll that combines traditional and latest techniques. This tea-drawing doll is placed in a teacup with tea in the kitchen (K) in... | stdin | null | 1,102 | 1 | [
"5 3\n#####\n#K.M#\n#####\n9 5\n#########\n#.....###\n#.###..M#\n#K#######\n#########\n9 5\n#########\n#K......#\n####.####\n####M####\n#########\n9 5\n#########\n#M......#\n####.####\n####K####\n#########\n7 9\n#######\n#####M#\n#####.#\n#.....#\n#.###.#\n#.....#\n#.#####\n#K#####\n#######\n7 6\n#######\n#####.#\n... | [
"He can accomplish his mission.\nHe can accomplish his mission.\nHe cannot bring tea to his master.\nHe cannot return to the kitchen.\nHe can accomplish his mission.\nHe can accomplish his mission.\nHe cannot return to the kitchen.\nHe cannot return to the kitchen.\nHe can accomplish his mission.\nHe can accomplish... | [
"5 3\n#####\n#K.M#\n#####\n9 5\n#########\n#.....###\n#.###..M#\n#K#######\n#########\n9 5\n#########\n#K......#\n####.####\n####M####\n#########\n9 5\n#########\n#M......#\n####.####\n####K####\n#########\n7 9\n#######\n#####M#\n#####.#\n#.....#\n#.###.#\n#.....#\n#.#####\n#K#####\n#######\n7 6\n#######\n#####.#\n... | [
"He can accomplish his mission.\nHe can accomplish his mission.\nHe cannot bring tea to his master.\nHe cannot return to the kitchen.\nHe can accomplish his mission.\nHe can accomplish his mission.\nHe cannot return to the kitchen.\nHe cannot return to the kitchen.\nHe can accomplish his mission.\nHe can accomplish... |
CodeContests | As the Monk is also taking part in the CodeMonk Series, this week he learned about hashing. Now he wants to practice some problems. So he came up with a simple problem. Firstly, he made a hash function F such that:
F(x) = x % 10
Now using this function he wants to hash N integers and count the number of collisions th... | stdin | null | 4,693 | 1 | [
"2\n3\n1 2 3\n4\n1 1 2 3\n\nSAMPLE\n"
] | [
"0\n1\n"
] | [
"10\n100\n71935 12426 60607 14999 24788 53252 88601 42859 45596 30680 87885 51124 77664 80611 90491 86973 46221 65110 96706 46538 83381 43340 32299 40293 9548 49969 79168 66193 97914 31290 11074 83337 45655 53742 68569 25330 50677 80395 86052 27510 44845 66918 277 61536 39582 3082 22510 85702 7401 90386 67991 37222... | [
"90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n",
"0\n1\n",
"0\n0\n",
"1\n0\n",
"1\n1\n",
"0\n2\n",
"90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n",
"90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n",
"90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n",
"0\n1\n"
] |
CodeContests | Example
Input
2 1
1 2
1 2 1 1
Output
1/2 | stdin | null | 2,381 | 1 | [
"2 1\n1 2\n1 2 1 1\n"
] | [
"1/2\n"
] | [
"2 1\n1 2\n1 2 1 2\n",
"2 0\n1 2\n1 2 1 1\n",
"4 1\n1 2\n1 2 1 1\n",
"4 1\n1 2\n1 2 2 2\n",
"2 1\n1 2\n1 2 1 3\n",
"3 0\n1 2\n1 2 1 1\n",
"5 0\n1 2\n1 2 1 1\n",
"5 0\n1 2\n0 2 1 1\n",
"5 0\n1 2\n0 2 1 0\n",
"3 0\n1 2\n0 2 1 0\n"
] | [
"4/5\n",
"0/1\n",
"1/2\n",
"16/5\n",
"9/10\n",
"0/1\n",
"0/1\n",
"0/1\n",
"0/1\n",
"0/1\n"
] |
CodeContests | People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 172), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland.
There are four combinations of coins... | stdin | null | 4,593 | 1 | [
"2\n10\n30\n0\n"
] | [
"1\n4\n27\n"
] | [
"2\n10\n12\n0\n",
"2\n11\n3\n0\n",
"2\n16\n3\n0\n",
"2\n14\n3\n0\n",
"2\n10\n39\n0\n",
"2\n11\n6\n0\n",
"2\n17\n39\n0\n",
"2\n4\n1\n0\n",
"2\n2\n6\n0\n",
"2\n17\n37\n0\n"
] | [
"1\n4\n5\n",
"1\n4\n1\n",
"1\n8\n1\n",
"1\n6\n1\n",
"1\n4\n50\n",
"1\n4\n2\n",
"1\n9\n50\n",
"1\n2\n1\n",
"1\n1\n2\n",
"1\n9\n46\n"
] |
CodeContests | Description
KMC sells CDs every year at a coterie spot sale called Comic Market. F was supposed to sell CDs at the comic market, but due to the popularity of F, the KMC sales floor was flooded with people, and the calculation of change could not keep up. So F decided to write a program that would output the change as ... | stdin | null | 2,261 | 1 | [
"500 1000\n100 10000\n400 700\n600 5000\n10000 10000\n0 0\n"
] | [
"0 1 0\n4 1 9\n3 0 0\n4 0 4\n0 0 0\n"
] | [
"500 1001\n100 10000\n400 700\n600 5000\n10000 10000\n0 0\n",
"500 1001\n100 10100\n400 700\n600 5000\n10000 10000\n0 0\n",
"500 1001\n100 10100\n400 700\n429 5000\n10000 10000\n0 0\n",
"500 1001\n100 10100\n400 700\n429 5000\n10000 11001\n0 0\n",
"500 1001\n100 10100\n454 700\n429 5000\n10000 11001\n0 0\n"... | [
"0 1 0\n4 1 9\n3 0 0\n4 0 4\n0 0 0\n",
"0 1 0\n0 0 10\n3 0 0\n4 0 4\n0 0 0\n",
"0 1 0\n0 0 10\n3 0 0\n0 1 4\n0 0 0\n",
"0 1 0\n0 0 10\n3 0 0\n0 1 4\n0 0 1\n",
"0 1 0\n0 0 10\n2 0 0\n0 1 4\n0 0 1\n",
"0 1 0\n0 0 10\n3 0 0\n3 0 4\n0 0 0\n",
"0 1 0\n4 1 9\n1 0 0\n4 0 4\n0 0 0\n",
"0 1 0\n0 0 10\n3 0 0\n1... |
CodeContests | Ramesh is a hard-working employee.Seeing his dedication towards his work his boss decided to promote him. Ramesh was overjoyed on getting to know this.But soon he realized he needed to shift to another Town X. Ramesh needed to transport his n boxes to Town X for which he contacted the company "Packers and Movers".This ... | stdin | null | 3,148 | 1 | [
"7 2\n10 2 16 19 6 11 5\n29 25\n\nSAMPLE\n"
] | [
"7\n"
] | [
"5 3\n2 5 2 4 7\n6 12 9\n",
"7 2\n10 2 16 19 6 11 10\n29 25\n\nSAMPLE\n",
"7 2\n10 2 7 19 6 11 10\n2 20\n\nELPMAS\n",
"7 2\n10 2 7 19 1 11 10\n2 20\n\nELPMAS\n",
"5 3\n2 5 2 4 7\n6 8 0\n",
"7 2\n10 2 16 19 2 11 5\n29 1\n\nSAMPLE\n",
"5 3\n2 5 2 4 10\n6 12 9\n",
"7 2\n10 2 7 19 6 11 10\n29 25\n\nSAMPLE... | [
"3\n",
"7\n",
"11\n",
"9\n",
"5\n",
"13\n",
"3\n",
"7\n",
"3\n",
"7\n"
] |
CodeContests | Aizu Gakuen High School holds a school festival every year. The most popular of these is the haunted house. The most popular reason is that 9 classes do haunted houses instead of 1 or 2 classes. Each one has its own unique haunted house. Therefore, many visitors come from the neighborhood these days.
Therefore, the sc... | stdin | null | 4,749 | 1 | [
"1a 132 243\n1c 324 183\n1f 93 199\n2b 372 163\n2c 229 293\n2e 391 206\n3a 118 168\n3b 263 293\n3d 281 102\n"
] | [
"1a 375 99300\n1c 507 119700\n1f 292 78300\n2b 535 123300\n2c 522 133700\n2e 597 140000\n3a 286 74000\n3b 556 140500\n3d 383 86800\n"
] | [
"1a 132 243\n1c 324 183\n1f 93 199\n2b 372 163\n2c 229 346\n2e 391 206\n3a 118 168\n3b 263 293\n3d 281 102\n",
"1a 132 243\n1c 324 183\n1f 93 199\n3b 372 163\n2c 229 346\n2e 391 206\n3a 118 168\n3b 263 293\n3d 281 102\n",
"1a 132 243\n1c 324 183\n1f 93 199\n3b 372 163\n2c 229 346\n2e 12 206\n3a 118 168\n3b 263 ... | [
"1a 375 99300\n1c 507 119700\n1f 292 78300\n2b 535 123300\n2c 575 149600\n2e 597 140000\n3a 286 74000\n3b 556 140500\n3d 383 86800\n",
"1a 375 99300\n1c 507 119700\n1f 292 78300\n3b 535 123300\n2c 575 149600\n2e 597 140000\n3a 286 74000\n3b 556 140500\n3d 383 86800\n",
"1a 375 99300\n1c 507 119700\n1f 292 78300... |
CodeContests | The nth triangular number is defined as the sum of the first n positive integers. The nth tetrahedral number is defined as the sum of the first n triangular numbers. It is easy to show that the nth tetrahedral number is equal to n(n+1)(n+2) ⁄ 6. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+... | stdin | null | 187 | 1 | [
"40\n14\n5\n165\n120\n103\n106\n139\n0\n"
] | [
"2 6\n2 14\n2 5\n1 1\n1 18\n5 35\n4 4\n3 37\n"
] | [
"40\n14\n5\n165\n120\n133\n106\n139\n0\n",
"40\n14\n5\n98\n120\n133\n106\n139\n0\n",
"40\n14\n5\n98\n120\n133\n106\n150\n0\n",
"40\n14\n5\n70\n120\n133\n106\n150\n0\n",
"40\n14\n9\n70\n120\n133\n106\n150\n0\n",
"40\n14\n9\n70\n72\n133\n106\n150\n0\n",
"40\n14\n9\n29\n72\n133\n106\n150\n0\n",
"40\n14\n... | [
"2 6\n2 14\n2 5\n1 1\n1 18\n4 31\n4 4\n3 37\n",
"2 6\n2 14\n2 5\n3 30\n1 18\n4 31\n4 4\n3 37\n",
"2 6\n2 14\n2 5\n3 30\n1 18\n4 31\n4 4\n3 14\n",
"2 6\n2 14\n2 5\n2 2\n1 18\n4 31\n4 4\n3 14\n",
"2 6\n2 14\n3 9\n2 2\n1 18\n4 31\n4 4\n3 14\n",
"2 6\n2 14\n3 9\n2 2\n4 4\n4 31\n4 4\n3 14\n",
"2 6\n2 14\n3 9... |
CodeContests | We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i.
Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5. Initially, the intensity o... | stdin | null | 4,185 | 1 | [
"5 1\n1 0 0 1 0\n",
"5 2\n1 0 0 1 0\n"
] | [
"1 2 2 1 2\n",
"3 3 4 4 3\n"
] | [
"5 1\n0 0 0 1 0\n",
"5 2\n0 0 0 1 0\n",
"5 2\n0 0 0 0 0\n",
"5 2\n1 0 0 0 0\n",
"5 2\n0 0 0 0 1\n",
"5 0\n0 0 0 0 1\n",
"5 2\n1 0 0 2 0\n",
"5 2\n0 0 0 2 0\n",
"5 3\n0 0 0 0 0\n",
"5 2\n0 1 0 0 1\n"
] | [
"1 1 2 1 2\n",
"3 3 4 3 3\n",
"2 3 3 3 2\n",
"2 3 3 4 2\n",
"2 4 3 3 2\n",
"0 0 0 0 1\n",
"3 3 4 4 4\n",
"3 3 4 4 3\n",
"4 4 5 4 4\n",
"3 4 4 3 3\n"
] |
CodeContests | G: Minimum Enclosing Rectangle-Minimum Enclosing Rectangle-
story
Hello everyone! It's Airi Aiza from the Hachimori Naka Prokon Club. Suddenly, I want everyone to solve the problem that Airi couldn't solve before. I solved the A problem of ICPC2010 in this front activity, but the problem at that time was difficult.
... | stdin | null | 195 | 1 | [
"1\n"
] | [
"1\n"
] | [
"001\n",
"001\n"
] | [
"1.000000000\n",
"1.000000000\n"
] |
CodeContests | Brio wants to get a beautiful house constructed near the National Highway. As his in laws are very much fond of triangles, he decided to give his house a perfect Triangular Shape.
Now, here comes the problem that he faces. The plots in Hackers' Land are all circular in shape. You need to help Brio find the area of the ... | stdin | null | 873 | 1 | [
"2\n5.0000 3.0000 4.0000\n12.0000 13.0000 5.0000\n\n\nSAMPLE\n"
] | [
"19.6344\n132.7284\n"
] | [
"2\n5.0000 3.5218061682463278 4.0000\n12.0000 13.0000 5.0000\n\n\nSAMPLE\n",
"2\n5.0000 3.5218061682463278 4.0000\n12.0000 13.173512536333314 5.0000\n\n\nSAMPLE\n",
"2\n5.757769514565519 3.5218061682463278 4.0000\n12.0000 13.173512536333314 5.0000\n\n\nSAMPLE\n",
"2\n5.757769514565519 3.5218061682463278 4.000... | [
"19.9251\n132.7284\n",
"19.9251\n136.4906\n",
"26.7980\n136.4906\n",
"26.7980\n158.7734\n",
"26.7980\n155.2843\n",
"26.7980\n201.5500\n",
"38.4310\n201.5500\n",
"39.6730\n201.5500\n",
"32.3274\n201.5500\n",
"32.3274\n243.4488\n"
] |
CodeContests | Sha, Nero, Eri, and Ko, who entered the University of Aizu Elementary School (Aizu University and Small), decided to participate in a programming contest called IPPC in order to play an active role as a competition programmer. However, IPPCs are required to participate in the contest as a team of three people, and it i... | stdin | null | 3,885 | 1 | [
"4\n-100 -100\n100 -100\n100 100\n-100 100\n4\n-99 -100\n100 -100\n100 100\n-99 100\n4\n-100 -99\n100 -99\n100 100\n-100 100\n14\n-99 -70\n-92 -79\n10 -98\n37 -100\n62 -95\n77 -69\n88 -47\n92 -10\n96 28\n100 91\n42 92\n-62 92\n-88 91\n-98 64\n0\n"
] | [
"100.000000000000000 0.000000000000000\n100.000000000000000 0.000000000000000\n0.000000000000000 100.000000000000000\n-96.983291994836122 66.745111613942484\n"
] | [
"4\n-100 -100\n100 -100\n100 100\n-100 100\n4\n-99 -100\n100 -100\n100 100\n-99 000\n4\n-100 -99\n100 -99\n100 100\n-100 100\n14\n-99 -70\n-92 -79\n10 -98\n37 -100\n62 -95\n77 -69\n88 -47\n92 -10\n96 28\n100 91\n42 92\n-62 92\n-88 91\n-98 64\n0\n",
"4\n-100 -100\n100 -100\n100 100\n-100 100\n4\n-99 -100\n100 -100... | [
"hello world\n",
"hello world\n",
"hello world\n",
"hello world\n",
"hello world\n",
"hello world\n",
"hello world\n",
"hello world\n",
"hello world\n",
"hello world\n"
] |
CodeContests | You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N.
You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's say with the index j) and arbitrarily shuffle the elements of our permutatio... | stdin | null | 4,370 | 1 | [
"2\n7 4\n3 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3\n"
] | [
"Possible\nImpossible\n"
] | [
"2\n7 4\n6 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3\n",
"2\n7 4\n3 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 6\n2 4\n2 3\n",
"2\n7 4\n6 1 2 4 5 7 6\n1 2\n4 0\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3\n",
"2\n8 4\n6 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3\n",
"2\n7 4\n6 1 2 4 5 7 6\n... | [
"Impossible\nImpossible\n",
"Possible\nImpossible\n",
"Impossible\nImpossible\n",
"Impossible\nImpossible\n",
"Impossible\nImpossible\n",
"Impossible\nImpossible\n",
"Impossible\nImpossible\n",
"Impossible\nImpossible\n",
"Impossible\nImpossible\n",
"Impossible\nImpossible\n"
] |
CodeContests | You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.
There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i.
According to an examina... | stdin | null | 2,007 | 1 | [
"6\n5 2 4 2 8 8\n",
"6\n2 3 3 1 3 1\n",
"32\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5\n"
] | [
"0\n",
"3\n",
"22\n"
] | [
"32\n3 1 4 1 5 9 4 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5\n",
"32\n3 1 4 1 5 9 4 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 2 5\n",
"32\n3 1 4 1 5 9 4 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 2 8\n",
"32\n3 1 4 1 5 9 4 12 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 2 8\n",
"6\n2 3 6 1 3 1... | [
"23\n",
"24\n",
"25\n",
"27\n",
"3\n",
"26\n",
"28\n",
"21\n",
"19\n",
"20\n"
] |
CodeContests | Problem
There is a grid of $ N \ times N $ cells. Initially all cells are white. Follow the steps below to increase the number of black squares.
Select one white cell from the cells that are even-numbered from the top and even-numbered from the left. The selected square turns black. Further, the adjacent white square... | stdin | null | 3,695 | 1 | [
"5\noxooo\noxooo\noxooo\nxxxxx\noxooo\n",
"9\noxoooooxo\noxxxxxxxx\noxoooooxo\nxxxxxxxxx\noxoxooooo\noxxxxxxxx\noxoxoxooo\noxoxxxxxx\noxoxoxooo\n"
] | [
"1\n",
"4\n"
] | [
"9\noxoooooxo\noxxxxxxxx\noxoooooxo\nxxxxxxxxx\noxoxooooo\noxxxxxxxx\noxoxoxooo\nxxxxxxoxo\noxoxoxooo\n",
"5\noxoop\noxooo\noxooo\nxxxxx\noxooo\n",
"9\noxoooooxo\noxxxxxxxx\noxoooooxo\nxxxxxxxxx\noxoxooooo\noxxxxxxxx\noxoxoxooo\nxxxxxxoxo\noooxoxoxo\n",
"9\noxoooooxo\noxxxxxxxx\noxoooooxo\nxxxxxxxxx\noxoxoooo... | [
"4\n",
"1\n",
"4\n",
"4\n",
"4\n",
"4\n",
"4\n",
"4\n",
"4\n",
"4\n"
] |
CodeContests | You are planning to create a map of an RPG. This map is represented by a grid whose size is $H \times W$. Each cell in this grid is either '@', '*', '#', or '.'. The meanings of the symbols are as follows.
* '@': The start cell. The story should start from this cell.
* '*': A city cell. The story goes through or ends ... | stdin | null | 4,877 | 1 | [
"11 7\n.......\n.......\n*.....*\n.......\n..@....\n.......\n*......\n.......\n....*..\n.......\n.......\n",
"7 11\n........*..\n...........\n...........\n...........\n....*...*..\n...........\n..*.@...*..\n"
] | [
".......\n.......\n*#####*\n......#\n..@...#\n..#.###\n*##.#..\n#...#..\n####*..\n.......\n.......\n",
"........*..\n........#..\n........#..\n........#..\n..##*##.*..\n..#...#.#..\n..*#@.##*..\n"
] | [
"11 7\n.......\n.......\n*.....*\n.......\n..@....\n.......\n......*\n.......\n....*..\n.......\n.......\n",
"11 7\n.......\n.......\n*.....*\n.......\n..@....\n.......\n......*\n.......\n..*....\n.......\n.......\n",
"11 7\n.......\n.......\n*.....*\n.......\n..@....\n.......\n*......\n.......\n....*..\n-........ | [
"#######\n#.....#\n*.###.*\n..#.#.#\n..@.#.#\n....#.#\n....#.*\n....#.#\n....*.#\n....#.#\n....###\n",
"#######\n#.....#\n*.###.*\n#.#.#.#\n#.@.#.#\n#...#.#\n#...#.*\n#...#.#\n#.*.#.#\n#.#.#.#\n###.###\n",
"#######\n#.....#\n*.###.*\n#.#.#.#\n#.@.#.#\n#...#.#\n*...#.#\n....#.#\n....*.#\n-...#.#\n....###\n",
"... |
CodeContests | Problem
Den, the phone number of Ukunikia Co., Ltd., enters a very long phone number into the phone every day.
One day, too tired, Den came up with a surprising idea.
"Isn't it even a little easier if you rearrange the arrangement of the buttons on the phone ?!"
The phone has squares evenly spaced at $ 3 \ times 3 $,... | stdin | null | 788 | 1 | [
"10\n1236547896\n",
"11\n31415926535\n"
] | [
"123\n456\n789\n",
"137\n456\n892\n"
] | [
"10\n1598114589\n",
"11\n18396312558\n",
"10\n2555486547\n",
"10\n2722382398\n",
"10\n2713182985\n",
"10\n4333783596\n",
"11\n24764186449\n",
"10\n1859787539\n",
"10\n1888971773\n",
"10\n6843843631\n"
] | [
"142\n853\n967\n",
"124\n857\n369\n",
"123\n659\n847\n",
"139\n428\n576\n",
"317\n482\n659\n",
"124\n783\n695\n",
"318\n246\n597\n",
"124\n853\n796\n",
"173\n892\n456\n",
"125\n347\n689\n"
] |
CodeContests | Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range. The mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N. Mr. Takahashi traversed the range from the west and Mr. Aoki from the east.
The height of Mt. i is h_i... | stdin | null | 2,768 | 1 | [
"5\n1 3 3 3 3\n3 3 2 2 2\n",
"10\n1 3776 3776 8848 8848 8848 8848 8848 8848 8848\n8848 8848 8848 8848 8848 8848 8848 8848 3776 5\n",
"1\n17\n17\n",
"5\n1 1 1 2 2\n3 2 1 1 1\n"
] | [
"4\n",
"884111967\n",
"1\n",
"0\n"
] | [
"5\n2 3 3 3 3\n3 3 2 2 2\n",
"5\n1 1 1 2 2\n6 2 1 1 1\n",
"5\n1 1 1 4 2\n6 2 1 1 1\n",
"5\n1 1 1 4 2\n6 2 1 1 0\n",
"5\n1 1 1 4 2\n6 0 1 1 0\n",
"5\n1 1 1 4 2\n6 1 1 1 0\n",
"5\n1 1 1 4 2\n6 2 1 2 0\n",
"5\n1 1 1 4 2\n9 2 1 2 0\n",
"5\n1 1 1 1 2\n9 2 1 2 0\n",
"5\n1 1 1 1 2\n9 2 1 2 -1\n"
] | [
"4\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n"
] |
CodeContests | Your job is to find out the secret number hidden in a matrix, each of whose element is a digit ('0'-'9') or a letter ('A'-'Z'). You can see an example matrix in Figure 1.
<image>
Figure 1: A Matrix
The secret number and other non-secret ones are coded in a matrix as sequences of digits in a decimal format. You shoul... | stdin | null | 4,315 | 1 | [
"7 4\n9R2A993\n0E314A0\n8A900DE\n820R037\n6 7\nJH03HE\nID7722\n0DA1AH\n30C9G5\n99971A\nCA7EAI\nAHLBEM\n20 2\nA1234567891234CBDEGH\nBDEDF908034265091499\n0 0\n"
] | [
"23900037\n771971\n12345908034265091499\n"
] | [
"7 4\n9R2A993\n0E314A0\n8A900DE\n820R037\n6 7\nJH03HE\nID7722\n0DA1AH\n30C9G5\n99971A\nCA7EAI\nAHLBEM\n20 2\nHGEDBC4321987654321A\nBDEDF908034265091499\n0 0\n",
"7 4\n9R2A993\n0E314A0\n8A900DE\n820R037\n6 7\nJI03HE\nID7722\n0DA1AH\n30C9G5\n99971A\nCA7EAI\nAHLBEM\n20 2\nA1234567891234CBDEGH\nBDEDF908034265091499\n... | [
"23900037\n771971\n908034265091499\n",
"23900037\n771971\n12345908034265091499\n",
"23900037\n771971\n994190562430809\n",
"23900037\n771979\n12345908034265091499\n",
"23900037\n771871\n994190562430809\n",
"908820703\n771979\n12345908034265091499\n",
"93900037\n771971\n12345908034265091499\n",
"2314093... |
CodeContests | Vardhaman college of engg. is conducting a coding challenge. The registrations are opened. Many people from different colleges are being registered for this event. Some of them are trying to make some errors in the registrations. They have registered there names more than one time by creating different e-mail ids. This... | stdin | null | 2,037 | 1 | [
"10\nraghav\nsitish\nraghu\nvishwa\nkumar \nraghu\nraghu\nraghav\nritesh\ndeepesh\n\nSAMPLE\n"
] | [
"2\nraghav\nraghu\n"
] | [
"10\nraghav\nsitish\nraghu\nvishwa\nkumar \nsaghu\nraghu\nraghav\nritesh\ndeepesh\n\nSAMPLE\n",
"10\nraghav\nsitish\nraghu\nawhsiv\nkumar \nuhgar\nuhgar\nraghav\nqisesh\nhsepeed\n\nDLPMAS\n",
"10\nraghav\nsitish\nsaghu\nawhsiv\nkuram \nraghu\nsaghu\nraghav\nqigess\nhseoeed\n\nDLPNAS\n",
"10\nraghav\nsitish\nr... | [
"2\nraghav\nraghu\n",
"2\nraghav\nuhgar\n",
"2\nraghav\nsaghu\n",
"2\nraghav\nraghu\n",
"2\nraghav\nraghu\n",
"2\nraghav\nraghu\n",
"2\nraghav\nraghu\n",
"2\nraghav\nraghu\n",
"2\nraghav\nraghu\n",
"2\nraghav\nraghu\n"
] |
CodeContests | Given are a positive integer N and a sequence of length 2^N consisting of 0s and 1s: A_0,A_1,\ldots,A_{2^N-1}. Determine whether there exists a closed curve C that satisfies the condition below for all 2^N sets S \subseteq \\{0,1,\ldots,N-1 \\}. If the answer is yes, construct one such closed curve.
* Let x = \sum_{i ... | stdin | null | 3,872 | 1 | [
"2\n1000\n",
"1\n10\n",
"2\n1001\n",
"1\n11\n"
] | [
"Possible\n6\n1 0\n2 0\n2 1\n1 1\n0 1\n0 0\n1 0\n",
"Possible\n4\n0 0\n0 1\n1 1\n1 0\n0 0\n",
"Impossible\n",
"Possible\n0\n1 1\n"
] | [
"1\n0\n",
"1\n13\n",
"2\n1010\n",
"2\n1100\n",
"2\n1110\n",
"2\n0001\n",
"2\n0101\n",
"1\n12\n",
"2\n0111\n",
"2\n1111\n"
] | [
"Impossible\n",
"Possible\n0\n0 0\n",
"Possible\n4\n0 0\n0 1\n1 1\n1 0\n0 0\n",
"Possible\n6\n0 0\n1 0\n1 1\n2 1\n2 0\n1 0\n0 0\n",
"Possible\n20\n0 0\n1 0\n1 1\n2 1\n2 0\n1 0\n0 0\n0 1\n1 1\n1 0\n0 0\n1 0\n2 0\n2 1\n1 1\n1 0\n0 0\n1 0\n1 1\n0 1\n0 0\n",
"Impossible\n",
"Impossible\n",
"Possible\n0\n0... |
CodeContests | Snuke has X+Y balls. X of them have an integer A written on them, and the other Y of them have an integer B written on them.
Snuke will divide these balls into some number of groups. Here, every ball should be contained in exactly one group, and every group should contain one or more balls.
A group is said to be good... | stdin | null | 3,430 | 1 | [
"3\n3 3 4 4 5\n2 1 1 5 3\n3 1 4 2 5\n"
] | [
"2\n2\n0\n"
] | [
"3\n3 3 4 8 5\n2 1 1 5 3\n3 1 4 2 5\n",
"3\n3 3 4 8 5\n2 2 1 5 3\n3 1 4 2 5\n",
"3\n3 3 4 7 5\n2 1 1 10 3\n3 1 4 2 5\n",
"3\n3 3 4 7 5\n2 1 1 10 3\n3 1 1 2 5\n",
"3\n1 3 4 7 5\n2 2 1 10 3\n3 1 1 0 8\n",
"3\n1 3 7 7 5\n0 2 1 10 3\n3 1 1 -1 6\n",
"3\n3 3 2 8 5\n2 2 1 5 3\n3 1 4 2 5\n",
"3\n1 3 4 7 5\n2 ... | [
"2\n2\n0\n",
"2\n3\n0\n",
"2\n4\n0\n",
"2\n4\n1\n",
"3\n4\n0\n",
"3\n5\n0\n",
"4\n3\n0\n",
"3\n2\n0\n",
"2\n7\n1\n",
"2\n5\n0\n"
] |
CodeContests | D: Country In Distortion-
story
Alice was completely bored. This is because the White Rabbit, who is always playing with him, is out to Trump Castle. (Ah, I wish I had gone out with him in this case.) Alice thought. However, this is a country of distortion. If you go out so easily, you will get very tired. What does ... | stdin | null | 3,934 | 1 | [
"4 4\n1 2 3\n2 3 1\n2 4 5\n3 4 2\n5\n4 5 6\n"
] | [
"34\n"
] | [
"4 4\n1 3 3\n2 3 1\n2 4 5\n3 4 2\n5\n4 5 6\n",
"4 4\n1 2 3\n2 3 1\n2 4 5\n3 4 2\n5\n4 5 7\n",
"4 4\n1 3 4\n2 3 1\n2 4 5\n3 4 2\n5\n4 5 6\n",
"4 4\n1 3 4\n2 3 0\n2 4 5\n3 4 2\n5\n4 5 6\n",
"4 4\n1 3 4\n2 3 1\n2 2 10\n3 4 1\n5\n4 5 6\n",
"4 4\n1 2 3\n2 3 1\n3 4 5\n3 4 2\n5\n4 5 6\n",
"4 4\n1 3 4\n2 3 1\n2... | [
"38\n",
"33\n",
"46\n",
"32\n",
"42\n",
"40\n",
"24\n",
"41\n",
"60\n",
"36\n"
] |
CodeContests | Shil is your new boss and he likes palindromes very much. Palindrome is a string that can be read the same way in either direction, from the left to the right and from the right to the left. (ex. madam , aabaa, racecar)
Given a string S , beautiful Palindrome is a lexicographical minimum palindrome that can be form... | stdin | null | 2,395 | 1 | [
"aabcc\n\nSAMPLE\n"
] | [
"acbca\n"
] | [
"yvqszlrqoxkfaupflahrnwygzetlwynhxalauuzhaaeoxzkyroertpxdwxlngzfoxregqxqhgmoklururjaetlwwnsggpyarhrxwgfaqhoecwrwwaewfsnwuaeurualuytawoeuaowtulstcumwntegoxjjsuptrjvbaouygwahnzdbnxsexdwtlngcxaxtbnrfqgrblxqntqnmeqtqwaalzjgqgoellzxlylnjqoaydqgprvaezoremrlghjaoobeysywoouzjzhwhexezcakesevlvjardondnxgzbewmgznlnarwohnowhaa... | [
"-1\n",
"acbca\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n"
] |
CodeContests | Saksham is fond of perfection in everything. He is also fond of playing FIFA so he likes to have perfection in his shots while shooting for a goal. Consider there is a goalpost, it has two corners left corner and right corner. There is a line in the center of the goalpost. If the player is on the left of the line it is... | stdin | null | 3,986 | 1 | [
"2\n5 3\n10 -3\n8 1\n\nSAMPLE\n"
] | [
"Right Corner\n"
] | [
"1000\n60065146 80268\n22709169 71940\n25432977 16093\n77193281 -60750\n90748118 -7517\n66724224 81335\n49810208 73886\n31769796 -48214\n87587072 5767\n72421175 -93960\n93233003 -59105\n17256872 -68273\n2560514 1250\n23976371 10882\n95240044 75351\n28338486 -15926\n43022402 -26134\n21406467 -95929\n58452727 -99352\... | [
"Right Corner\n",
"Left Corner\n",
"Either Corner\n",
"Right Corner\n",
"Right Corner\n",
"Right Corner\n",
"Right Corner\n",
"Right Corner\n",
"Right Corner\n",
"Right Corner\n"
] |
CodeContests | D: Many Decimal Integers
problem
Given a string S consisting only of numbers (0-9) and a string T consisting only of numbers and `?`. S and T are the same length.
Consider changing each `?` That exists in T to one of the numbers from 0 to 9 to create the string T'consisting of only numbers. At this time, it must be ... | stdin | null | 197 | 1 | [
"73\n6?\n"
] | [
"645\n"
] | [
"73\n?6\n",
"73\n@6\n",
"73\n5?\n",
"73\n?5\n",
"73\n4?\n",
"73\n?4\n",
"73\n?8\n",
"73\n?7\n",
"73\n7?\n",
"73\n?3\n"
] | [
"252\n",
"0\n",
"545\n",
"245\n",
"445\n",
"238\n",
"266\n",
"259\n",
"286\n",
"304\n"
] |
CodeContests | Snuke has decided to use a robot to clean his room.
There are N pieces of trash on a number line. The i-th piece from the left is at position x_i. We would like to put all of them in a trash bin at position 0.
For the positions of the pieces of trash, 0 < x_1 < x_2 < ... < x_{N} \leq 10^{9} holds.
The robot is initi... | stdin | null | 573 | 1 | [
"5 1\n1 999999997 999999998 999999999 1000000000\n",
"16 10\n1 7 12 27 52 75 731 13856 395504 534840 1276551 2356789 9384806 19108104 82684732 535447408\n",
"2 100\n1 10\n",
"10 8851025\n38 87 668 3175 22601 65499 90236 790604 4290609 4894746\n"
] | [
"19999999983\n",
"3256017715\n",
"355\n",
"150710136\n"
] | [
"5 1\n1 1856513539 999999998 999999999 1000000000\n",
"16 10\n1 7 12 27 52 75 731 13856 395504 534840 1276551 903860 9384806 19108104 82684732 535447408\n",
"2 100\n1 13\n",
"10 8851025\n38 87 668 4845 22601 65499 90236 790604 4290609 4894746\n",
"16 10\n1 7 12 27 52 75 731 18298 395504 534840 1276551 90386... | [
"24282567693\n",
"3248753070\n",
"370\n",
"150735186\n",
"3248775280\n",
"430\n",
"151679486\n",
"3248775305\n",
"433\n",
"151687340\n"
] |
CodeContests | There is a grid with H rows and W columns, where each square is painted black or white.
You are given H strings S_1, S_2, ..., S_H, each of length W. If the square at the i-th row from the top and the j-th column from the left is painted black, the j-th character in the string S_i is `#`; if that square is painted whi... | stdin | null | 3,993 | 1 | [
"3 3\n.#.\n..#\n#..\n",
"4 3\n\n\n...\n",
"3 3\n.#.\n..#\n..\n",
"2 4\n....\n....\n"
] | [
"10\n",
"6\n",
"10\n",
"0\n"
] | [
"3 4\n.#.\n..#\n#..\n",
"4 4\n\n\n...\n",
"3 3\n.#.\n-.#\n..\n",
"3 4\n.#.\n..#\n#./\n",
"3 2\n.#.\n-.#\n..\n",
"3 1\n.#.\n..#\n#./\n",
"3 2\n.#.\n#.-\n..\n",
"4 2\n.#.\n#.-\n..\n",
"4 2\n.#.\n#.-\n-.\n",
"4 1\n.#.\n#--\n..\n"
] | [
"16\n",
"0\n",
"14\n",
"27\n",
"4\n",
"1\n",
"6\n",
"8\n",
"12\n",
"3\n"
] |
CodeContests | Raju loves playing with maths.He is very fond of factorials.Now he is interested in knowing the last five digits n!(nth number factorial).
As he is not very good at programming , so he needs your help.
Your task is to print the last five digits of n!.
If number of digits is less than 5 then print the answer with leadi... | stdin | null | 2,550 | 1 | [
"4\n1 \n2\n3\n4\n\nSAMPLE\n"
] | [
"00001\n00002\n00006\n00024\n"
] | [
"10\n15\n16\n17\n18\n19\n5\n21\n22\n23\n24\n",
"4\n1 \n1\n3\n4\n\nSAMPLE\n",
"10\n15\n16\n17\n32\n19\n5\n21\n22\n23\n24\n",
"4\n2 \n1\n3\n4\n\nSAMPLE\n",
"4\n2 \n1\n1\n4\n\nSAMPLE\n",
"4\n4 \n1\n1\n4\n\nRAMPLE\n",
"4\n4 \n1\n1\n3\n\nRAMPLE\n",
"4\n4 \n2\n1\n3\n\nQALPLE\n",
"4\n3 \n2\n1\n3\n\nQALPLE\... | [
"68000\n88000\n96000\n28000\n32000\n00120\n40000\n80000\n40000\n60000\n",
"00001\n00001\n00006\n00024\n",
"68000\n88000\n96000\n00000\n32000\n00120\n40000\n80000\n40000\n60000\n",
"00002\n00001\n00006\n00024\n",
"00002\n00001\n00001\n00024\n",
"00024\n00001\n00001\n00024\n",
"00024\n00001\n00001\n00006\... |
CodeContests | Given are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.
Constraints
* S and T are strings consisting of lowercase English letters.
* The lengths of S and T are between 1 and 100 (inclusive).
Input
Input is gi... | stdin | null | 4,422 | 1 | [
"humu humu\n",
"oder atc\n"
] | [
"humuhumu\n",
"atcoder\n"
] | [
"gumu humu\n",
"oder atb\n",
"gumt humu\n",
"redo atb\n",
"gums humu\n",
"redp atb\n",
"gums muhu\n",
"redp bta\n",
"gums luhu\n",
"redo bta\n"
] | [
"humugumu\n",
"atboder\n",
"humugumt\n",
"atbredo\n",
"humugums\n",
"atbredp\n",
"muhugums\n",
"btaredp\n",
"luhugums\n",
"btaredo\n"
] |
CodeContests | Arrays have fallen out of Chef's good books, and he plans to destroy all arrays he possesses. He is left with the last array A, consisting of N positive integers. In order to destroy the array, he can perform the following 2 types of operations any number of times.
Choose any 2 elements, say X and Y, from the given a... | stdin | null | 3,780 | 1 | [
"3\n2\n1 2\n2\n1 1\n3\n1 2 3\n"
] | [
"1\n2\n2\n"
] | [
"3\n2\n1 2\n2\n1 1\n3\n1 4 3\n",
"3\n2\n0 2\n2\n1 0\n3\n1 4 3\n",
"3\n2\n1 1\n2\n1 1\n3\n1 2 -1\n",
"3\n2\n1 1\n2\n1 2\n3\n1 2 -1\n",
"3\n2\n1 2\n2\n1 1\n3\n0 0 0\n",
"3\n2\n1 4\n2\n0 1\n3\n0 0 0\n",
"3\n2\n1 0\n2\n1 1\n3\n1 4 3\n",
"3\n2\n1 2\n2\n1 1\n3\n1 2 0\n",
"3\n2\n0 2\n2\n1 1\n3\n1 4 3\n",
... | [
"1\n2\n2\n",
"1\n1\n2\n",
"2\n2\n2\n",
"2\n1\n2\n",
"1\n2\n3\n",
"1\n1\n3\n",
"1\n2\n2\n",
"1\n2\n2\n",
"1\n2\n2\n",
"1\n2\n2\n"
] |
CodeContests | Navi got a task at school to collect N stones. Each day he can collect only one stone. As N can be a very large number so it could take many days to complete the task, but then he remembers that his mother gave him a magic that can double anything (i.e if he has 2 stones, the magic will make them to 4 stones). Navi ... | stdin | null | 2,876 | 1 | [
"2\n1\n3\n\nSAMPLE\n"
] | [
"1\n2\n"
] | [
"10000\n30712\n29260\n18391\n27280\n1418\n9121\n21242\n25603\n24535\n31483\n27489\n19374\n29055\n23121\n17850\n13263\n13007\n2951\n11242\n2065\n17626\n16180\n4279\n8810\n17099\n26792\n3012\n10052\n15737\n6958\n20931\n27867\n5436\n19598\n31974\n29158\n9728\n8406\n14742\n10105\n31127\n9050\n11112\n4650\n29780\n4346\n... | [
"11\n7\n10\n6\n5\n6\n9\n5\n12\n12\n8\n9\n11\n7\n8\n10\n9\n7\n9\n3\n7\n9\n7\n6\n7\n6\n6\n6\n10\n8\n7\n10\n7\n7\n10\n9\n3\n6\n8\n9\n10\n7\n7\n5\n7\n7\n8\n7\n10\n8\n5\n6\n5\n8\n9\n7\n9\n11\n6\n8\n7\n8\n6\n3\n9\n8\n8\n10\n5\n10\n5\n7\n11\n9\n6\n8\n11\n9\n7\n11\n6\n9\n9\n8\n4\n4\n4\n9\n5\n7\n7\n8\n4\n7\n6\n10\n7\n5\n6\n... |
CodeContests | Let us define the beauty of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3.
There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusi... | stdin | null | 1,050 | 1 | [
"2 3 1\n",
"1000000000 180707 0\n"
] | [
"1.0000000000\n",
"0.0001807060\n"
] | [
"1000000000 180707 1\n",
"1000000000 241440 1\n",
"1001000000 241440 5\n",
"1001000000 353960 8\n",
"0001000000 353960 8\n",
"0001000000 353960 15\n",
"1001100000 353960 15\n",
"1001100100 149885 23\n",
"1001101100 149885 23\n",
"1011101100 149885 23\n"
] | [
"0.0003614120\n",
"0.0004828780\n",
"0.0004823956\n",
"0.0007072108\n",
"0.7079123367\n",
"0.7079073812\n",
"0.0007071401\n",
"0.0002994386\n",
"0.0002994383\n",
"0.0002964768\n"
] |
CodeContests | Did you ever hear about 'Dragon Food' ? Its used to refer to the chocolates bought for your loved ones :). Po offers dragon food to master Shifu, who is a famous cook in the valley of food. In return, Shifu hands over the dragon scroll to Po, which is said to hold the ingredients of the secret recipe. To open the drago... | stdin | null | 1,510 | 1 | [
"3\n3 5 4\n5 0 1\n4 3 7\n"
] | [
"7\n16\n14\n"
] | [
"3\n3 5 4\n2 0 1\n4 3 7\n",
"3\n3 5 4\n2 0 1\n4 3 12\n",
"3\n3 5 4\n2 0 1\n4 3 0\n",
"3\n3 5 4\n10 0 1\n4 3 7\n",
"3\n3 5 4\n2 1 1\n4 3 12\n",
"3\n3 5 4\n1 0 1\n4 3 6\n",
"3\n3 5 4\n10 0 1\n3 3 7\n",
"3\n3 5 0\n2 0 1\n4 3 7\n",
"3\n3 5 4\n2 1 1\n6 3 12\n",
"3\n3 5 4\n10 0 1\n3 4 7\n"
] | [
"7\n2\n14\n",
"7\n2\n15\n",
"7\n2\n12\n",
"7\n512\n14\n",
"7\n3\n15\n",
"7\n1\n15\n",
"7\n512\n4\n",
"6\n2\n14\n",
"7\n3\n60\n",
"7\n512\n6\n"
] |
CodeContests | You are given an H × W grid.
The squares in the grid are described by H strings, S_1,...,S_H.
The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).
`.` stands for an empty square, and `#` stands for a square containin... | stdin | null | 297 | 1 | [
"3 5\n.....\n.#.#.\n.....\n",
"3 5\n",
"6 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...\n"
] | [
"11211\n1#2#1\n11211\n",
"\n",
"3\n8#7##\n5#\n4#65#2\n5##21\n4#310\n"
] | [
"3 7\n.....\n.#.#.\n.....\n",
"6 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...\n",
"12 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...\n",
"11 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...\n",
"2 5\n.....\n.#.#.\n.....\n",
"21 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...\n",
"16 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...\n",
"7 8\n.\n.#.#... | [
"11211\n1#2#1\n11211\n",
"1\n2#3##\n3#\n3#42#1\n3##21\n2#310\n",
"1\n2#3##\n3#\n3#42#1\n3##21\n2#310\n",
"1\n2#3##\n3#\n3#42#1\n3##21\n2#310\n",
"11211\n1#2#1\n",
"1\n2#3##\n3#\n3#42#1\n3##21\n2#310\n",
"1\n2#3##\n3#\n3#42#1\n3##21\n2#310\n",
"1\n2#3##\n3#\n3#42#1\n3##21\n2#310\n",
"11211\n1#2#1\n11... |
CodeContests | Given A and B, count the numbers N such that A ≤ N ≤ B and N is a palindrome.
Examples:
Palindromes: 121, 11 , 11411
Not Palindromes: 122, 10
Input:
First line contains T, the number of testcases. Each testcase consists of two integers A and B in one line.
Output:
For each testcase, print the required answer ... | stdin | null | 4,655 | 1 | [
"2\n10 13\n20 30\n\nSAMPLE\n"
] | [
"1\n1\n"
] | [
"2\n10 13\n20 30\n\nSPMALE\n",
"2\n10 13\n20 54\n\nAPMSLE\n",
"2\n10 13\n4 54\n\nAPMSLE\n",
"2\n8 13\n20 30\n\nSPMALE\n",
"2\n6 13\n20 30\n\nAPMSLE\n",
"2\n1 13\n20 54\n\nAPMSLE\n",
"2\n1 13\n32 54\n\nAPMSLE\n",
"2\n2 13\n20 30\n\nELAMPS\n",
"2\n1 3\n32 54\n\nAPMSLE\n",
"2\n2 3\n20 30\n\nELAMPS\n"... | [
"1\n1\n",
"1\n3\n",
"1\n10\n",
"3\n1\n",
"5\n1\n",
"10\n3\n",
"10\n2\n",
"9\n1\n",
"3\n2\n",
"2\n1\n"
] |
CodeContests | Two coordinates (a1, a2) and (b1, b2) on a two-dimensional grid of r × c are given. The cost of moving from a cell (e, f) to one of the cells (e + 1, f), (e-1, f), (e, f + 1), (e, f-1) is 1. And. You can also move between (e, c-1) and (e, 0), and between (r-1, f) and (0, f) at a cost of 1. At this time, find the number... | stdin | null | 70 | 1 | [
"500 500 0 0 200 200\n",
"4 4 0 0 1 1\n",
"4 4 0 0 3 3\n",
"2 3 0 0 1 2\n"
] | [
"34807775\n",
"2\n",
"2\n",
"4\n"
] | [
"500 500 0 0 107 200\n",
"4 1 0 0 1 1\n",
"4 4 1 0 3 3\n",
"2 3 0 0 1 1\n",
"500 500 0 0 107 239\n",
"2 1 0 0 1 1\n",
"678 500 0 0 107 168\n",
"500 500 0 0 200 277\n",
"500 500 1 0 107 239\n",
"678 353 0 0 107 239\n"
] | [
"68949311\n",
"1\n",
"6\n",
"4\n",
"29183355\n",
"2\n",
"46712821\n",
"1876138\n",
"8735893\n",
"48683066\n"
] |
CodeContests | A tatami mat, a Japanese traditional floor cover, has a rectangular form with aspect ratio 1:2. When spreading tatami mats on a floor, it is prohibited to make a cross with the border of the tatami mats, because it is believed to bring bad luck.
Your task is to write a program that reports how many possible ways to sp... | stdin | null | 1,103 | 1 | [
"3 4\n4 4\n0 0\n"
] | [
"4\n2\n"
] | [
"3 1\n4 4\n0 0\n",
"3 1\n6 4\n0 0\n",
"3 4\n4 1\n0 0\n",
"3 1\n4 2\n0 0\n",
"3 2\n6 4\n0 0\n",
"3 7\n4 1\n0 0\n",
"4 4\n4 1\n0 0\n",
"4 1\n4 2\n0 0\n",
"3 7\n7 1\n0 0\n",
"4 1\n6 4\n0 0\n"
] | [
"0\n2\n",
"0\n3\n",
"4\n1\n",
"0\n4\n",
"3\n3\n",
"0\n1\n",
"2\n1\n",
"1\n4\n",
"0\n0\n",
"1\n3\n"
] |
CodeContests | Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string.
One swap on a string is performed in this way:
Assuming 1 indexing, the i'th letter from the end is inserted
between i'th and (i+1)'th l... | stdin | null | 1,638 | 1 | [
"3\nhrrkhceaate\n\nSAMPLE\n"
] | [
"hackerearth\n"
] | [
"98765322\npjbsuxmdxyoxmlfokhmgpcnebqcpyxdokeifewlexackohcyooffqvltmnlooodyuneylpdjsiwhpyifpnmjjadyopnfgseehkfudlgxtdhjepqudfepgjqwbgciyioistfxfmvbrdlwserymxqshhrjnttoeiaycfxktvlmcyjwedvsbmlivftlyndfvdebkclhyytdyfafiwxllltjqqvreywdedergryhqskrakykjyvxmrifieyngvqmcweiodrhxecxqbkddgbpyjvhpuwxtplxmridvalvgnwyqhcvodmpo... | [
"pgypycmdmnjkrlkcaqtrwyhdswtmnevpwffovhnpwdebntvalinavnhqplsyqckeokbhhkcvhnlbelvfluftvhuovyctdleaabkjcmvbekyfamrjoxrdakyhieimevlefmdlbpavgggodpsbjxovyxvexreovmppnrrtrvjwymkdxjbdfxlwvtsyuloastbxstwtdstmgeqnltshycxrilgomvkkkixhibjfrevyiorhnfiddpfvwdakeaqcfyfvytmpeqcrwwvdqhynurjvqfjoeiywgqdeinhvqemamwlthfijcmabqprdhan... |
CodeContests | We have an analog clock whose three hands (the second hand, the minute hand and the hour hand) rotate quite smoothly. You can measure two angles between the second hand and two other hands.
Write a program to find the time at which "No two hands overlap each other" and "Two angles between the second hand and two other... | stdin | null | 1,696 | 1 | [
"12 0 0 0\n12 11 59 59\n12 1 56 0\n12 1 56 3\n12 1 56 34\n12 3 9 43\n12 3 10 14\n12 7 17 58\n12 7 18 28\n12 7 23 0\n12 7 23 31\n2 0 38 29\n2 0 39 0\n2 0 39 30\n2 1 6 20\n2 1 20 1\n2 1 20 31\n3 2 15 0\n3 2 59 30\n4 0 28 48\n5 1 5 40\n5 1 6 10\n5 1 7 41\n11 0 55 0\n0 0 0 0\n"
] | [
"0 0 43200 1427\n0 0 43200 1427\n1 56 4080 1427\n1 56 47280 1427\n1 57 4860 1427\n3 10 18600 1427\n3 10 61800 1427\n7 18 39240 1427\n7 18 82440 1427\n7 23 43140 1427\n7 24 720 1427\n0 38 4680 79\n0 39 2340 79\n0 40 0 1\n1 6 3960 79\n1 20 2400 79\n1 21 60 79\n2 15 0 1\n0 0 2700 89\n0 28 48 1\n1 6 320 33\n1 6 40 1\n1... | [
"12 0 0 0\n12 11 59 59\n12 1 56 0\n12 1 56 3\n12 1 56 34\n12 3 9 43\n12 3 10 14\n12 7 17 58\n12 7 18 28\n12 7 23 0\n12 7 23 31\n2 0 38 29\n2 0 39 0\n2 0 39 30\n2 1 6 20\n2 1 20 1\n2 1 20 31\n3 2 15 0\n3 2 59 30\n4 0 28 48\n5 1 5 37\n5 1 6 10\n5 1 7 41\n11 0 55 0\n0 0 0 0\n",
"12 0 0 0\n12 11 59 59\n12 1 56 0\n12 ... | [
"0 0 43200 1427\n0 0 43200 1427\n1 56 4080 1427\n1 56 47280 1427\n1 57 4860 1427\n3 10 18600 1427\n3 10 61800 1427\n7 18 39240 1427\n7 18 82440 1427\n7 23 43140 1427\n7 24 720 1427\n0 38 4680 79\n0 39 2340 79\n0 40 0 1\n1 6 3960 79\n1 20 2400 79\n1 21 60 79\n2 15 0 1\n0 0 2700 89\n0 28 48 1\n1 5 1300 33\n1 6 40 1\n... |
CodeContests | Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into its position in ... | stdin | null | 2,784 | 1 | [
"7\n2 5 1 3 2 3 0\n"
] | [
"0 1 2 2 3 3 5\n"
] | [
"7\n2 5 1 3 2 3 1\n",
"7\n2 5 1 3 4 3 1\n",
"7\n2 5 2 3 4 3 1\n",
"7\n4 5 2 3 4 3 1\n",
"7\n4 9 2 3 4 3 1\n",
"7\n4 9 2 3 4 3 2\n",
"7\n4 9 2 1 4 3 2\n",
"7\n4 9 2 0 4 3 3\n",
"7\n8 9 2 0 4 3 3\n",
"7\n8 9 2 0 6 3 3\n"
] | [
"1 1 2 2 3 3 5\n",
"1 1 2 3 3 4 5\n",
"1 2 2 3 3 4 5\n",
"1 2 3 3 4 4 5\n",
"1 2 3 3 4 4 9\n",
"2 2 3 3 4 4 9\n",
"1 2 2 3 4 4 9\n",
"0 2 3 3 4 4 9\n",
"0 2 3 3 4 8 9\n",
"0 2 3 3 6 8 9\n"
] |
CodeContests | Mobile phones are equipped with a function that displays input candidates in order to efficiently input texts such as emails. This records frequently used words and presents words that have the entered letters as initial letters as input candidates. For example, if you usually enter the word "computer" a lot, just ente... | stdin | null | 3,087 | 1 | [
"1\nben likes bananas the best among many fruits because bananas are sweet and cheap\nb\n1\nwinners get to visit aizu and the university of aizu and make many friends as well\na\n3\nask alex about\nthe answer for the\nassignment on android apps\na\n2\nprogramming is both\na sport and an intellectual puzzle\nc\n0\n"... | [
"bananas because ben best\naizu and as\nabout alex android answer apps\nNA\n"
] | [
"1\nben likes bananas the best among many fruits because bananas are sweet and cheap\nb\n1\nwinners get to visit aizu and the university of aizu and make many friends as well\na\n3\nask alex about\nthe answer for the\nassignment on android apps\na\n2\nprogramming is both\na spprt and an intellectual puzzle\nc\n0\n"... | [
"bananas because ben best\naizu and as\nabout alex android answer apps\nNA\n",
"bananas because ben best\nNA\nabout alex android answer apps\nNA\n",
"bananas because ben best\naizu and as\nabout alex android answer ask\nNA\n",
"bananas because ben best\naizu and ane as\nabout alex android answer ask\nNA\n",
... |
CodeContests | I: Ravage
Santa Claus was caught in the illuminations of the city and broke it.
There are N light bulbs in the illumination, and the $ i $ th light bulb only comes on when the voltage is above $ A_i $ and below $ B_i $.
The voltage should be the same everywhere in the illumination.
Find out how many light bulbs can... | stdin | null | 4,129 | 1 | [
"4\n1 4\n3 6\n2 7\n5 8\n"
] | [
"3\n"
] | [
"4\n0 4\n3 6\n2 7\n5 8\n",
"4\n0 4\n3 6\n2 9\n0 8\n",
"4\n-1 2\n3 2\n3 7\n-1 8\n",
"4\n-1 0\n1 2\n3 0\n1 12\n",
"4\n0 4\n3 6\n2 9\n5 8\n",
"4\n0 4\n3 6\n2 9\n1 8\n",
"4\n0 4\n3 6\n2 7\n1 8\n",
"4\n0 4\n3 6\n3 7\n1 8\n",
"4\n0 4\n3 6\n3 7\n0 8\n",
"4\n0 2\n3 6\n3 7\n0 8\n"
] | [
"3\n",
"4\n",
"2\n",
"1\n",
"3\n",
"4\n",
"4\n",
"4\n",
"4\n",
"3\n"
] |
CodeContests | Stannis borathean is attacking kings landing from three gates.To defend the city Tyrion again comes up with a fair solution. Tyrion has N soldier troops with given strengths. Tyrion wants to divide army into 3 sets such that the sum of strengths in these three sets are as equal as possible. In other words he wants to m... | stdin | null | 1,713 | 1 | [
"4\n3\n4\n1\n3\n\nSAMPLE\n"
] | [
"4\n"
] | [
"4\n3\n4\n1\n3\n\nELPMAS\n",
"4\n3\n1\n1\n3\n\nELPMAS\n",
"4\n2\n4\n4\n3\n\nSAMPLE\n",
"4\n2\n4\n4\n6\n\nSBMPLE\n",
"4\n1\n0\n1\n2\n\nELPMAR\n",
"4\n1\n-1\n1\n1\n\nELPMAR\n",
"4\n4\n7\n2\n6\n\nELPM@S\n",
"4\n2\n4\n1\n3\n\nSAMPLE\n",
"4\n2\n4\n1\n3\n\nELPMAS\n",
"4\n3\n1\n1\n3\n\nELPMBS\n"
] | [
"4\n",
"3\n",
"5\n",
"6\n",
"2\n",
"1\n",
"7\n",
"4\n",
"4\n",
"3\n"
] |
CodeContests | The north country is conquered by the great shogun-sama (which means king). Recently many beautiful dice which were made by order of the great shogun-sama were given to all citizens of the country. All citizens received the beautiful dice with a tear of delight. Now they are enthusiastically playing a game with the dic... | stdin | null | 4,396 | 1 | [
"1 2\n8 8\n0 0\n0 1\n3 3\n1 2 5\n2 8 3\n0 1 2\n0 0\n2 2\n3 3\n1 2 5\n2 8 3\n0 1 2\n0 0\n1 2\n2 2\n1 2\n3 4\n0 0\n0 1\n2 3\n1 2 3\n4 5 6\n0 0\n1 2\n0 0\n"
] | [
"24\n19\n17\n6\n21\n"
] | [
"1 2\n8 8\n0 0\n0 1\n3 3\n1 2 5\n2 8 3\n0 1 2\n0 0\n2 2\n3 3\n1 2 5\n2 8 6\n0 1 2\n0 0\n1 2\n2 2\n1 2\n3 4\n0 0\n0 1\n2 3\n1 2 3\n4 5 6\n0 0\n1 2\n0 0\n",
"1 2\n8 8\n0 0\n0 1\n3 3\n1 3 5\n2 13 1\n0 1 2\n0 0\n2 2\n3 3\n1 2 4\n2 8 6\n0 1 2\n0 0\n1 2\n2 2\n1 2\n3 4\n0 0\n0 1\n2 3\n1 2 3\n4 5 6\n0 0\n1 2\n0 0\n",
"... | [
"24\n19\n23\n6\n21\n",
"24\n19\n22\n6\n21\n",
"24\n16\n22\n6\n21\n",
"24\n19\n17\n6\n21\n",
"0\n19\n22\n6\n21\n",
"24\n19\n23\n0\n21\n",
"24\n10\n22\n6\n21\n",
"24\n19\n23\n0\n22\n",
"24\n10\n22\n6\n22\n",
"24\n19\n23\n11\n21\n"
] |
CodeContests | Raju is very much interested in winning money through lotteries.
Lottery Association is organising lottery matches quite frequently.
A lottery match begins at certain time and ends at a certain time. Raju can buy ticket of certain match if he wants to bet in that match.
But according to Lottery Association, Raju can ... | stdin | null | 2,430 | 1 | [
"2\n4\n1 10 100\n10 20 100\n20 30 100\n30 40 100\n4\n1 10 50\n10 20 100\n20 30 100\n30 40 100\n\nSAMPLE\n"
] | [
"4.00\n3.50\n"
] | [
"10\n45\n269876887 287890694 61\n891455470 911442875 95\n441012503 475998809 29\n747404821 775131142 38\n442552118 456806149 54\n509333872 539796200 86\n657246639 657637257 40\n480644550 486969608 28\n709400771 743746317 29\n273903164 311272595 97\n290822372 330628530 5\n484461387 517045443 69\n486293168 525771630 ... | [
"15.06\n14.89\n14.53\n14.49\n12.52\n14.07\n18.04\n16.96\n18.14\n14.45\n",
"14.76\n12.56\n13.64\n13.86\n14.41\n17.76\n16.25\n18.15\n19.35\n17.98\n",
"4.01\n3.50\n",
"4.01\n2.50\n",
"3.01\n2.50\n",
"15.06\n14.89\n14.53\n14.49\n12.75\n14.07\n18.04\n16.96\n18.14\n14.45\n",
"3.02\n2.50\n",
"15.06\n14.89\n1... |
CodeContests | Ruchi is doing her undergrad in Maths from a reputed college in New Delhi. Recently her professor gave her a problem which is baffling her for a long time. So she asks your help.
Problem is:
Given order of n x n matrix is it possible to find two matrices such that when there corresponding elements are combined in the... | stdin | null | 3,106 | 1 | [
"1\n3\n\nSAMPLE\n"
] | [
"Yes\n"
] | [
"1\n3\n\nSAMPKE\n",
"1\n2\n\nBJEQMR\n",
"1\n5\n\nSAMPKE\n",
"1\n10\n\nSAMPKE\n",
"1\n7\n\nSAMPKE\n",
"1\n12\n\nSAMPKE\n",
"1\n3\n\nSAMPEK\n",
"1\n4\n\nSAMPEK\n",
"1\n4\n\nSKMPEA\n",
"1\n4\n\nSKMPEB\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n"
] |
CodeContests | Ignoring the air resistance, velocity of a freely falling object $v$ after $t$ seconds and its drop $y$ in $t$ seconds are represented by the following formulas:
$ v = 9.8 t $
$ y = 4.9 t^2 $
A person is trying to drop down a glass ball and check whether it will crack. Your task is to write a program to help this ex... | stdin | null | 4,708 | 1 | [
"25.4\n25.4\n"
] | [
"8\n8\n"
] | [
"26.000450676027395\n25.4\n",
"26.601491934975797\n25.4\n",
"26.840499084692592\n26.667646669726267\n",
"28.332769442919567\n26.667646669726267\n",
"30.680680649968536\n27.762964644795844\n",
"30.680680649968536\n28.560601801329888\n",
"31.609624009789687\n28.560601801329888\n",
"32.30423764671557\n29... | [
"8\n8\n",
"9\n8\n",
"9\n9\n",
"10\n9\n",
"11\n9\n",
"11\n10\n",
"12\n10\n",
"12\n11\n",
"12\n12\n",
"13\n12\n"
] |
CodeContests | Constraints
* 1 ≤ |V| ≤ 1000
* 0 ≤ |E| ≤ 2000
* -10000 ≤ di ≤ 10000
* There are no parallel edges
* There are no self-loops
Input
An edge-weighted graph G (V, E) and the source r.
|V| |E| r
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 verti... | stdin | null | 2,385 | 1 | [
"4 5 1\n0 1 2\n0 2 3\n1 2 -5\n1 3 1\n2 3 2\n",
"4 5 0\n0 1 2\n0 2 3\n1 2 -5\n1 3 1\n2 3 2\n",
"4 6 0\n0 1 2\n0 2 3\n1 2 -5\n1 3 1\n2 3 2\n3 1 0\n"
] | [
"INF\n0\n-5\n-3\n",
"0\n2\n-3\n-1\n",
"NEGATIVE CYCLE\n"
] | [
"4 5 1\n0 1 2\n0 3 3\n1 2 -5\n1 3 1\n2 3 2\n",
"4 5 0\n0 1 2\n0 2 3\n1 2 -5\n2 3 1\n2 3 2\n",
"4 6 0\n0 1 2\n0 2 3\n1 2 -5\n1 3 1\n3 3 2\n3 1 0\n",
"4 5 0\n0 1 2\n0 2 3\n1 0 -5\n2 3 1\n2 3 2\n",
"4 5 2\n0 1 2\n0 3 3\n1 2 -5\n1 3 2\n2 3 2\n",
"4 0 1\n0 0 2\n1 2 3\n2 0 -5\n2 3 1\n0 2 2\n",
"4 5 1\n0 1 2\n... | [
"INF\n0\n-5\n-3\n",
"0\n2\n-3\n-2\n",
"0\n2\n-3\n3\n",
"NEGATIVE CYCLE\n",
"INF\nINF\n0\n2\n",
"INF\n0\nINF\nINF\n",
"INF\n0\n-5\n1\n",
"0\n3\n-2\n0\n",
"0\nINF\nINF\nINF\n",
"-2\n0\n3\n0\n"
] |
CodeContests | Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on an undirected graph. An example of pseudo code of BFS is as follows:
1: $current \leftarrow \{start\_vertex\}$
2: $visited \leftarrow current$
3: while $visited \ne $ the set of all the v... | stdin | null | 3,574 | 1 | [
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"4 3\n1 2\n2 3\n3 4\n",
"3 3\n1 2\n1 3\n2 3\n",
"8 9\n2 1\n3 5\n1 6\n2 5\n3 1\n8 4\n2 7\n7 1\n7 4\n"
] | [
"-1\n",
"-1\n",
"2\n",
"3\n"
] | [
"4 4\n1 2\n2 3\n3 1\n4 1\n",
"4 3\n1 2\n2 4\n3 4\n",
"8 9\n2 1\n3 5\n1 6\n2 5\n3 1\n8 4\n2 7\n7 1\n6 4\n",
"4 4\n1 2\n2 3\n3 1\n4 2\n",
"4 4\n1 2\n2 3\n4 4\n4 1\n",
"8 9\n2 1\n6 5\n1 6\n4 5\n3 1\n8 4\n2 7\n2 1\n6 4\n",
"4 4\n1 2\n4 3\n3 1\n4 2\n",
"8 9\n2 1\n3 5\n1 6\n2 5\n3 1\n8 7\n2 7\n7 1\n7 4\n",
... | [
"3\n",
"-1\n",
"5\n",
"2\n",
"4\n",
"6\n",
"-1\n",
"3\n",
"-1\n",
"-1\n"
] |
CodeContests | You are given three strings A, B and C. Check whether they form a word chain.
More formally, determine whether both of the following are true:
* The last character in A and the initial character in B are the same.
* The last character in B and the initial character in C are the same.
If both are true, print `YES`.... | stdin | null | 298 | 1 | [
"a a a\n",
"rng gorilla apple\n",
"aaaaaaaaab aaaaaaaaaa aaaaaaaaab\n",
"yakiniku unagi sushi\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | [
"a a `\n",
"baaaa`aaaa aabaaaaaaa aaaaa`aaab\n",
"rnh gorilla apple\n",
"aaaaaaaaab aaaaaaaaaa aaaaa`aaab\n",
"ybkiniku unagi sushi\n",
"a b a\n",
"rng gorilla paple\n",
"aaaaaaaaab aaaaaaaaaa baaa`aaaaa\n",
"ybkiniku inagu sushi\n",
"a b `\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n"
] |
CodeContests | The three dice brothers are triplets, one and the same, and three can be said to be one. Since they are triplets, they are indistinguishably similar. Such three dice brothers are A's favorite toys. Mr. A is always playing with rolling dice in a set of three. As you can see, A is a toy that he enjoys playing, but in fac... | stdin | null | 1,580 | 1 | [
"4 4\n4o..\n.o3.\n.o..\n.5..\n",
"3 3\n4o.\n4o.\n4o.\n",
"6 10\n1xxxxxxxxx\no.......o.\nxxxx.xxxx4\nxoxx.xxxx.\nx....3xx..\nx..xxxxx..\n"
] | [
"3\n",
"3\n",
"34\n"
] | [
"4 4\n4o..\n.3o.\n.o..\n.5..\n",
"6 10\n1xxxxxxxxx\no.......o/\nxxxx.xxxx4\nxoxx.xxxx.\nx....3xx..\nx..xxxxx..\n",
"3 3\n.o4\n3o/\n4o.\n",
"3 3\n.o4\n2o/\n4o.\n",
"4 4\n4o..\n.3o.\n/-o.\n.5./\n",
"10 10\nxxxxxxxxx1\no.......o/\nxxxv.xxxx4\nxoxx.xxxx.\nx....3xx..\nx..xxxxx..\n",
"3 3\n4o.\n4o.\n4o/\n",
... | [
"7\n",
"34\n",
"11\n",
"9\n",
"8\n",
"35\n",
"3\n",
"6\n",
"12\n",
"52\n"
] |
CodeContests | HCII, the health committee for interstellar intelligence, aims to take care of the health of every interstellar intelligence.
Staff of HCII uses a special equipment for health checks of patients. This equipment looks like a polygon-shaped room with plenty of instruments. The staff puts a patient into the equipment, th... | stdin | null | 2,299 | 1 | [
"5 4\n0 0 20 0 20 10 0 10 1 5\n10 3 12 5 10 7 8 5\n10 5\n4 3\n0 0 10 0 10 5 0 5\n3 1 6 1 5 4\n0 0\n5 3\n0 0 10 0 10 10 0 10 3 5\n1 1 4 1 4 6\n0 0\n0 0\n"
] | [
"360.0000000\n12.6803835\n3.3722867\n"
] | [
"5 4\n0 0 20 0 20 10 0 10 1 5\n10 3 12 5 10 7 13 5\n10 5\n4 3\n0 0 10 0 10 5 0 5\n3 1 6 1 5 4\n0 0\n5 3\n0 0 10 0 10 10 0 10 3 5\n1 1 4 1 4 6\n0 0\n0 0\n",
"6 4\n0 0 20 0 20 10 0 10 1 5\n10 3 12 5 10 7 13 5\n10 5\n4 3\n0 0 10 0 10 5 0 5\n3 1 6 1 5 4\n0 0\n5 3\n0 0 10 0 10 10 0 10 3 5\n1 1 4 1 4 6\n0 0\n0 0\n",
... | [
"360.000000000\n12.680383492\n3.372286683\n",
"36.869897646\n",
"360.000000000\n12.680383492\n14.036243468\n",
"360.000000000\n12.680383492\n6.340191746\n",
"15.165535541\n",
"14.980897157\n",
"360.000000000\n12.680383492\n2.933750514\n",
"32.036386436\n",
"19.073134605\n",
"18.735192603\n"
] |
CodeContests | We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, ... | stdin | null | 374 | 1 | [
"3 3\n.#.\n###\n.#.\n",
"5 5\n.#.#\n.#.#.\n.#.#\n.#.#.\n.#.#\n",
"11 11\n...#####...\n.##.....##.\n..##.##..#\n..##.##..#\n.........#\n...###...#\n.#########.\n.#.#.#.#.#.\n.#.#.#.##\n..##.#.##..\n.##..#..##.\n",
"3 3\n.#.\n\n.#.\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n"
] | [
"3 5\n.#.\n###\n.#.\n",
"5 5\n.#.#\n.#.#.\n-#.#\n.#.#.\n.#.#\n",
"11 11\n...#####...\n.##.....##.\n..##.##..#\n..##.##..#\n.........#\n...###...#\n.#########.\n.#.#.#.#.#.\n.#.#.#.#$\n..##.#.##..\n.##..#..##.\n",
"3 6\n.#.\n###\n.#.\n",
"11 11\n...#####...\n.##.....##.\n..##.##..#\n..##.##..#\n.........#\n.... | [
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n"
] |
CodeContests | N people are waiting in a single line in front of the Takahashi Store. The cash on hand of the i-th person from the front of the line is a positive integer A_i.
Mr. Takahashi, the shop owner, has decided on the following scheme: He picks a product, sets a positive integer P indicating its price, and shows this product... | stdin | null | 2,925 | 1 | [
"15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9\n",
"3\n3\n2\n5\n"
] | [
"18\n",
"3\n"
] | [
"15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n6\n9\n",
"3\n3\n2\n10\n",
"3\n6\n2\n10\n",
"3\n6\n3\n10\n",
"3\n7\n3\n10\n",
"3\n7\n5\n10\n",
"3\n7\n9\n10\n",
"3\n7\n13\n10\n",
"15\n3\n1\n4\n1\n5\n9\n2\n11\n5\n3\n5\n8\n9\n7\n9\n",
"15\n3\n1\n1\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n6\n9\n"
] | [
"18\n",
"5\n",
"8\n",
"10\n",
"11\n",
"12\n",
"14\n",
"16\n",
"20\n",
"17\n"
] |
CodeContests | Chef changed the password of his laptop a few days ago, but he can't remember it today. Luckily, he wrote the encrypted password on a piece of paper, along with the rules for decryption.
The encrypted password is a string S consists of ASCII printable characters except space (ASCII 33 - 126, in decimal notation, the sa... | stdin | null | 4,687 | 1 | [
"4\n2\n5 3\n3 1\n5\n0\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#dd098x\n"
] | [
"3\n1800\n.001\n321.33098\n"
] | [
"4\n2\n5 3\n3 1\n5\n0\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#xd098d\n",
"4\n2\n5 3\n3 1\n5\n0\n01800.00\n0\n0.9085107376538183\n3\nx 0\nd 3\n# .\n0xd21#xd098d\n",
"4\n2\n9 3\n3 1\n5\n0\n01800.00\n0\n0.9085107376538183\n3\nx 0\nd 3\n# .\n0xd21#xd098d\n",
"4\n2\n9 3\n3 1\n5\n0\n1800.0294198888307\n0\n0.... | [
"3\n1800\n.001\n321.030983\n",
"3\n1800\n.9085107376538183\n321.030983\n",
"5\n1800\n.9085107376538183\n321.030983\n",
"5\n1800.0294198888307\n.9085107376538183\n321.030983\n",
"5\n1800.0294198888307\n.9085107376538183\nx 0\n",
"5\n1800.9099072926942\n.9085107376538183\nx 0\n",
"3\n1800.058991211277\n.0... |
CodeContests | Today is the ticket release date for Aizu Entertainment's recommended idol group "Akabeko & Koboushi". There are four types of tickets:
S seat 6000 yen
A seat 4000 yen
B seat 3000 yen
C seat 2000 yen
You, the sales manager, are excitedly waiting for the launch. Finally on sale. It's selling very well!
Shortly after ... | stdin | null | 5,059 | 1 | [
"3 10\n1 4\n4 1\n2 5\n"
] | [
"30000\n24000\n2000\n20000\n"
] | [
"3 10\n1 4\n4 1\n1 5\n",
"3 13\n1 4\n4 1\n1 5\n",
"3 13\n1 4\n1 1\n1 5\n",
"3 13\n1 4\n1 2\n1 5\n",
"2 13\n1 4\n1 2\n1 5\n",
"2 13\n1 4\n1 2\n1 3\n",
"2 13\n1 6\n1 2\n1 3\n",
"3 10\n1 0\n4 1\n2 5\n",
"3 10\n1 4\n2 1\n1 5\n",
"3 16\n1 4\n1 1\n1 5\n"
] | [
"30000\n24000\n2000\n30000\n",
"39000\n24000\n2000\n30000\n",
"39000\n24000\n6000\n30000\n",
"39000\n24000\n12000\n30000\n",
"52000\n24000\n12000\n30000\n",
"52000\n24000\n12000\n18000\n",
"52000\n36000\n12000\n18000\n",
"30000\n0\n2000\n20000\n",
"30000\n24000\n4000\n30000\n",
"48000\n24000\n6000... |
CodeContests | Problem
There are $ N $ islands and $ N-1 $ bridges in Aiz, and each island is assigned a number from $ 1 $ to $ N $. The $ i $ th bridge connects the island $ u_i $ and the island $ v_i $ in both directions, and islanders can use the bridge to move between islands. Also, there is no way to go back and forth between i... | stdin | null | 1,828 | 1 | [
"5\n4 0 4 0 0\n1 2\n1 3\n1 4\n2 5\n",
"7\n0 7 2 5 0 3 0\n1 2\n1 3\n1 4\n2 5\n3 6\n3 7\n"
] | [
"7\n",
"10\n"
] | [
"5\n4 1 4 0 0\n1 2\n1 3\n1 4\n2 5\n",
"5\n4 0 4 0 -1\n1 2\n1 3\n1 4\n2 5\n",
"5\n4 0 4 0 0\n1 2\n2 3\n1 4\n2 5\n",
"5\n4 0 4 0 -1\n1 2\n1 3\n1 4\n1 5\n",
"5\n4 1 2 0 2\n1 2\n1 3\n2 4\n2 5\n",
"5\n4 1 2 0 2\n1 4\n1 3\n2 4\n2 5\n",
"5\n4 0 4 0 -1\n1 2\n1 3\n1 4\n3 5\n",
"7\n0 7 2 9 0 3 0\n1 2\n2 3\n1 4\... | [
"7\n",
"8\n",
"5\n",
"6\n",
"3\n",
"2\n",
"4\n",
"19\n",
"9\n",
"13\n"
] |
CodeContests | For a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ which is sorted by ascending order, eliminate all equivalent elements.
Constraints
* $1 \leq n \leq 100,000$
* $-1000,000,000 \leq a_i \leq 1,000,000,000$
* $a_0 \leq a_1 \leq ... \leq a_{n-1}$
Input
A sequence is given in the following format.
$n$
$a_... | stdin | null | 2,502 | 1 | [
"4\n1 2 2 4\n"
] | [
"1 2 4\n"
] | [
"4\n0 2 2 4\n",
"4\n0 2 2 3\n",
"4\n0 2 2 2\n",
"4\n-1 2 2 2\n",
"4\n0 1 2 2\n",
"4\n0 0 0 4\n",
"4\n-1 0 2 2\n",
"4\n0 0 1 4\n",
"4\n1 2 2 3\n",
"4\n0 0 2 8\n"
] | [
"0 2 4\n",
"0 2 3\n",
"0 2\n",
"-1 2\n",
"0 1 2\n",
"0 4\n",
"-1 0 2\n",
"0 1 4\n",
"1 2 3\n",
"0 2 8\n"
] |
CodeContests | You are given a tree with N vertices numbered 1, 2, ..., N. The i-th edge connects Vertex a_i and Vertex b_i. You are also given a string S of length N consisting of `0` and `1`. The i-th character of S represents the number of pieces placed on Vertex i.
Snuke will perform the following operation some number of times:... | stdin | null | 1,048 | 1 | [
"7\n0010101\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n",
"7\n0010110\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n",
"2\n01\n1 2\n"
] | [
"3\n",
"-1\n",
"0\n"
] | [
"2\n01\n2 2\n",
"7\n0011101\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n",
"7\n0111101\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n",
"7\n0110110\n1 1\n2 3\n1 4\n1 5\n2 6\n6 7\n",
"7\n0110110\n1 2\n2 3\n1 4\n1 5\n2 6\n6 7\n",
"7\n0010101\n1 2\n4 3\n1 4\n4 5\n1 6\n6 7\n",
"2\n01\n2 0\n",
"2\n2\n2 0\n",
"2\n4\n2 0\n",
"2\n4\... | [
"0\n",
"-1\n",
"4\n",
"1\n",
"2\n",
"3\n",
"0\n",
"0\n",
"0\n",
"0\n"
] |
CodeContests | C: Digital Clock
story
Aizu Nyan has recently caught a cold. I can't get out of bed because I'm too lazy. The spicy appearance is also cute.
However, Aizu Nyan, who had no choice but to spare time, came up with a way to play with the digital clock under the pillow. The number of glowing bars of a digital clock as sh... | stdin | null | 1,545 | 1 | [
"28\n0\n"
] | [
"1\n"
] | [
"28\n000\n",
"28\n000\n"
] | [
"1\n",
"1\n"
] |
CodeContests | In the year 2xxx, an expedition team landing on a planet found strange objects made by an ancient species living on that planet. They are transparent boxes containing opaque solid spheres (Figure 1). There are also many lithographs which seem to contain positions and radiuses of spheres.
<image>
Figure 1: A strange o... | stdin | null | 2,694 | 1 | [
"3\n95 20 180 18\n125 20 185 18\n40 27 195 10\n1\n5 5 5 4\n2\n5 5 5 4\n5 5 5 3\n2\n5 5 5 4\n5 7 5 3\n16\n2338 3465 29034 710\n1571 14389 25019 842\n1706 8015 11324 1155\n1899 4359 33815 888\n2160 10364 20511 1264\n2048 8835 23706 1906\n2598 13041 23679 618\n1613 11112 8003 1125\n1777 4754 25986 929\n2707 9945 11458... | [
"8\n11011000\n2\n10\n2\n10\n2\n10\n28\n1011100100110101101000101100\n"
] | [
"3\n95 20 180 18\n125 20 185 18\n40 27 195 10\n1\n5 5 5 4\n2\n5 5 5 4\n5 5 5 3\n2\n5 5 5 4\n5 7 5 3\n16\n2338 3465 29034 710\n1571 14389 25019 842\n1706 8015 11324 1155\n1899 4359 33815 888\n2160 10364 20511 1264\n2048 8835 23706 1906\n2598 3176 23679 618\n1613 11112 8003 1125\n1777 4754 25986 929\n2707 9945 11458 ... | [
"8\n11011000\n2\n10\n2\n10\n2\n10\n28\n1011100100110101101000101100\n",
"8\n11011000\n2\n10\n2\n10\n2\n10\n30\n101110010011010101101000101100\n",
"8\n11011000\n2\n10\n2\n10\n2\n10\n32\n10111001001101010110100101001100\n",
"8\n11011000\n2\n10\n2\n10\n2\n10\n30\n101110010011010101101001001100\n",
"8\n11011000... |
CodeContests | You are given an array A of size N, and Q queries to deal with. For each query, you are given an integer X, and you're supposed to find out if X is present in the array A or not.
Input:
The first line contains two integers, N and Q, denoting the size of array A and number of queries. The second line contains N space s... | stdin | null | 6 | 1 | [
"5 10\n50 40 30 20 10\n10\n20\n30\n40\n50\n60\n70\n80\n90\n100\n\nSAMPLE\n"
] | [
"YES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\n"
] | [
"100 10000\n337491026 878382762 942177429 998998997 292784016 407647544 813626083 20338593 191780719 781848699 64249580 610506520 697548073 793260253 627296562 144951458 542499902 395006034 635349920 343021549 226012154 335095984 527123886 239116176 349402179 858020247 508958550 686994126 225913467 481444398 993957... | [
"YES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO... |
CodeContests | Nimbus, the techical festival of NIT Hanirpur is coming and thus Arun, the core-cordinator of departmental team of CSE, decided a conduct a game. In this game, the participant will be given a natural number N and will be asked T questions of form Type K.
Here Type denotes the type of question asked and K denotes a nat... | stdin | null | 4,730 | 1 | [
"12 6\n1 6\n1 14\n2 4\n2 3\n3 12\n3 14\n\nSAMPLE\n"
] | [
"4\n2\n2\n3\n5\n6\n"
] | [
"12 6\n1 6\n1 14\n4 4\n2 3\n3 12\n3 14\n\nSAMPLE\n",
"5 6\n1 6\n1 14\n4 4\n2 3\n3 12\n3 14\n\nSAMPLE\n",
"5 6\n1 6\n2 14\n4 6\n2 3\n3 12\n3 14\n\nSAMPLE\n",
"5 6\n1 6\n2 7\n4 6\n3 3\n3 12\n3 14\n\nSAMPLE\n",
"12 6\n1 6\n1 14\n2 4\n2 3\n3 12\n3 11\n\nSAMPLE\n",
"5 6\n1 6\n4 7\n4 6\n2 3\n3 12\n3 14\n\nSAMPL... | [
"4\n2\n4\n3\n5\n6\n",
"1\n1\n2\n0\n2\n2\n",
"1\n0\n2\n0\n2\n2\n",
"1\n0\n2\n2\n2\n2\n",
"4\n2\n2\n3\n5\n6\n",
"1\n2\n2\n0\n2\n2\n",
"2\n0\n2\n2\n2\n2\n",
"4\n2\n",
"4\n2\n4\n6\n5\n6\n",
"1\n1\n0\n0\n2\n2\n"
] |
CodeContests | Platypus Perry is on a mission again. This time, Dr. Heinz Doofenshmirtz has plotted a bomb in the centre of Danville town. He wishes to rebuild the town.
We need to defuse the bomb for Perry. As always, Dr. Heinz has given perry the key combination to defuse the bomb, but unfortunately Perry has not been able to get ... | stdin | null | 1,273 | 1 | [
"1\n98765 23\n\nSAMPLE\n"
] | [
"2254\n2001\n1748\n1495\n"
] | [
"2\n987654321 123\n101985221 22\n",
"1\n47242 23\n\nSAMPLE\n",
"2\n987654321 123\n184032096 22\n",
"2\n918674826 123\n184032096 22\n",
"1\n33342 23\n\nELPMAS\n",
"2\n1279346303 123\n184032096 22\n",
"1\n33342 30\n\nELPMAS\n",
"2\n1279346303 123\n184032096 38\n",
"1\n17816 30\n\nELPMAS\n",
"2\n1279... | [
"121401\n107748\n94095\n80442\n66789\n53136\n39483\n220\n22\n418\n2156\n1870\n1144\n484\n462\n",
"1081\n1656\n552\n966\n",
"121401\n107748\n94095\n80442\n66789\n53136\n39483\n396\n1848\n880\n66\n704\n440\n198\n2112\n",
"112914\n22878\n106641\n82902\n92004\n59286\n101598\n396\n1848\n880\n66\n704\n440\n198\n211... |
CodeContests | You will participate in the ski competition held on Mt. Bandai. In this competition, each player slides down the slope twice and competes for the short total time. There are several flags on the slopes, and a line is set between them for athletes to pass through. Athletes slide down the line from the start point to the... | stdin | null | 619 | 1 | [
"4 5\n1 2 3 5\n1 3 1 3\n3 2 2 5\n2 4 6 1\n3 4 5 5\n",
"3 3\n1 2 1 2\n2 3 1 2\n1 3 1 3\n",
"3 3\n1 2 1 2\n2 3 1 2\n1 3 1 1\n"
] | [
"13\n",
"3\n",
"2\n"
] | [
"3 3\n1 2 1 2\n2 3 0 2\n1 3 1 1\n",
"4 5\n1 2 3 5\n1 3 1 3\n3 2 2 5\n2 4 9 1\n3 4 5 5\n",
"3 3\n1 2 1 2\n2 3 0 2\n1 3 1 0\n",
"3 3\n1 2 1 2\n2 3 0 2\n1 3 0 0\n",
"3 3\n1 2 2 2\n2 3 0 1\n1 3 1 2\n",
"4 5\n1 2 4 5\n1 3 1 3\n3 2 2 5\n2 4 6 0\n3 4 5 5\n",
"4 5\n1 2 1 5\n1 3 1 3\n3 2 2 5\n2 4 6 0\n3 4 5 5\n"... | [
"2\n",
"14\n",
"1\n",
"0\n",
"3\n",
"13\n",
"10\n",
"9\n",
"16\n",
"15\n"
] |
CodeContests | AtCoDeer the deer found N rectangle lying on the table, each with height 1. If we consider the surface of the desk as a two-dimensional plane, the i-th rectangle i(1≤i≤N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i], as shown in the following figure:
<image>
AtCoDeer will move these rect... | stdin | null | 1,053 | 1 | [
"3\n2 5\n4 6\n1 4\n",
"5\n123456 789012\n123 456\n12 345678901\n123456 789012\n1 23\n",
"3\n1 3\n5 7\n1 3\n",
"1\n1 400\n",
"5\n999999999 1000000000\n1 2\n314 315\n500000 500001\n999999999 1000000000\n"
] | [
"0\n",
"246433\n",
"2\n",
"0\n",
"1999999680\n"
] | [
"3\n2 5\n4 6\n2 4\n",
"5\n123456 789012\n17 456\n12 345678901\n123456 789012\n1 23\n",
"3\n1 3\n5 8\n1 3\n",
"5\n999999999 1000000000\n1 2\n314 70\n500000 500001\n999999999 1000000000\n",
"5\n123456 789012\n17 456\n12 345678901\n40029 789012\n1 23\n",
"3\n1 3\n8 8\n1 3\n",
"5\n999999999 1000000000\n1 2\... | [
"0\n",
"246433\n",
"2\n",
"1999999925\n",
"163006\n",
"5\n",
"1999999889\n",
"1\n",
"1999999891\n",
"162898\n"
] |
CodeContests | Takahashi has two positive integers A and B.
It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
Constraints
* 2 ≤ N ≤ 10^5
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Outp... | stdin | null | 2,521 | 1 | [
"15\n",
"100000\n"
] | [
"6\n",
"10\n"
] | [
"22\n",
"37\n",
"36\n",
"3\n",
"5\n",
"7\n",
"26\n",
"38\n",
"58\n",
"78\n"
] | [
"4\n",
"10\n",
"9\n",
"3\n",
"5\n",
"7\n",
"8\n",
"11\n",
"13\n",
"15\n"
] |
CodeContests | Mr. Hoge is in trouble. He just bought a new mansion, but it’s haunted by a phantom. He asked a famous conjurer Dr. Huga to get rid of the phantom. Dr. Huga went to see the mansion, and found that the phantom is scared by its own mirror images. Dr. Huga set two flat mirrors in order to get rid of the phantom.
As you m... | stdin | null | 2,260 | 1 | [
"4 4\n3 3 5 3\n3 5 5 6\n4 4\n3 3 5 3\n3 5 5 5\n0 0\n"
] | [
"4\nTOO MANY\n"
] | [
"4 4\n3 3 5 3\n3 5 5 6\n4 4\n3 3 5 3\n3 5 8 5\n0 0\n",
"4 4\n3 6 5 3\n3 5 5 6\n4 4\n3 3 5 3\n3 5 8 5\n0 0\n",
"4 4\n3 6 5 3\n3 5 5 6\n4 2\n3 3 5 3\n3 5 8 5\n0 0\n",
"4 5\n3 6 5 3\n3 5 5 6\n4 2\n5 3 5 3\n3 5 8 5\n0 0\n",
"4 4\n3 3 5 3\n3 9 5 6\n4 4\n3 3 5 3\n3 5 5 5\n0 0\n",
"4 5\n3 6 2 3\n3 5 5 6\n4 2\n5 ... | [
"4\nTOO MANY\n",
"2\nTOO MANY\n",
"2\n1\n",
"4\n1\n",
"1\nTOO MANY\n",
"1\n1\n",
"TOO MANY\n1\n",
"1\n0\n",
"4\n4\n",
"4\n6\n"
] |
CodeContests | When you enter 8 numbers from 0 to 9, write a program that outputs the difference between the largest integer and the smallest integer that can sort the 8 numbers. The number that can be sorted may start from 0, such as 00135569.
Input
Given multiple datasets. The number of datasets n (n ≤ 50) is given on the first... | stdin | null | 2,769 | 1 | [
"2\n65539010\n65539010\n"
] | [
"96417531\n96417531\n"
] | [
"2\n65539010\n102034250\n",
"2\n65539010\n31390532\n",
"2\n65539010\n31927280\n",
"2\n65539010\n40089442\n",
"2\n65539010\n45258123\n",
"2\n65539010\n53937586\n",
"2\n65539010\n66277190\n",
"2\n124008976\n66277190\n",
"2\n188122632\n66277190\n",
"2\n169123376\n66277190\n"
] | [
"96417531\n543098655\n",
"96417531\n94099851\n",
"96417531\n97508421\n",
"96417531\n98199711\n",
"96417531\n73308663\n",
"96417531\n65208744\n",
"96417531\n96499431\n",
"986395311\n96499431\n",
"774098523\n96499431\n",
"864296532\n96499431\n"
] |
CodeContests | Nathan O. Davis is a student at the department of integrated systems. Today he learned digital quanti- zation in a class. It is a process that approximates analog data (e.g. electrical pressure) by a finite set of discrete values or integers.
He had an assignment to write a program that quantizes the sequence of real ... | stdin | null | 72 | 1 | [
"5 2 1\n0.1 0.2 0.3 0.4 0.5\n6 2 2\n0.1 0.2 0.3 0.4 0.5 0.6\n0 0 0\n"
] | [
"0.01\n0.00\n"
] | [
"5 2 1\n0.1 0.2 0.3 0.5915213038191143 0.5\n6 2 2\n0.1 0.2 0.3 0.4 0.5 0.6\n0 0 0\n",
"5 2 1\n0.1 0.3034585214713487 0.3 0.5915213038191143 0.5\n6 2 2\n0.1 0.2 0.3 0.4 0.5 0.6\n0 0 0\n",
"5 2 1\n0.1 0.3034585214713487 1.0488885934387808 0.5915213038191143 0.5\n6 2 2\n0.1 0.2 0.48010372072768065 0.4 1.3195412798... | [
"0.00837615\n0.00000000\n",
"0.00001196\n0.00000000\n",
"0.00837615\n0.00288429\n",
"0.00837615\n0.00116847\n",
"0.02465713\n0.00116847\n",
"0.01000000\n0.00000000\n",
"0.00001196\n0.00052294\n",
"0.00837615\n0.00071042\n",
"0.00837615\n0.00024093\n",
"0.02465713\n0.00000000\n"
] |
CodeContests | Little Deepu and Little Kuldeep are world renowned criminals. But, they are not bad people at heart. (Oh, they are...) Anyway, their occupation is to smuggle drugs from one place to another. And both of them are partners in this occupation of theirs. But, now Little Deepu is an amateur drug seller, while Little Kuld... | stdin | null | 2,351 | 1 | [
"3\n3\n1\n2\n3\n4\n2\n2\n2\n2\n3\n11\n111\n1111\n\nSAMPLE\n"
] | [
"1\n4\n1\n"
] | [
"3\n3\n0\n2\n3\n4\n2\n2\n2\n2\n3\n11\n111\n1111\n\nSAMPLE\n",
"3\n3\n0\n2\n3\n4\n2\n2\n2\n1\n3\n11\n111\n1111\n\nSAMPLE\n",
"3\n3\n0\n2\n3\n4\n0\n2\n2\n1\n3\n0\n111\n1111\n\nSAMPLE\n",
"3\n2\n0\n2\n3\n4\n0\n2\n2\n1\n3\n0\n111\n1111\n\nSAMPLE\n",
"3\n2\n1\n0\n3\n4\n2\n3\n2\n1\n1\n0\n001\n1111\n\nRAMPLE\n",
... | [
"1\n4\n1\n",
"1\n3\n1\n",
"1\n2\n1\n",
"1\n1\n1\n",
"1\n1\n2\n",
"2\n4\n1\n",
"2\n1\n1\n",
"3\n2\n1\n",
"2\n2\n1\n",
"3\n1\n1\n"
] |
CodeContests | Let x be a string of length at least 1. We will call x a good string, if for any string y and any integer k (k \geq 2), the string obtained by concatenating k copies of y is different from x. For example, `a`, `bbc` and `cdcdc` are good strings, while `aa`, `bbbb` and `cdcdcd` are not.
Let w be a string of length at l... | stdin | null | 4,350 | 1 | [
"ddd\n",
"aab\n",
"bcbc\n"
] | [
"3\n1\n",
"1\n1\n",
"2\n3\n"
] | [
"ddc\n",
"aaa\n",
"adad\n",
"bbcc\n",
"dec\n",
"aa`\n",
"ccbb\n",
"eec\n",
"aa_\n",
"ccbc\n"
] | [
"1\n1\n",
"3\n1\n",
"2\n3\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n"
] |
CodeContests | Quan_Lank loves awsome numbers. Awsome numbers are the positive integers whose decimal representations contain only the awsome digits 4 and 7. For example, numbers 7, 74, 4 are awsome and 5, 137, 4467 are not. Unfortunately, not all numbers are awsome. Quan_Lank calls a number nearly awsome if the number of awsome digi... | stdin | null | 2,195 | 1 | [
"2\n40047\n4777\n\nSAMPLE\n"
] | [
"NO\nYES\n"
] | [
"2\n54145\n4777\n",
"2\n40047\n5670\n\nSAMPLE\n",
"34\n40047\n1530500\n1000000000000000000\n7\n4\n474404774\n4744000695826\n10000000004744744\n446486416781684178\n999999999\n7777\n87414417444\n111222333444555667\n1\n4700\n3794555488744477\n444444444444444444\n474447447774444774\n777777777777777\n347777450210000... | [
"NO\nYES\n",
"NO\nNO\n",
"NO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nYES\nYES\nNO\n",
"NO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nNO\nN... |
CodeContests | A: four tea
problem
Tea is indispensable for programming contests. Tea has the effect of relieving constant tension [citation needed]
There are N players participating in the contest, so I would like to prepare tea for this number of people. There are four types of tea packages, A, B, C, and D, all of which are the ... | stdin | null | 4,955 | 1 | [
"10\n1 2 3 4\n1 2 4 8\n"
] | [
"6\n"
] | [
"10\n1 2 3 2\n1 2 4 8\n",
"10\n1 1 3 2\n0 2 3 8\n",
"10\n1 1 3 2\n0 2 3 16\n",
"10\n0 1 3 2\n1 2 3 16\n",
"10\n1 2 3 4\n1 3 4 8\n",
"10\n1 1 3 2\n0 2 3 1\n",
"10\n0 1 6 1\n0 0 1 50\n",
"10\n0 2 1 4\n0 1 0 8\n",
"10\n1 2 3 2\n0 0 4 3\n",
"10\n1 1 6 2\n1 1 2 1\n"
] | [
"4\n",
"3\n",
"2\n",
"0\n",
"6\n",
"5\n",
"1\n",
"8\n",
"7\n",
"10\n"
] |
CodeContests | Example
Input
2 10
10 200 1
10 100 100
Output
200 | stdin | null | 4,876 | 1 | [
"2 10\n10 200 1\n10 100 100\n"
] | [
"200\n"
] | [
"2 10\n10 200 1\n10 100 101\n",
"2 10\n10 137 1\n10 100 101\n",
"0 10\n10 200 0\n10 100 100\n",
"2 10\n6 331 1\n0 110 100\n",
"3 10\n1 349 1\n16 100 101\n",
"2 10\n6 554 1\n0 100 100\n",
"1 10\n1 470 -1\n15 101 101\n",
"2 10\n6 28 1\n10 100 101\n",
"3 10\n6 318 1\n10 100 101\n",
"3 10\n6 121 1\n10... | [
"200\n",
"137\n",
"0\n",
"331\n",
"349\n",
"554\n",
"470\n",
"100\n",
"318\n",
"121\n"
] |
CodeContests | Tic-Tac-Toe are three cousins. They are playing a game on Fibonacci numbers. The rule of the game is simple -
If the sum of Non-Fibonacci numbers upto N is prime, Tic wins.
If the sum of Non-Fibonacci numbers upto N is even, Tac wins.
If the sum of Non-Fibonacci numbers upto N is odd and not prime, Toe wins.
Fibonacci... | stdin | null | 2,005 | 1 | [
"5\n91\n12\n135\n7\n66\n\nSAMPLE\n"
] | [
"Tac\nTic\nTac\nTac\nTic\n"
] | [
"20\n359\n957\n567\n344\n648\n861\n133\n115\n631\n126\n172\n413\n349\n549\n969\n498\n429\n311\n313\n130\n",
"5\n91\n12\n212\n7\n66\n\nSAMPLE\n",
"20\n359\n957\n567\n344\n648\n861\n133\n115\n631\n20\n172\n413\n349\n414\n969\n498\n429\n311\n313\n130\n",
"20\n359\n957\n567\n149\n648\n861\n133\n115\n631\n20\n172\... | [
"Toe\nToe\nTac\nTac\nToe\nToe\nToe\nTac\nTac\nTac\nToe\nToe\nTac\nTic\nToe\nTac\nTic\nToe\nTac\nTac\n",
"Tac\nTic\nTic\nTac\nTic\n",
"Toe\nToe\nTac\nTac\nToe\nToe\nToe\nTac\nTac\nTac\nToe\nToe\nTac\nTac\nToe\nTac\nTic\nToe\nTac\nTac\n",
"Toe\nToe\nTac\nTic\nToe\nToe\nToe\nTac\nTac\nTac\nToe\nToe\nTac\nTac\nTo... |
CodeContests | Snuke has a board with an N \times N grid, and N \times N tiles.
Each side of a square that is part of the perimeter of the grid is attached with a socket. That is, each side of the grid is attached with N sockets, for the total of 4 \times N sockets. These sockets are labeled as follows:
* The sockets on the top sid... | stdin | null | 2,728 | 1 | [
"2\n2 0\n2 0\n0 0\n0 0\n",
"3\n0 0 1\n1 1 0\n3 0 1\n0 1 1\n"
] | [
"NO\n",
"L1\nL1\nL1\nL3\nD1\nR2\nU3\nR3\nD2\n"
] | [
"2\n2 0\n0 0\n0 0\n0 0\n",
"2\n2 2\n0 0\n0 0\n0 0\n",
"2\n2 0\n0 0\n0 0\n-1 0\n",
"2\n4 0\n0 0\n0 0\n-1 0\n",
"2\n4 0\n1 0\n0 0\n-1 0\n",
"2\n3 0\n1 0\n0 0\n-1 0\n",
"2\n3 0\n1 0\n0 0\n-2 0\n",
"2\n3 0\n1 0\n0 -1\n-2 0\n",
"2\n3 0\n1 0\n0 -1\n-4 0\n",
"2\n3 1\n1 0\n0 -1\n-4 0\n"
] | [
"NO\n",
"U1\nU2\nU1\nU2\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n"
] |
CodeContests | problem
There are fine icicles under the eaves of JOI's house in Canada. Because of this, JOI decided to investigate the icicles.
There are N (2 ≤ N ≤ 100000 = 105) icicles under the eaves of JOI's house. These icicles are aligned and i cm (1 ≤ i ≤ N) from the left edge of the eaves. There are i-th icicles at the pos... | stdin | null | 4,551 | 1 | [
"4 6\n4\n2\n3\n5\n"
] | [
"8\n"
] | [
"4 6\n7\n2\n3\n5\n",
"4 6\n4\n1\n3\n5\n",
"1 6\n4\n2\n3\n1\n",
"4 10\n7\n1\n3\n5\n",
"4 11\n5\n2\n3\n5\n",
"4 5\n4\n2\n3\n1\n",
"1 6\n3\n2\n3\n1\n",
"1 6\n2\n2\n3\n1\n",
"4 9\n7\n2\n3\n5\n",
"1 6\n1\n0\n1\n1\n"
] | [
"8\n",
"9\n",
"2\n",
"21\n",
"23\n",
"6\n",
"3\n",
"4\n",
"17\n",
"5\n"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.