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
Selection of Participants of an Experiment Dr. Tsukuba has devised a new method of programming training. In order to evaluate the effectiveness of this method, he plans to carry out a control experiment. Having two students as the participants of the experiment, one of them will be trained under the conventional metho...
stdin
null
1,062
1
[ "5\n10 10 10 10 10\n5\n1 5 8 9 11\n7\n11 34 83 47 59 29 70\n0\n" ]
[ "0\n1\n5\n" ]
[ "5\n10 10 1 10 10\n5\n1 5 8 9 11\n7\n11 34 83 47 59 29 70\n0\n", "5\n10 10 1 10 10\n5\n1 5 8 9 11\n7\n11 34 83 47 59 29 48\n0\n", "5\n10 10 1 10 10\n5\n1 5 8 5 11\n7\n11 34 83 47 59 29 48\n0\n", "5\n10 10 1 10 10\n5\n1 5 8 5 11\n7\n11 34 83 47 54 29 2\n0\n", "5\n10 10 10 10 10\n5\n1 5 8 9 11\n7\n11 34 83 47...
[ "0\n1\n5\n", "0\n1\n1\n", "0\n0\n1\n", "0\n0\n5\n", "0\n1\n3\n", "0\n0\n", "0\n0\n0\n", "0\n2\n3\n", "0\n1\n2\n", "0\n2\n" ]
CodeContests
Raju and Rani and playing games in the school. Raju has recently learned how to draw angles. He knows how to draw some angles. He also can add/subtract any of the two angles he draws. Rani now wants to test Raju. Input: First line contains N and K, denoting number of angles Raju knows how to draw and K the number...
stdin
null
2,789
1
[ "1 2\n100\n60 70\n\nSAMPLE\n" ]
[ "YES\nNO\n" ]
[ "1 2\n100\n60 112\n\nSAMPLE\n", "6 10\n202 354 122 286 138 46\n42 266 181 4 203 246 227 153 68 346\n", "4 5\n120 304 184 200\n331 352 194 208 332\n", "1 3\n260\n4 353 248\n", "6 10\n202 354 122 286 138 46\n69 266 181 4 203 246 227 153 68 346\n", "1 2\n100\n44 17\n\nRAMPLE\n", "6 10\n202 354 122 286 182 ...
[ "YES\nNO\n", "YES\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nYES\nYES\n", "NO\nYES\nNO\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nYES\nYES\n", "NO\nNO\n", "NO\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nYES\nYES\n", "NO\nYES\nYES\n", "NO\nYES\nNO\nYES\nNO\nYES\nYES\nNO\nYES\nYES\n", "NO\nYES\nYES\...
CodeContests
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and...
stdin
null
1,052
1
[ "1 999 1000\n", "5 2 7\n" ]
[ "A\n", "B\n" ]
[ "1 999 0000\n", "1 381 1110\n", "5 1 7\n", "1 999 0100\n", "10 1 7\n", "1 999 0101\n", "10 2 7\n", "1 999 0001\n", "10 1 9\n", "1 381 0001\n" ]
[ "B\n", "A\n", "B\n", "B\n", "B\n", "B\n", "B\n", "B\n", "B\n", "B\n" ]
CodeContests
Mohan and his friends got bore so they decided to play something which help them to improve their Mental Math as exams are near by.So all of them frame their own questions for the game. But when Mohan asked his question none his friends was able to answer it so now they asked you for the help you have to tell the lar...
stdin
null
2,001
1
[ "1\n8 4 0 0\n\nSAMPLE\n" ]
[ "4\n" ]
[ "1\n8 4 1 0\n\nSAMPLE\n", "1\n12 4 2 0\n\nELPMAS\n", "1\n5 4 1 0\n\nELPM@S\n", "1\n13 4 1 1\n\nELPMAS\n", "1\n8 5 -2 0\n\nELPMAS\n", "1\n8 5 -4 -1\n\nELPSAM\n", "1\n13 20 3 0\n\nSAMPLD\n", "1\n15 9 6 0\n\nTAMPJE\n", "1\n1 15 -7 -1\n\nEMQTAM\n", "1\n2 0 -5 -7\n\nFMQATL\n" ]
[ "1\n", "2\n", "4\n", "3\n", "5\n", "6\n", "10\n", "9\n", "8\n", "7\n" ]
CodeContests
You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$ as a subset. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a ...
stdin
null
2,345
1
[ "4\n2 0 2\n" ]
[ "5: 0 2\n7: 0 1 2\n13: 0 2 3\n15: 0 1 2 3\n" ]
[ "4\n2 1 2\n", "4\n2 1 3\n", "4\n0 0 2\n", "4\n1 1 2\n", "4\n1 0 2\n", "4\n2 1 0\n", "4\n1 2 0\n", "4\n2 0 3\n", "4\n2 2 0\n", "4\n1 3 2\n" ]
[ "6: 1 2\n7: 0 1 2\n14: 1 2 3\n15: 0 1 2 3\n", "10: 1 3\n11: 0 1 3\n14: 1 2 3\n15: 0 1 2 3\n", "0:\n1: 0\n2: 1\n3: 0 1\n4: 2\n5: 0 2\n6: 1 2\n7: 0 1 2\n8: 3\n9: 0 3\n10: 1 3\n11: 0 1 3\n12: 2 3\n13: 0 2 3\n14: 1 2 3\n15: 0 1 2 3\n", "2: 1\n3: 0 1\n6: 1 2\n7: 0 1 2\n10: 1 3\n11: 0 1 3\n14: 1 2 3\n15: 0 1 2 3\n"...
CodeContests
Given is a permutation P of \\{1, 2, \ldots, N\\}. For a pair (L, R) (1 \le L \lt R \le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R. Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}. Constraints * 2 \le N \le 10^5 * 1 \le P_i \le N * P_i \neq P_j (i \neq j) * All values...
stdin
null
3,154
1
[ "5\n1 2 3 4 5\n", "3\n2 3 1\n", "8\n8 2 7 3 4 5 6 1\n" ]
[ "30\n", "5\n", "136\n" ]
[ "3\n1 3 2\n", "3\n3 1 2\n", "5\n1 3 2 4 5\n", "5\n2 3 1 4 5\n", "8\n8 1 7 3 4 5 6 2\n", "3\n3 2 1\n", "3\n2 1 3\n", "3\n1 2 3\n", "3\n1 3 2\n", "3\n1 2 3\n" ]
[ "5\n", "4\n", "29\n", "28\n", "135\n", "5\n", "4\n", "5\n", "5\n", "5\n" ]
CodeContests
We have a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n}. Print the number of elements p_i (1 < i < n) that satisfy the following condition: * p_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}. Constraints * All values in input are integers. * 3 \leq n \leq 20 * p...
stdin
null
2,245
1
[ "9\n9 6 3 2 5 8 7 4 1\n", "5\n1 3 5 4 2\n" ]
[ "5\n", "2\n" ]
[ "9\n9 6 3 2 5 14 7 4 1\n", "5\n2 3 5 4 2\n", "9\n14 17 3 4 5 25 7 4 0\n", "5\n2 1 5 4 2\n", "9\n14 12 3 2 9 14 1 4 0\n", "5\n2 6 4 8 3\n", "9\n14 6 3 2 5 14 7 4 1\n", "9\n14 6 3 2 5 14 7 4 0\n", "9\n14 12 3 2 5 14 7 4 0\n", "9\n14 12 3 2 5 14 7 4 -1\n" ]
[ "5\n", "2\n", "4\n", "1\n", "3\n", "0\n", "5\n", "5\n", "5\n", "5\n" ]
CodeContests
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when ...
stdin
null
3,118
1
[ "10\naaaaaaaaaa\n", "6\naabbca\n", "45\ntgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir\n" ]
[ "1\n", "2\n", "9\n" ]
[ "10\naaabaaaaaa\n", "6\n`abbca\n", "45\ntgxgdqkyjphyzutjjtllptdfxocrylqfqjynmfbfucbir\n", "45\ntgxgtqkyjfhyzutjjdllptdpxrbrylqfqjynmfbfucbio\n", "45\nbnxgtqkykfhyzutjjdllptdpxrtrylqfqjygmfbftcbio\n", "10\naba`ab`bbb\n", "10\n`bcca_ba_`\n", "45\nblxhtqkyjehxzutkjdmlpidpurtrzlbfribgmhqfzcyto\n", "45\n...
[ "1\n", "2\n", "9\n", "10\n", "11\n", "3\n", "4\n", "12\n", "8\n", "0\n" ]
CodeContests
We have N integers. The i-th number is A_i. \\{A_i\\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N. \\{A_i\\} is said to be setwise coprime when \\{A_i\\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1. Determine if \\{A_i\\} is pairwise coprime, setw...
stdin
null
134
1
[ "3\n6 10 16\n", "3\n6 10 15\n", "3\n3 4 5\n" ]
[ "not coprime\n", "setwise coprime\n", "pairwise coprime\n" ]
[ "3\n6 5 15\n", "3\n4 4 2\n", "3\n4 3 1\n", "3\n4 4 5\n", "3\n4 8 2\n", "3\n8 8 2\n", "3\n4 4 1\n", "3\n4 4 4\n", "3\n6 8 2\n", "3\n7 4 4\n" ]
[ "setwise coprime\n", "not coprime\n", "pairwise coprime\n", "setwise coprime\n", "not coprime\n", "not coprime\n", "setwise coprime\n", "not coprime\n", "not coprime\n", "setwise coprime\n" ]
CodeContests
In Aizu prefecture, we decided to create a new town to increase the population. To that end, we decided to cultivate a new rectangular land and divide this land into squares of the same size. The cost of developing this land is proportional to the number of plots, but the prefecture wants to minimize this cost. Create...
stdin
null
4,828
1
[ "27 6 1\n", "10 20 5\n" ]
[ "18\n", "10\n" ]
[ "9 6 1\n", "10 20 9\n", "10 20 16\n", "4 11 1\n", "8 20 16\n", "6 11 1\n", "8 20 11\n", "3 11 1\n", "2 1 11\n", "3 3 1\n" ]
[ "6\n", "18\n", "32\n", "44\n", "160\n", "66\n", "110\n", "33\n", "22\n", "1\n" ]
CodeContests
Find the area of intersection between a circle $c$ and a polygon $g$. The center coordinate of the circle is ($0, 0$). The polygon $g$ is represented by a sequence of points $p_1$, $p_2$,..., $p_n$ where line segments connecting $p_i$ and $p_{i+1}$ ($1 \leq i \leq n−1$) are sides of the polygon. The line segment conne...
stdin
null
991
1
[ "4 5\n0 0\n-3 -6\n1 -3\n5 -4\n", "3 5\n1 1\n4 1\n5 5\n" ]
[ "11.787686807576\n", "4.639858417607\n" ]
[ "4 5\n0 0\n-3 -5\n1 -3\n5 -4\n", "3 5\n1 1\n4 1\n8 5\n", "4 8\n0 0\n-3 -5\n1 -3\n5 -4\n", "3 8\n1 1\n4 1\n8 5\n", "4 8\n-1 0\n-3 -5\n1 -3\n5 -4\n", "3 8\n1 1\n4 2\n8 5\n", "4 8\n-1 0\n-3 -5\n1 -3\n5 -6\n", "3 8\n1 1\n8 2\n8 5\n", "4 8\n-1 0\n-3 -5\n1 -3\n10 -6\n", "3 8\n2 1\n8 2\n8 5\n" ]
[ "11.81461408\n", "3.30601148\n", "12.50000000\n", "5.72138510\n", "13.00000000\n", "2.37187120\n", "11.00000000\n", "8.49840805\n", "17.27422100\n", "7.06852713\n" ]
CodeContests
You have probably learnt chemical equations (chemical reaction formulae) in your high-school days. The following are some well-known equations. 2H2 + O2 -> 2H2O (1) Ca(OH)2 + CO2 -> CaCO3 + H2O (2) N2 + 3H2 -> 2NH3 ...
stdin
null
1,100
1
[ "N2+H2->NH3.\nNa+Cl2->NaCl.\nCa(OH)2+CO2->CaCO3+H2O.\nCaCl2+AgNO3->Ca(NO3)2+AgCl.\nC2H5OH+O2->CO2+H2O.\nC4H10+O2->CO2+H2O.\nA12B23+C34D45+ABCD->A6D7+B8C9.\nA98B+B98C+C98->A98B99C99.\nA2+B3+C5+D7+E11+F13->ABCDEF.\n.\n" ]
[ "1 3 2\n2 1 2\n1 1 1 1\n1 2 1 2\n1 3 2 3\n2 13 8 10\n2 123 33042 5511 4136\n1 1 1 1\n15015 10010 6006 4290 2730 2310 30030\n" ]
[ "N2+H2->NH3.\nNa+Cl2->NaCl.\nCa(OH)2+CO2->CaCO3+H2O.\nCaCl2+AgNO3->Ca(NO3)2+AgCl.\nC2H5OH+O2->CO2+H2O.\nC4H10+O2->CO2+H2O.\nA12B23+C34D45+ABCD->A6D7+B8C9.\nA98B+B89C+C98->A98B99C99.\nA2+B3+C5+D7+E11+F13->ABCDEF.\n.\n", "N2+H2->NH3.\nNa+Cl2->NaCl.\nCa(OH)2+CO2->CaCO3+H2O.\nCaCl2+AgNO3->Ca(NO3)2+AgCl.\nC2H5OH+O2->C...
[ "1 3 2\n2 1 2\n1 1 1 1\n1 2 1 2\n1 3 2 3\n2 13 8 10\n2 123 33042 5511 4136\n8722 9604 8713 8722\n15015 10010 6006 4290 2730 2310 30030\n", "1 3 2\n2 1 2\n1 1 1 1\n1 2 1 2\n1 4 2 3\n2 13 8 10\n2 123 33042 5511 4136\n8722 9604 8713 8722\n15015 10010 6006 4290 2730 2310 30030\n", "3 1 2\n2 1 2\n1 1 1 1\n1 2 1 2\n1...
CodeContests
After Chef successfully built a modern (L, K)-window on the attic wall he decided to expand the notion of the (L, K)-window in some other areas. Now he considers a rectangular grid that contains only zeroes and ones and has size N x M. He considers the (L, K)-window here as any submatrix of size L x K that contains onl...
stdin
null
3,140
1
[ "2\n3 2 2 1\n11\n01\n10\n3 3 2 2\n111\n101\n111\n" ]
[ "2\n5\n" ]
[ "2\n3 2 1 1\n11\n01\n10\n3 3 2 2\n111\n101\n111\n", "2\n3 2 1 1\n11\n01\n10\n3 3 2 2\n110\n101\n111\n", "2\n3 2 1 1\n11\n01\n10\n3 3 2 2\n010\n101\n111\n", "2\n3 2 1 1\n11\n01\n10\n3 3 2 2\n000\n111\n111\n", "2\n3 2 1 1\n11\n01\n10\n3 3 1 2\n000\n111\n111\n", "2\n3 2 2 1\n11\n01\n12\n3 3 2 2\n111\n101\n11...
[ "4\n5\n", "4\n2\n", "4\n1\n", "4\n3\n", "4\n6\n", "2\n5\n", "1\n2\n", "4\n4\n", "2\n2\n", "1\n5\n" ]
CodeContests
Ringo Mart, a convenience store, sells apple juice. On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new can...
stdin
null
19
1
[ "24\n1 2 3 4\n1 2 4 3\n1 3 2 4\n1 3 4 2\n1 4 2 3\n1 4 3 2\n2 1 3 4\n2 1 4 3\n2 3 1 4\n2 3 4 1\n2 4 1 3\n2 4 3 1\n3 1 2 4\n3 1 4 2\n3 2 1 4\n3 2 4 1\n3 4 1 2\n3 4 2 1\n4 1 2 3\n4 1 3 2\n4 2 1 3\n4 2 3 1\n4 3 1 2\n4 3 2 1\n", "14\n9 7 5 9\n9 7 6 9\n14 10 7 12\n14 10 8 12\n14 10 9 12\n14 10 7 11\n14 10 8 11\n14 10 9...
[ "No\nNo\nNo\nNo\nNo\nNo\nYes\nYes\nNo\nNo\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n", "No\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nYes\nNo\nNo\nYes\n" ]
[ "24\n1 2 3 4\n1 2 4 3\n1 3 2 4\n1 3 4 2\n1 4 1 3\n1 4 3 2\n2 1 3 4\n2 1 4 3\n2 3 1 4\n2 3 4 1\n2 4 1 3\n2 4 3 1\n3 1 2 4\n3 1 4 2\n3 2 1 4\n3 2 4 1\n3 4 1 2\n3 4 2 1\n4 1 2 3\n4 1 3 2\n4 2 1 3\n4 2 3 1\n4 3 1 2\n4 3 2 1\n", "14\n9 7 5 9\n9 7 6 9\n14 10 7 12\n14 10 8 12\n14 10 9 12\n14 10 7 11\n14 10 8 11\n14 10 9...
[ "No\nNo\nNo\nNo\nNo\nNo\nYes\nYes\nNo\nNo\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n", "No\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nYes\nNo\nYes\nYes\n", "No\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nNo\nYes\nNo\nYes\nYes\n", "No\nYes\nNo\nYes\nYes\nYes\nNo\nYes\nNo\nNo\nYes\nNo\nYes\nYes\n",...
CodeContests
There are N mountains ranging from east to west, and an ocean to the west. At the top of each mountain, there is an inn. You have decided to choose where to stay from these inns. The height of the i-th mountain from the west is H_i. You can certainly see the ocean from the inn at the top of the westmost mountain. F...
stdin
null
332
1
[ "4\n6 5 6 8\n", "5\n9 5 6 8 4\n", "5\n4 5 3 5 4\n" ]
[ "3\n", "1\n", "3\n" ]
[ "4\n6 5 5 8\n", "5\n9 0 6 8 4\n", "4\n6 5 8 8\n", "5\n2 3 3 4 8\n", "5\n2 3 3 4 2\n", "5\n4 5 3 1 4\n", "5\n9 -1 6 8 4\n", "5\n4 5 3 2 4\n", "4\n6 5 11 8\n", "5\n9 -1 4 8 4\n" ]
[ "2\n", "1\n", "3\n", "5\n", "4\n", "2\n", "1\n", "2\n", "2\n", "1\n" ]
CodeContests
Sandy is given an array of N integers which is a permutation of the first N natural numbers. He can swap any two elements of the array and can make at most K swaps. He needs to tell the largest permutation, in numerical order, could be made? You being sandy's friend help him in doing so. Input Format:- The first line ...
stdin
null
3,468
1
[ "5 1\n4 2 3 5 1\n\nSAMPLE\n" ]
[ "5 2 3 4 1\n" ]
[ "5 1\n4 2 3 5 1\n\nSAMOLE\n", "5 1\n4 2 3 5 0\n\nSAMPLE\n", "5 1\n2 2 3 5 0\n\nSAMPLE\n", "5 1\n3 2 3 5 0\n\nSAMPLE\n", "5 1\n4 0 3 5 1\n\nSAMPLE\n", "5 1\n2 3 3 5 0\n\nSAMPLE\n", "5 1\n3 2 1 5 0\n\nSAMPKE\n", "5 1\n4 2 2 5 1\n\nOAMSLE\n", "5 1\n3 2 3 5 1\n\nELPMAS\n", "5 1\n4 0 3 5 2\n\nSAMPEL\n"...
[ "5 2 3 4 1\n", "5 2 3 4 0\n", "5 2 3 2 0\n", "5 2 3 3 0\n", "5 0 3 4 1\n", "5 3 3 2 0\n", "5 2 1 3 0\n", "5 2 2 4 1\n", "5 2 3 3 1\n", "5 0 3 4 2\n" ]
CodeContests
Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set. Specifying the number of set elements and their sum to be k and s, respectively, sets satisfyin...
stdin
null
150
1
[ "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 10 155\n3 4 3\n4 2 11\n0 0 0\n" ]
[ "1\n2\n0\n20\n1542\n5448\n1\n0\n0\n" ]
[ "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 10 155\n3 5 3\n4 2 11\n0 0 0\n", "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 20 155\n3 5 3\n4 2 11\n0 0 0\n", "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 8 105\n20 20 155\n3 5 3\n4 2 11\n0 0 0\n", "9 3 23\n2 3 22\n10 3 28\n16 ...
[ "1\n2\n0\n20\n1542\n5448\n1\n0\n0\n", "1\n2\n0\n20\n1542\n5448\n0\n0\n0\n", "1\n2\n0\n20\n1542\n1095\n0\n0\n0\n", "1\n0\n0\n20\n1542\n1095\n0\n0\n0\n", "1\n0\n0\n20\n0\n1095\n0\n0\n0\n", "1\n2\n0\n20\n32200\n5448\n1\n0\n0\n", "0\n2\n0\n20\n1542\n1095\n0\n0\n0\n", "1\n26\n0\n20\n1542\n1095\n0\n0\n0\n",...
CodeContests
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000. a + b + c + d = n Create a program that outputs the number of combinations that satisfy the conditions. Input Given multiple datasets. Each dataset is given n on one row. Please process until the end of the inpu...
stdin
null
500
1
[ "2\n3\n35\n" ]
[ "10\n20\n8436\n" ]
[ "2\n0\n35\n", "2\n-1\n35\n", "2\n-1\n24\n", "2\n-1\n43\n", "2\n-1\n72\n", "2\n-1\n81\n", "2\n-1\n61\n", "2\n-1\n82\n", "2\n0\n82\n", "2\n-1\n59\n" ]
[ "10\n1\n8436\n", "10\n0\n8436\n", "10\n0\n2925\n", "10\n0\n15180\n", "10\n0\n67525\n", "10\n0\n95284\n", "10\n0\n41664\n", "10\n0\n98770\n", "10\n1\n98770\n", "10\n0\n37820\n" ]
CodeContests
Let's play a new board game ``Life Line''. The number of the players is greater than 1 and less than 10. In this game, the board is a regular triangle in which many small regular triangles are arranged (See Figure l). The edges of each small triangle are of the same length. <image> Figure 1: The board The size of ...
stdin
null
1,376
1
[ "4 4\n 2\n 2 3\n 1 0 4\n1 1 4 0\n4 5\n 2\n 2 3\n 3 0 4\n1 1 4 0\n4 1\n 2\n 2 3\n 3 0 4\n1 1 4 0\n4 1\n 1\n 1 1\n 1 1 1\n1 1 1 0\n4 2\n 1\n 1 1\n 1 1 1\n1 1 1 0\n4 1\n 0\n 2 2\n 5 0 7\n0 5 7 0\n4 2\n 0\n 0 3\n 1 0 4\n0 1 0 4\n4 3\n 0\n 3 3\n 3 2 3\n0 3 0 3\n4 2\n 0\n 3 3\n 3 2 3\n0 3 0 3\n...
[ "6\n5\n1\n-10\n8\n-1\n0\n1\n-1\n5\n0\n5\n", "6\n5\n1\n-10\n8\n-1\n0\n1\n-1\n5\n0\n5\n" ]
[ "4 4\n2\n2 3\n1 0 4\n1 1 4 0\n4 5\n2\n2 3\n3 0 4\n1 1 4 0\n4 1\n2\n2 3\n3 0 4\n1 1 4 0\n4 1\n1\n1 1\n1 1 1\n1 1 1 0\n4 2\n1\n1 1\n1 1 1\n1 1 1 0\n4 1\n0\n2 2\n5 0 7\n0 5 7 0\n4 2\n0\n0 3\n1 0 4\n0 1 0 4\n4 3\n0\n3 3\n3 2 3\n0 3 0 3\n4 2\n0\n3 3\n3 2 3\n0 3 0 3\n6 1\n1\n0 2\n1 1 0\n6 7 6 8\n0 7 6 8 2\n6 6 7 2 2 0\n5...
[ "6\n5\n1\n-10\n8\n-1\n0\n1\n-1\n5\n0\n5\n", "6\n5\n1\n-10\n8\n-1\n1\n1\n-1\n5\n0\n5\n", "6\n5\n1\n-10\n8\n-1\n0\n2\n-1\n5\n0\n5\n", "6\n5\n1\n-10\n8\n0\n0\n2\n-1\n5\n0\n5\n", "6\n5\n1\n-10\n8\n-1\n0\n2\n-1\n5\n0\n8\n", "6\n2\n1\n-10\n8\n-1\n1\n1\n-1\n5\n0\n5\n", "6\n5\n1\n-10\n8\n-1\n1\n2\n-1\n5\n0\n5\n...
CodeContests
Pranav just learned about Modulus(%) and trying to solve a problem on Modulus but he always get TLE. Your task is to help him. Problem is simple, you have been given two numbers A and M and you have to find A%M and print it. Input Format Firstline: T, where T is the number of test cases. Now T line followed, Where e...
stdin
null
4,734
1
[ "2\n12344 12\n12 123\n\nSAMPLE\n" ]
[ "8\n12\n" ]
[ "2\n12344 11\n12 123\n\nSAMPLE\n", "2\n22339 11\n12 123\n\nSAMPLE\n", "2\n27435 11\n12 123\n\nSAMPLE\n", "2\n37424 11\n2 123\n\nSAMPLE\n", "2\n37424 4\n2 123\n\nSAMPLE\n", "2\n13587 4\n2 3\n\nSAMPLE\n", "2\n12344 12\n0 123\n\nSAMPLE\n", "2\n12344 11\n3 123\n\nSAMPLE\n", "2\n19004 7\n2 3\n\nSAMOLE\n"...
[ "2\n12\n", "9\n12\n", "1\n12\n", "2\n2\n", "0\n2\n", "3\n2\n", "8\n0\n", "2\n3\n", "6\n2\n", "1\n0\n" ]
CodeContests
There is a sequence $A = a_0, a_1, ..., a_{n-1}$. You are given the following information and questions. * relate$(x, y, z)$: $a_y$ is greater than $a_x$ by $z$ * diff$(x, y)$: report the difference between $a_x$ and $a_y$ $(a_y - a_x)$ Constraints * $2 \leq n \leq 100,000$ * $1 \leq q \leq 200,000$ * $0 \leq x, y <...
stdin
null
3,617
1
[ "5 6\n0 0 2 5\n0 1 2 3\n1 0 1\n1 1 3\n0 1 4 8\n1 0 4\n" ]
[ "2\n?\n10\n" ]
[ "5 6\n0 0 2 5\n0 1 2 3\n1 0 1\n1 1 3\n0 1 4 4\n1 0 4\n", "5 6\n0 0 2 5\n0 2 2 3\n1 0 1\n1 1 3\n0 1 4 4\n1 0 4\n", "5 6\n0 0 2 5\n0 1 2 3\n1 0 1\n1 1 3\n0 1 4 3\n1 0 4\n", "5 6\n0 0 2 5\n0 1 2 5\n1 0 1\n1 1 3\n0 1 4 3\n1 0 4\n", "5 6\n0 0 2 5\n0 2 2 3\n1 0 1\n1 0 0\n0 1 4 4\n1 0 4\n", "5 6\n0 0 2 5\n0 1 2 ...
[ "2\n?\n6\n", "?\n?\n?\n", "2\n?\n5\n", "0\n?\n3\n", "?\n0\n?\n", "3\n?\n6\n", "3\n?\n3\n", "?\n?\n2\n", "?\n?\n", "-1\n?\n2\n" ]
CodeContests
E - Minimum Spanning Tree Problem Statement You are given an undirected weighted graph G with n nodes and m edges. Each edge is numbered from 1 to m. Let G_i be an graph that is made by erasing i-th edge from G. Your task is to compute the cost of minimum spanning tree in G_i for each i. Input The dataset is forma...
stdin
null
2,263
1
[ "4 6\n1 2 2\n1 3 6\n1 4 3\n2 3 1\n2 4 4\n3 4 5\n" ]
[ "8\n6\n7\n10\n6\n6\n" ]
[ "4 6\n1 2 2\n1 3 6\n1 4 3\n2 3 1\n2 4 3\n3 4 5\n", "4 6\n1 2 2\n1 3 6\n1 4 3\n2 3 1\n2 4 3\n3 4 9\n", "4 6\n1 2 2\n1 3 6\n1 4 3\n2 3 2\n2 4 3\n3 4 9\n", "4 6\n1 2 2\n1 3 6\n1 4 3\n2 3 1\n2 4 3\n3 4 1\n", "4 6\n1 2 3\n1 3 6\n1 4 3\n2 3 1\n2 4 3\n3 4 5\n", "4 6\n1 2 2\n1 3 10\n1 4 3\n2 3 1\n2 4 3\n3 4 9\n",...
[ "7\n6\n6\n10\n6\n6\n", "7\n6\n6\n11\n6\n6\n", "8\n7\n7\n11\n7\n7\n", "5\n4\n4\n6\n4\n6\n", "7\n7\n7\n11\n7\n7\n", "7\n6\n6\n14\n6\n6\n", "7\n7\n7\n12\n7\n7\n", "9\n8\n8\n11\n8\n8\n", "6\n5\n5\n13\n6\n5\n", "8\n6\n7\n10\n6\n6\n" ]
CodeContests
Mr. B loves Brainf * ck and submits all the assignments given at school using Brainf * ck. Recently, I was brainwashed by Mr. B, and the teacher limited the language to solve the problem to Brainf * ck. At this rate, everyone will lose credit. You decide to help rescue everyone's units by creating a program that will ...
stdin
null
4,639
1
[ "ABC\n" ]
[ "++++++++[>++++++++<-]>+.+.+.\n" ]
[ "ABD\n", "ACD\n", "ADD\n", "DDA\n", "DD@\n", "CD@\n", "D@D\n", "@DD\n", "DD?\n", "?DD\n" ]
[ ">+++++[<++++++>-]>+++++[<++++++++>-]>+++++[<++++++++++>-]>++++++[<++++++++++>-]>+++++++[<++++++++++>-]>++++++++[<++++++++++>-]>+++++++++[<++++++++++>-]>++++++++++[<++++++++++>-]>+++++++++++[<++++++++++>-]>++++++++++++[<++++++++++>-]><<<<<<<<<<<>>>+++++.-----++++++.------++++++++.--------\n", ">+++++[<++++++>-]>+...
CodeContests
problem You have to play a darts game with the following rules. You can throw up to four arrows towards the target. You don't have to throw all four, you don't have to throw one. The target is divided into N parts. The score P1, ..., PN is written in each part. The total score S of the place where the arrow is stuck ...
stdin
null
4,395
1
[ "4 50\n3\n14\n15\n9\n3 21\n16\n11\n2\n0 0\n" ]
[ "48\n20\n" ]
[ "4 58\n3\n14\n15\n9\n3 21\n16\n11\n2\n0 0\n", "4 50\n3\n14\n27\n9\n3 21\n16\n11\n2\n0 0\n", "4 58\n6\n14\n15\n6\n3 21\n5\n11\n2\n0 0\n", "4 50\n3\n14\n20\n9\n3 21\n16\n11\n2\n0 0\n", "4 58\n3\n14\n25\n9\n3 21\n16\n11\n2\n0 0\n", "4 58\n6\n14\n28\n6\n3 21\n16\n11\n2\n0 0\n", "4 10\n3\n14\n20\n9\n3 21\n16...
[ "58\n20\n", "50\n20\n", "58\n21\n", "49\n20\n", "57\n20\n", "56\n20\n", "9\n20\n", "77\n20\n", "51\n20\n", "52\n20\n" ]
CodeContests
problem Chairman K is a regular customer of the JOI pizza shop in the center of JOI city. For some reason, he decided to start a life-saving life this month. So he wanted to order the pizza with the highest calories per dollar among the pizzas he could order at the JOI pizza store. Let's call such a pizza the "best pi...
stdin
null
108
1
[ "3\n12 2\n200\n50\n300\n100\n" ]
[ "37\n" ]
[ "3\n12 2\n200\n50\n300\n110\n", "3\n17 2\n200\n73\n300\n110\n", "3\n12 2\n200\n50\n599\n100\n", "3\n12 2\n200\n73\n575\n110\n", "3\n17 2\n200\n50\n300\n010\n", "3\n17 2\n63\n50\n300\n010\n", "3\n12 2\n200\n54\n506\n110\n", "3\n17 2\n38\n50\n300\n010\n", "3\n12 2\n358\n87\n575\n010\n", "3\n12 2\n20...
[ "38\n", "29\n", "57\n", "55\n", "26\n", "19\n", "51\n", "18\n", "66\n", "43\n" ]
CodeContests
Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view. Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of ...
stdin
null
1,462
1
[ "1\n0\nicpc\n" ]
[ "icpc\n" ]
[ "1\n0\nccpi\n", "1\n0\nipcc\n", "1\n0\njpcc\n", "1\n0\ncbpi\n", "1\n0\niocc\n", "1\n0\ncboi\n", "1\n0\ncdpi\n", "1\n0\njpbc\n", "1\n0\niodc\n", "1\n0\ncdip\n" ]
[ "ccpi\n", "ipcc\n", "jpcc\n", "cbpi\n", "iocc\n", "cboi\n", "cdpi\n", "jpbc\n", "iodc\n", "cdip\n" ]
CodeContests
If the given input positive integer is equal to the sum of its proper positive divisors then it will form a triangular array of numbers in which those at the ends of the rows are 1 and each of the others is the sum of the nearest two numbers in the row above (the apex, 1, being at the top). OR it can also be understoo...
stdin
null
1,796
1
[ "6\n\nSAMPLE\n" ]
[ "1\n11\n121\n1331\n14641\n15101051\n" ]
[ "6\n\nELPMAS\n", "6\n\nEAPMLS\n", "6\n\nEAPMLR\n", "6\n\nFAPMLR\n", "6\n\nFAQMLR\n", "6\n\nFAQMKR\n", "6\n\nFAQLKR\n", "6\n\nFAPLKR\n", "6\n\nFBPLKR\n", "6\n\nRKLPBF\n" ]
[ "1\n11\n121\n1331\n14641\n15101051\n", "1\n11\n121\n1331\n14641\n15101051\n", "1\n11\n121\n1331\n14641\n15101051\n", "1\n11\n121\n1331\n14641\n15101051\n", "1\n11\n121\n1331\n14641\n15101051\n", "1\n11\n121\n1331\n14641\n15101051\n", "1\n11\n121\n1331\n14641\n15101051\n", "1\n11\n121\n1331\n14641\n151...
CodeContests
Pati's girlfriend dumped him because he couldn't even solve a simple string puzzle. Puzzle is, given a string of lowercase alphabets and you are supposed to check whether the frequency of the most frequent character is even or not. Even after being dumped because of this puzzle, Pati is quite confident that it is im...
stdin
null
2,434
1
[ "2\n5\naabcd\n6\nxyzzdz\n\nSAMPLE\n" ]
[ "Yes\nNo\n" ]
[ "6\n5\naabcd\n6\nxyzzdz\n1\nb\n3\nacd\n4\naaaa\n2\ncb\n", "2\n1656\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
[ "Yes\nNo\nNo\nNo\nYes\nNo\n", "No\nYes\n", "Yes\nNo\n", "Yes\nNo\nNo\nNo\nYes\nYes\n", "No\nNo\n", "Yes\nYes\n", "Yes\nNo\nNo\nNo\nNo\nYes\n", "Yes\nNo\nNo\nNo\nNo\nNo\n", "No\nNo\nNo\nNo\nNo\nNo\n", "Yes\nNo\n" ]
CodeContests
In 40XX, the Earth was invaded by aliens! Already most of the Earth has been dominated by aliens, leaving Tsuruga Castle Fortress as the only remaining defense base. Suppression units are approaching the Tsuruga Castle Fortress one after another. <image> But hope remains. The ultimate defense force weapon, the ultra...
stdin
null
3,124
1
[ "100 5\n101 101 5 5\n110 110 2 3\n-112 -100 9 11\n-208 160 82 90\n-110 108 10 2\n10 11\n15 0 5 1\n25 0 5 1\n35 0 5 1\n45 0 5 1\n55 0 5 1\n65 0 5 1\n75 0 5 1\n85 0 5 1\n95 0 5 1\n-20 0 5 20\n-30 0 500 5\n0 0\n" ]
[ "1\n1\n" ]
[ "100 5\n101 101 5 5\n110 110 2 3\n-112 -100 9 11\n-208 160 82 90\n-110 108 10 2\n10 11\n15 0 5 1\n25 0 5 1\n35 0 5 1\n45 0 5 1\n55 0 5 1\n65 0 5 1\n75 0 5 1\n85 0 5 1\n95 0 5 1\n-19 0 5 20\n-30 0 500 5\n0 0\n", "100 5\n101 101 5 5\n110 110 2 3\n-112 -100 5 11\n-208 160 82 90\n-110 108 10 2\n10 11\n15 0 5 1\n25 0 ...
[ "1\n1\n", "1\n0\n", "2\n1\n", "0\n1\n", "1\n2\n", "0\n2\n", "1\n3\n", "0\n0\n", "0\n3\n", "1\n4\n" ]
CodeContests
Tim likes Math. He likes it so much that he always brings his tablets with him and reads math e-books everywhere, even during parties. Tim found an interesting exercise in one of the e-books he is reading. But you want him to join the party, so you decide to answer the question for him. The problem is: Given D and P,...
stdin
null
1,842
1
[ "3\n1 2\n0 4\n-1 1\n\nSAMPLE\n" ]
[ "4\n2\n0\n" ]
[ "2000\n317110 317111\n316190 632384\n1 12\n281788 563580\n1 6\n2 0\n749907 749908\n170484 340972\n309894 929691\n418799 0\n727178 727179\n111560 0\n200172 600525\n1 12\n850176 0\n10612 833820\n835142 0\n870825 0\n242298 242299\n493666 0\n283427 283428\n0 9\n334736 334737\n896246 896247\n988085 0\n255137 765420\n576...
[ "4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n2\n4\n4\n4\n4\n4\n4\n4\n2\n2\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n2\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n...
CodeContests
You happened to get a special bicycle. You can run with it incredibly fast because it has a turbo engine. You can't wait to try it off road to enjoy the power. You planned to go straight. The ground is very rough with ups and downs, and can be seen as a series of slopes (line segments) when seen from a lateral view. T...
stdin
null
74
1
[ "2 10\n0 0\n10000 0\n", "4 50\n0 10000\n1 10000\n2 0\n10000 0\n", "5 10\n0 0\n10 10\n20 0\n30 10\n40 0\n", "4 10000\n0 0\n1 1\n9999 0\n10000 10000\n" ]
[ "10000.00000000\n", "7741.23024274\n", "22.22335598\n", "11.21323169\n" ]
[ "4 50\n0 10000\n1 10000\n2 1\n10000 0\n", "4 10001\n0 0\n1 1\n9999 0\n10000 10000\n", "4 100\n0 10000\n1 10000\n2 1\n10000 0\n", "4 10001\n0 0\n1 1\n9999 -1\n10000 10000\n", "4 100\n0 10000\n1 10010\n2 1\n10000 0\n", "4 10001\n0 0\n1 1\n9999 -1\n10000 10100\n", "4 100\n0 10100\n1 10010\n2 1\n10000 0\n",...
[ "7741.31771861082324903691\n", "11.21127218305485762073\n", "5482.58435572738653718261\n", "11.21127208352683091164\n", "9447.09514967305767640937\n", "111.22114447885144272732\n", "10048.86393193447474914137\n", "1.00000000000000000000\n", "11085.68590092738304520026\n", "11085.433664613705332158...
CodeContests
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a. For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times. Given are N strings s_1, s_2, \ldots, s...
stdin
null
3,713
1
[ "5\nabaaaaaaaa\noneplustwo\naaaaaaaaba\ntwoplusone\naaaabaaaaa\n", "2\noneplustwo\nninemodsix\n", "3\nacornistnt\npeanutbomb\nconstraint\n" ]
[ "4\n", "0\n", "1\n" ]
[ "5\nabaaaaaaaa\noweplustno\naaaaaaaaba\ntwoplusone\naaaabaaaaa\n", "2\noneplustwo\nnioemodsix\n", "3\nacornistnt\npeaoutbnmb\nconstraint\n", "5\nabaaaaaaaa\noweplustmo\naaaaaaaaba\nunoselpowt\naaaaaaaaba\n", "5\nabaaaaaaaa\noweplustno\naaaaaaaaba\ntwoplusone\naaaaaaaaba\n", "2\nonepltsuwo\nnioemodsix\n", ...
[ "4\n", "0\n", "1\n", "3\n", "4\n", "0\n", "1\n", "4\n", "0\n", "1\n" ]
CodeContests
problem Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class. In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exam score was used as is. All students with a final exam score of le...
stdin
null
4,829
1
[ "10\n65\n100\n30\n95\n" ]
[ "68\n" ]
[ "10\n65\n101\n30\n95\n", "10\n65\n111\n30\n95\n", "10\n65\n010\n30\n95\n", "10\n62\n010\n30\n95\n", "10\n9\n100\n30\n95\n", "10\n65\n111\n30\n47\n", "10\n65\n110\n30\n24\n", "10\n65\n010\n30\n100\n", "10\n115\n010\n30\n95\n", "10\n9\n110\n30\n95\n" ]
[ "68\n", "70\n", "56\n", "55\n", "63\n", "60\n", "59\n", "57\n", "66\n", "65\n" ]
CodeContests
Description In 200X, the mysterious circle K, which operates at K University, announced K Poker, a new game they created on the 4th floor of K East during the university's cultural festival. At first glance, this game is normal poker, but it is a deeper game of poker with the addition of basic points to the cards. The...
stdin
null
3,570
1
[ "3\n0 1 0 1 0 0 0 0 0 1 0 0 0\n1 0 0 0 0 0 1 0 0 1 0 0 2\n0 1 1 0 1 1 1 0 0 0 0 5 5\n3 1 1 1 0 1 0 0 1 0 3 0 2\n1 1 2 4 5 10 20 50 100\n7H 6H 2H 5H 3H\n9S 9C 9H 8H 8D\nKS KH QH JD TS\n10\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 2 3 4 5 6 7 8 9\nA...
[ "25\n0\n14\n\n0\n5\n10\n15\n20\n25\n30\n35\n40\n45\n" ]
[ "3\n0 1 0 1 0 0 0 0 0 1 0 0 0\n1 0 0 0 0 0 1 0 0 1 0 0 2\n0 1 1 0 1 1 1 0 0 0 0 5 5\n3 1 1 1 0 1 0 0 1 0 3 0 2\n1 0 2 4 5 10 20 50 100\n7H 6H 2H 5H 3H\n9S 9C 9H 8H 8D\nKS KH QH JD TS\n10\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 2 3 4 5 6 7 8 9\nA...
[ "25\n0\n14\n\n0\n5\n10\n15\n20\n25\n30\n35\n40\n45\n", "25\n0\n14\n\n0\n5\n10\n15\n20\n20\n30\n35\n40\n45\n", "25\n0\n14\n\n0\n4\n10\n15\n20\n25\n30\n28\n40\n45\n", "25\n0\n0\n\n0\n4\n10\n15\n20\n25\n30\n28\n40\n45\n", "25\n0\n14\n\n0\n5\n10\n15\n20\n20\n30\n35\n32\n45\n", "20\n0\n14\n\n0\n5\n10\n15\n20\n...
CodeContests
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice. Given is a string S. Find the minimum number of hugs needed to make S palindromic. Constraints * S is a string consisting of lowercase English ...
stdin
null
2,559
1
[ "abcdabc\n", "redcoder\n", "vvvvvv\n" ]
[ "2\n", "1\n", "0\n" ]
[ "aacdabc\n", "redocder\n", "vwwvvv\n", "rdebrdeo\n", "uuxxuu\n", "wvvvvv\n", "aacbadc\n", "reeocddr\n", "vvvvvw\n", "cdabcaa\n" ]
[ "3\n", "1\n", "2\n", "4\n", "0\n", "1\n", "3\n", "3\n", "1\n", "3\n" ]
CodeContests
Hide-and-seek is a children’s game. Players hide here and there, and one player called it tries to find all the other players. Now you played it and found all the players, so it’s turn to hide from it. Since you have got tired of running around for finding players, you don’t want to play it again. So you are going to ...
stdin
null
3,648
1
[ "2\n0 0 3 3\n0 4 3 1\n1 1\n0\n" ]
[ "4.243\n" ]
[ "2\n0 0 3 3\n0 5 3 1\n1 1\n0\n", "2\n0 0 3 3\n1 4 3 1\n1 1\n0\n", "2\n0 0 3 3\n1 4 3 0\n1 1\n0\n", "2\n0 0 3 3\n1 4 5 0\n1 1\n0\n", "2\n0 0 3 3\n1 4 6 0\n1 1\n0\n", "2\n0 0 3 3\n1 8 3 0\n1 1\n0\n", "2\n0 0 3 3\n0 4 6 0\n1 1\n0\n", "2\n0 0 3 3\n1 5 3 0\n1 1\n0\n", "2\n0 0 3 3\n1 1 5 0\n1 1\n0\n", "...
[ "5.1876726427\n", "3.8603870401\n", "3.6502815399\n", "5.6568542495\n", "6.6257720956\n", "7.7522468632\n", "6.3065605179\n", "4.6934811039\n", "4.1231056256\n", "4.8670420532\n" ]
CodeContests
You are given a permutation p = (p_1, \ldots, p_N) of \\{ 1, \ldots, N \\}. You can perform the following two kinds of operations repeatedly in any order: * Pay a cost A. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, ...
stdin
null
2,010
1
[ "3 20 30\n3 1 2\n", "1 10 10\n1\n", "4 20 30\n4 2 3 1\n", "4 1000000000 1000000000\n4 3 2 1\n", "9 40 50\n5 3 4 7 6 1 2 9 8\n" ]
[ "20\n", "0\n", "50\n", "3000000000\n", "220\n" ]
[ "3 26 30\n3 1 2\n", "4 20 30\n3 2 3 1\n", "9 40 87\n5 3 4 7 6 1 2 9 8\n", "4 8 30\n3 2 3 1\n", "4 11 30\n3 2 3 1\n", "4 20 36\n4 2 3 1\n", "4 20 46\n4 2 3 1\n", "9 67 87\n5 3 4 7 6 1 3 12 8\n", "9 72 87\n5 3 4 7 6 1 3 12 8\n", "1 8 10\n1\n" ]
[ "26\n", "50\n", "240\n", "24\n", "33\n", "56\n", "60\n", "375\n", "390\n", "0\n" ]
CodeContests
There is a new magician in town. His trick is known as "Find the Ring". He puts 3 glasses at 3 spots on the table, labeling them as 0, 1 and 2. Now, he hides a ring under one of the glasses. The glasses are opaque and placed upside down, so that the ring is not visible to the audience. Now, he begins to make certain ...
stdin
null
402
1
[ "3\n1 1\n0 1\n2 2\n\nSAMPLE\n" ]
[ "0\n1\n0\n" ]
[ "100\n0 5619\n0 3827\n2 1722\n2 909\n2 7032\n0 832\n1 7280\n2 5860\n0 1391\n2 5694\n0 109\n2 4742\n0 5886\n2 9924\n0 3544\n1 9460\n1 7759\n0 2056\n0 539\n0 861\n2 9947\n1 4501\n2 6755\n1 2787\n0 8049\n2 7526\n0 6094\n0 7932\n0 1551\n0 5864\n1 3707\n1 8735\n0 3911\n1 4988\n0 2173\n1 2851\n2 5676\n2 8498\n2 3784\n1 7...
[ "1\n1\n0\n1\n0\n0\n1\n0\n1\n0\n1\n0\n0\n0\n0\n1\n0\n0\n1\n1\n1\n0\n1\n0\n1\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n1\n0\n1\n0\n1\n1\n0\n1\n1\n1\n0\n1\n0\n1\n0\n1\n0\n0\n1\n0\n0\n0\n0\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n1\n1\n0\n0\n0\n1\n0\n1\n1\n1\n1\n", "1\n1\n0\n...
CodeContests
There is a square grid with N rows and M columns. Each square contains an integer: 0 or 1. The square at the i-th row from the top and the j-th column from the left contains a_{ij}. Among the 2^{N+M} possible pairs of a subset A of the rows and a subset B of the columns, find the number of the pairs that satisfy the f...
stdin
null
2,089
1
[ "2 2\n0 1\n1 0\n", "2 3\n0 0 0\n0 1 0\n" ]
[ "6\n", "8\n" ]
[ "2 3\n0 0 0\n-1 1 0\n", "2 3\n0 0 -1\n-1 1 0\n", "1 3\n0 0 -1\n-1 1 0\n", "2 2\n1 1\n1 0\n", "1 2\n-1 0 -1\n-1 0 0\n", "1 0\n-1 0 -1\n-1 0 0\n", "1 1\n-1 1 -4\n0 1 2\n", "1 3\n-1 0 -1\n-1 1 0\n", "1 3\n-1 0 -1\n-1 1 1\n", "1 3\n-1 1 -1\n-1 1 1\n" ]
[ "8\n", "12\n", "4\n", "6\n", "2\n", "0\n", "1\n", "4\n", "4\n", "4\n" ]
CodeContests
Chandu has been appointed as the superintendent of a jail having N prisoners . Prisoner are numbered form 1 to N. Today he has been specially invited to execute the prisoners. All the prisoners are arranged in circle and he starts executing them in clock-wise direction. He always starts with first prisoner and skips ...
stdin
null
3,144
1
[ "2\n5\n6\n\nSAMPLE\n" ]
[ "3\n5\n" ]
[ "1000\n3003\n4638\n1156\n4277\n1903\n1654\n1306\n3643\n4615\n2707\n1861\n2651\n1617\n1686\n2909\n3456\n1055\n1670\n2693\n1270\n4358\n4731\n4420\n4965\n1190\n2568\n4704\n2147\n3198\n2315\n1524\n4715\n2378\n3484\n3424\n1558\n3095\n3548\n1093\n3555\n1806\n1568\n4759\n1776\n4024\n4925\n2238\n3145\n4789\n4170\n3759\n352...
[ "1911\n1085\n265\n363\n1759\n1261\n565\n3191\n1039\n1319\n1675\n1207\n1187\n1325\n1723\n2817\n63\n1293\n1291\n493\n525\n1271\n649\n1739\n333\n1041\n1217\n199\n2301\n535\n1001\n1239\n661\n2873\n2753\n1069\n2095\n3001\n139\n3015\n1565\n1089\n1327\n1505\n3953\n1659\n381\n2195\n1387\n149\n3423\n2957\n485\n1629\n1801\n5...
CodeContests
On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is marked. They use only a single stone. The purpose of the game is to lead the stone from the start to the goal with the minim...
stdin
null
1,578
1
[ "2 1\n3 2\n6 6\n1 0 0 2 1 0\n1 1 0 0 0 0\n0 0 0 0 0 3\n0 0 0 0 0 0\n1 0 0 0 0 1\n0 1 1 1 1 1\n6 1\n1 1 2 1 1 3\n6 1\n1 0 2 1 1 3\n12 1\n2 0 1 1 1 1 1 1 1 1 1 3\n13 1\n2 0 1 1 1 1 1 1 1 1 1 1 3\n0 0\n" ]
[ "1\n4\n-1\n4\n10\n-1\n" ]
[ "2 1\n3 2\n6 6\n1 0 0 2 1 -1\n1 1 0 0 0 0\n0 0 0 0 0 3\n0 0 0 0 0 0\n1 0 0 0 0 1\n0 1 1 1 1 1\n6 1\n1 1 2 1 1 3\n6 1\n1 0 2 1 1 3\n12 1\n2 0 1 1 1 1 1 1 1 1 1 3\n13 1\n2 0 1 1 1 1 1 1 1 1 1 1 3\n0 0\n", "2 1\n5 2\n6 6\n1 0 0 2 1 -1\n1 1 0 0 0 0\n0 0 0 0 0 3\n0 0 0 0 0 0\n1 0 0 0 0 1\n0 1 1 1 1 1\n6 1\n1 1 2 1 1 3...
[ "1\n4\n-1\n4\n10\n-1\n", "-1\n4\n-1\n4\n10\n-1\n", "1\n4\n-1\n-1\n10\n-1\n", "1\n-1\n-1\n4\n10\n-1\n", "-1\n4\n-1\n4\n9\n-1\n", "-1\n4\n2\n4\n9\n-1\n", "1\n4\n-1\n4\n-1\n-1\n", "1\n5\n-1\n-1\n10\n-1\n", "1\n4\n-1\n-1\n10\n10\n", "-1\n4\n-1\n-1\n10\n-1\n" ]
CodeContests
Problem In recent years, turf wars have frequently occurred among squids. It is a recent squid fighting style that multiple squids form a team and fight with their own squid ink as a weapon. There is still a turf war, and the battlefield is represented by an R × C grid. The squid Gesota, who is participating in the t...
stdin
null
307
1
[ "4 5\nS#...\n.#.#.\n.#.#.\n...#G\n", "5 5\nSxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxG\n", "4 5\nS#ooo\no#o#o\no#o#o\nooo#G\n", "5 5\nS....\n.....\n.....\n.....\n....G\n", "4 5\nG####\nooxoo\nx#o\nSoooo\n" ]
[ "23\n", "15\n", "14\n", "14\n", "10\n" ]
[ "4 5\nS#...\n.#.$.\n.#.#.\n...#G\n", "5 5\n.S...\n.....\n.....\n.....\n....G\n", "4 5\nG####\nonxoo\nx#o\nSoooo\n", "4 5\nS#...\n.#.$.\n.#.#.\nG#../\n", "4 5\no#ooS\no#o#o\no#o#o\nooo#G\n", "7 5\nS....\n.....\n.....\n.....\n....G\n", "4 5\nS#-..\n.#.$.\n.#.$.\n/..#G\n", "4 5\nG####\npoxoo\no#x\noooSo\...
[ "21\n", "12\n", "8\n", "5\n", "4\n", "14\n", "17\n", "6\n", "9\n", "13\n" ]
CodeContests
Given are three integers N, K, and S. Find a sequence A_1, A_2, ..., A_N of N integers between 1 and 10^9 (inclusive) that satisfies the condition below. We can prove that, under the conditions in Constraints, such a sequence always exists. * There are exactly K pairs (l, r) of integers such that 1 \leq l \leq r \leq...
stdin
null
370
1
[ "5 3 100\n", "4 2 3\n" ]
[ "50 50 50 30 70\n", "1 2 3 4\n" ]
[ "5 3 000\n", "5 0 100\n", "4 1 3\n", "5 3 010\n", "4 0 3\n", "10 3 010\n", "8 0 3\n", "10 5 010\n", "8 1 3\n", "10 5 000\n" ]
[ "0 0 0 1 1\n", "101 101 101 101 101\n", "3 4 4 4\n", "10 10 10 11 11\n", "4 4 4 4\n", "10 10 10 11 11 11 11 11 11 11\n", "4 4 4 4 4 4 4 4\n", "10 10 10 10 10 11 11 11 11 11\n", "3 4 4 4 4 4 4 4\n", "0 0 0 0 0 1 1 1 1 1\n" ]
CodeContests
Xynazog was playing a game. He needed to score k points and he could play at most N moves and at least 1 move. In each move, he could get [0,k] points. Note: the number of points gained is always an integer. Xynazog's friend PowerShell challenged Xenny to find the number of ways in which he could score k points in exa...
stdin
null
763
1
[ "1\n2 2\n\nSAMPLE\n" ]
[ "3\n" ]
[ "10000\n17 16\n16 2\n6 17\n16 17\n15 18\n10 6\n15 14\n10 17\n11 1\n7 3\n12 18\n9 8\n15 3\n12 5\n14 18\n3 8\n14 12\n17 15\n16 14\n8 8\n12 16\n3 11\n18 19\n3 2\n10 12\n10 14\n3 15\n4 6\n1 7\n19 18\n7 8\n5 18\n13 10\n1 19\n1 13\n14 9\n2 19\n13 18\n7 11\n13 10\n18 19\n3 8\n2 19\n19 19\n7 5\n19 1\n5 5\n9 7\n3 6\n9 13\n1...
[ "601080390\n136\n26334\n565722720\n471435600\n5005\n40116600\n3124550\n11\n84\n34597290\n12870\n680\n4368\n206253075\n45\n5200300\n300540195\n77558760\n6435\n13037895\n78\n8597496600\n6\n293930\n817190\n136\n84\n1\n9075135300\n3003\n7315\n646646\n1\n1\n497420\n20\n86493225\n12376\n646646\n8597496600\n45\n20\n176726...
CodeContests
Problem statement Two players are playing the game. The rules of the game will be described below. There is a board of $ N × N $ squares, and each square has the number $ X_ {i, j} $ ($ 1 \ leq i, j \ leq N $) written on it. The first move and the second move alternately select hands and accumulate points. The first ...
stdin
null
3,931
1
[ "2 5\n3 4\n7 6\n", "2 0\n1 3\n1 1\n", "2 100\n0 0\n0 0\n" ]
[ "Draw\n4\n", "Second\n3\n", "First\n2\n" ]
[ "2 5\n3 7\n7 6\n", "2 100\n0 0\n0 -1\n", "3 5\n3 7\n7 6\n", "2 000\n0 0\n0 -2\n", "3 5\n3 7\n0 0\n", "3 5\n3 7\n0 1\n", "4 0\n1 3\n2 0\n", "6 5\n3 7\n0 0\n", "5 5\n3 7\n0 0\n", "6 7\n3 7\n1 1\n" ]
[ "Second\n3\n", "First\n2\n", "Second\n5\n", "Draw\n4\n", "First\n4\n", "Draw\n6\n", "Second\n7\n", "First\n10\n", "First\n8\n", "First\n6\n" ]
CodeContests
Flip the world is a game. In this game a matrix of size N*M is given, which consists of numbers. Each number can be 1 or 0 only. The rows are numbered from 1 to N, and the columns are numbered from 1 to M. Following steps can be called as a single move. Select two integers x,y (1 ≤ x ≤ N\; and\; 1 ≤ y ≤ M) i.e. one s...
stdin
null
4,924
1
[ "1\n5 5\n00011\n00011\n00011\n11111\n11111\n\nSAMPLE\n" ]
[ "1\n" ]
[ "1\n5 5\n00011\n00011\n00011\n11111\n11011\n\nSAMPLE\n", "30\n1 1\n1\n1 1\n0\n4 4\n0000\n1110\n0101\n1011\n4 4\n1100\n0010\n1010\n1101\n4 4\n1111\n1110\n0000\n0100\n4 4\n1000\n1110\n0011\n1110\n4 4\n0011\n0110\n0101\n1000\n4 4\n0010\n0111\n1100\n0100\n4 4\n0100\n1111\n1001\n0000\n4 4\n0001\n0011\n0111\n0100\n4 4\...
[ "5\n", "0\n1\n7\n6\n8\n10\n11\n11\n9\n9\n11\n11\n9\n10\n7\n6\n12\n7\n8\n10\n6\n7\n5\n8\n10\n8\n10\n11\n12\n7\n", "1\n", "0\n1\n7\n6\n8\n10\n11\n11\n9\n11\n11\n11\n9\n10\n7\n6\n12\n7\n8\n10\n6\n7\n5\n8\n10\n8\n10\n11\n12\n7\n", "3\n", "2\n", "0\n1\n7\n6\n8\n10\n11\n11\n9\n9\n11\n11\n9\n10\n7\n6\n12\n7\n8...
CodeContests
You are given a sequence A_1, A_2, ..., A_N and an integer K. Print the maximum possible length of a sequence B that satisfies the following conditions: * B is a (not necessarily continuous) subsequence of A. * For each pair of adjacents elements of B, the absolute difference of the elements is at most K. Constraint...
stdin
null
368
1
[ "10 3\n1\n5\n4\n3\n8\n6\n9\n7\n2\n4\n" ]
[ "7\n" ]
[ "10 3\n1\n5\n4\n3\n8\n6\n9\n7\n4\n4\n", "10 3\n1\n5\n4\n3\n6\n6\n9\n7\n4\n4\n", "10 3\n0\n1\n4\n3\n6\n6\n9\n7\n4\n4\n", "10 3\n1\n5\n4\n3\n8\n6\n9\n7\n3\n4\n", "10 3\n1\n5\n4\n3\n8\n11\n9\n7\n3\n4\n", "10 1\n0\n1\n4\n0\n5\n9\n9\n7\n8\n4\n", "10 1\n0\n5\n4\n3\n8\n11\n9\n7\n6\n2\n", "10 3\n1\n5\n2\n0\n6...
[ "8\n", "9\n", "10\n", "7\n", "6\n", "3\n", "4\n", "5\n", "1\n", "2\n" ]
CodeContests
Given three positive integers N, A and B (A < B < N), find the sum of all positive integers less than N, which are divisible by either A or B. For example, when N = 20, A = 4 and B = 7, the possible values are 4, 7, 8, 12, 14, and 16. Their sum is 61. Input Format The only line of the input file contains three space s...
stdin
null
1,005
1
[ "20 4 7\n\nSAMPLE\n" ]
[ "61\n" ]
[ "20 4 7\n\nEAMPLS\n", "20 4 14\n\nEAMPLS\n", "22 4 14\n\nEAMPLS\n", "13 4 7\n\nELPMAS\n", "22 6 14\n\nEAMPLR\n", "26 4 7\n\nELPMAS\n", "1010 3 5\n", "34 4 7\n\nSAMPLE\n", "20 6 7\n\nELPMAS\n", "17 6 14\n\nEAMPLR\n" ]
[ "61\n", "54\n", "74\n", "31\n", "50\n", "126\n", "237183\n", "186\n", "57\n", "32\n" ]
CodeContests
Revised The current era, Heisei, will end on April 30, 2019, and a new era will begin the next day. The day after the last day of Heisei will be May 1, the first year of the new era. In the system developed by the ACM-ICPC OB / OG Association (Japanese Alumni Group; JAG), the date uses the Japanese calendar (the Japa...
stdin
null
1,068
1
[ "HEISEI 1 1 8\nHEISEI 31 4 30\nHEISEI 31 5 1\nHEISEI 99 12 31\nHEISEI 38 8 30\nHEISEI 98 2 22\nHEISEI 2 3 26\nHEISEI 28 4 23\n#\n" ]
[ "HEISEI 1 1 8\nHEISEI 31 4 30\n? 1 5 1\n? 69 12 31\n? 8 8 30\n? 68 2 22\nHEISEI 2 3 26\nHEISEI 28 4 23\n" ]
[ "HEISEI 1 1 8\nHEISEI 31 4 30\nIESIEH 31 5 1\nHEISEI 99 12 31\nHEISEI 38 8 30\nHEISEI 98 2 22\nHEISEI 2 3 26\nHEISEI 28 4 23\n#\n", "HEISEI 1 1 8\nHEISEI 31 4 30\nIESIEH 31 5 1\nHEISEI 99 12 31\nHEISEI 38 8 30\nHEISEI 98 2 22\nHEISEI 3 3 26\nHEISEI 28 4 23\n#\n", "HEISEI 1 1 8\nHEISEI 31 4 30\nIESIEH 31 5 1\nHE...
[ "HEISEI 1 1 8\nHEISEI 31 4 30\n? 1 5 1\n? 69 12 31\n? 8 8 30\n? 68 2 22\nHEISEI 2 3 26\nHEISEI 28 4 23\n", "HEISEI 1 1 8\nHEISEI 31 4 30\n? 1 5 1\n? 69 12 31\n? 8 8 30\n? 68 2 22\nHEISEI 3 3 26\nHEISEI 28 4 23\n", "HEISEI 1 1 8\nHEISEI 31 4 30\n? 1 5 1\n? 69 12 31\n? 8 8 30\n? 68 2 22\nHEISEI 5 3 26\nHEISEI 28 ...
CodeContests
Ron is a master of a ramen shop. Recently, he has noticed some customers wait for a long time. This has been caused by lack of seats during lunch time. Customers loses their satisfaction if they waits for a long time, and even some of them will give up waiting and go away. For this reason, he has decided to increase s...
stdin
null
1,621
1
[ "1 4 100\n7\n10 1 50 50\n15 2 50 50\n25 1 50 50\n35 3 50 50\n1 2 100\n5\n30 3 20 50\n40 4 40 50\n1 2 100\n5\n49 3 20 50\n60 4 50 30\n1 2 100\n5\n50 3 20 50\n60 4 50 30\n2 3 100\n4 2\n10 4 20 20\n30 2 20 20\n40 4 20 20\n0 0 0\n" ]
[ "0.7428571428571429\n0.4285714285714285\n0.5542857142857143\n-0.1428571428571428\n0.8000000000000000\n" ]
[ "1 4 100\n7\n10 1 50 50\n15 2 50 50\n25 1 50 50\n35 3 50 50\n1 2 100\n5\n30 3 20 50\n40 0 40 50\n1 2 100\n5\n49 3 20 50\n60 4 50 30\n1 2 100\n5\n50 3 20 50\n60 4 50 30\n2 3 100\n4 2\n10 4 20 20\n30 2 20 20\n40 4 20 20\n0 0 0\n", "1 4 100\n7\n10 1 50 50\n15 2 50 50\n25 1 50 50\n35 3 50 50\n1 2 100\n5\n30 3 20 50\n...
[ "0.7428571428571429\n1.0000000000000000\n0.5542857142857143\n-0.1428571428571428\n0.8000000000000000\n", "0.7428571428571429\n0.4285714285714285\n0.5542857142857143\n-0.1428571428571428\n0.8000000000000000\n", "0.9742857142857143\n0.4285714285714285\n0.5542857142857143\n-0.1428571428571428\n0.8000000000000000\n...
CodeContests
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called deliciousness, as follows: * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X. * The deliciousn...
stdin
null
1,404
1
[ "2 2 2 8\n4 6\n1 5\n3 8\n", "10 10 10 20\n7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n4975681328 8974383988 2882263257 7690203955 514305523...
[ "19\n17\n15\n14\n13\n12\n10\n8\n", "23379871545\n22444657051\n22302177772\n22095691512\n21667941469\n21366963278\n21287912315\n21279176669\n21160477018\n21085311041\n21059876163\n21017997739\n20703329561\n20702387965\n20590247696\n20383761436\n20343962175\n20254073196\n20210218542\n20150096547\n", "400\n310\n31...
[ "2 2 2 1\n4 6\n1 5\n3 8\n", "10 10 10 20\n7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n4975681328 8974383988 2882263257 6426500770 514305523...
[ "19\n", "23379871545\n22444657051\n22302177772\n21667941469\n21366963278\n21287912315\n21279176669\n21085311041\n21059876163\n20831988327\n20703329561\n20702387965\n20590247696\n20343962175\n20254073196\n20210218542\n20150096547\n20007617268\n19982182390\n19953166481\n", "23379871545\n22444657051\n22302177772\n...
CodeContests
Binary trees are defined recursively. A binary tree T is a structure defined on a finite set of nodes that either * contains no nodes, or * is composed of three disjoint sets of nodes: - a root node. - a binary tree called its left subtree. - a binary tree called its right subtree. Your task is to write a program ...
stdin
null
2,344
1
[ "9\n0 1 4\n1 2 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1\n" ]
[ "Preorder\n 0 1 2 3 4 5 6 7 8\nInorder\n 2 1 3 0 6 5 7 4 8\nPostorder\n 2 3 1 6 7 5 8 4 0\n" ]
[ "9\n0 1 4\n1 2 5\n2 -1 -1\n3 -1 -1\n4 3 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1\n", "9\n0 2 4\n1 1 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1\n", "9\n0 2 4\n1 0 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1\n", "9\n0 2 4\n1 0 3\n2 -1 -1\n3 -1 0\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -...
[ "Preorder\n 0 1 2 5 6 7 4 3 8\nInorder\n 2 1 6 5 7 0 3 4 8\nPostorder\n 2 6 7 5 1 3 8 4 0\n", "Preorder\n 0 2 4 5 6 7 8\nInorder\n 2 0 6 5 7 4 8\nPostorder\n 2 6 7 5 8 4 0\n", "Preorder\n 1 0 2 4 5 6 7 8 3\nInorder\n 2 0 6 5 7 4 8 1 3\nPostorder\n 2 6 7 5 8 4 0 3 1\n", "Preorder\n 1 0 2 4 5 6 7 8 3 0 2 4 5 6 ...
CodeContests
You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a...
stdin
null
3,880
1
[ "3\n3 2 1\n", "3\n2 3 1\n", "2\n1 2\n" ]
[ "1 2 3\n5 3 1\n", "5 10 100\n100 10 1\n", "1 4\n5 4\n" ]
[ "2\n1 0\n", "2\n0 -1\n", "3\n2 0 1\n", "3\n1 3 2\n", "3\n1 -1 0\n", "3\n0 2 1\n", "3\n0 1 2\n", "3\n2 1 0\n", "2\n2 1\n", "2\n2 -1\n" ]
[ "1 3\n3 2\n", "2 3\n3 1\n", "3 4 6\n6 3 2\n", "1 4 6\n6 5 2\n", "1 3 6\n6 5 3\n", "3 5 6\n6 3 1\n", "2 5 6\n6 4 1\n", "2 3 6\n6 4 3\n", "2 3\n3 1\n", "2 3\n3 1\n" ]
CodeContests
Sherlock rolls a N faced die M times. He adds all the numbers he gets on all throws. What is the probability that he has a sum of K. A N faced die has all numbers from 1 to N written on it and each has equal probability of arriving when dice is thrown. Input First line T, the number of testcases. Each testcase co...
stdin
null
4,065
1
[ "2\n1 5 2\n2 3 2\n\nSAMPLE\n" ]
[ "2.000 1\n1.111 1\n" ]
[ "10\n5 6 23\n7 2 13\n2 9 11\n5 8 27\n3 10 21\n4 6 7\n2 1 1\n2 4 4\n8 3 6\n10 4 8\n", "2\n1 5 3\n2 3 2\n\nSAMPLE\n", "10\n7 6 23\n7 2 13\n2 9 11\n5 8 27\n3 10 21\n4 6 7\n2 1 1\n2 4 4\n8 3 6\n10 4 8\n", "10\n7 6 23\n7 2 13\n2 9 11\n5 8 6\n3 10 21\n4 6 7\n2 1 1\n2 4 4\n8 3 6\n10 4 8\n", "10\n7 6 23\n7 2 13\n2 ...
[ "3.922 2\n5.469 2\n9.877 2\n5.341 2\n5.500 2\n1.543 2\n0.000 0\n1.875 1\n0.000 0\n0.000 0\n", "2.000 1\n1.111 1\n", "8.204 2\n5.469 2\n9.877 2\n5.341 2\n5.500 2\n1.543 2\n0.000 0\n1.875 1\n0.000 0\n0.000 0\n", "8.204 2\n5.469 2\n9.877 2\n1.526 4\n5.500 2\n1.543 2\n0.000 0\n1.875 1\n0.000 0\n0.000 0\n", "8.2...
CodeContests
find the sum of the even fibonacci numbers till the given number(it is the value not index). INPUT: T test cases next T lines consists of a number n. OUTPUT: Output the sum value. 0<t<10 2<n<10^20 Example: if n=10 the numbers which are less than 10 are 2 and 8 in fibonacci. sum = 2+8=10 SAMPLE INPUT 2 10 100 SAMPLE...
stdin
null
1,673
1
[ "2\n10\n100\n\nSAMPLE\n" ]
[ "10\n44\n" ]
[ "5\n9197\n145786\n1254478\n147852\n125478\n", "10\n457866622145522214789856\n321245663325\n12254\n14221\n14256\n145\n225\n125\n1254785632145632145\n14789666620000000\n", "2\n6\n100\n\nSAMPLE\n", "5\n12857\n145786\n1254478\n147852\n125478\n", "10\n457866622145522214789856\n321245663325\n12254\n14221\n14256\n...
[ "3382\n60696\n1089154\n60696\n60696\n", "390887039715493615101718\n112925716858\n14328\n14328\n14328\n188\n188\n44\n889989708002357094\n11708364174233842\n", "2\n44\n", "14328\n60696\n1089154\n60696\n60696\n", "390887039715493615101718\n112925716858\n14328\n14328\n14328\n188\n188\n188\n889989708002357094\n1...
CodeContests
Roy is working on HackerEarth Profile. Right now he is working on User Statistics. One of the statistics data (Code Streak) is as follows: Given the User Activity Data, find the maximum number of continuous correct solutions submitted by any user. Seems easy eh? Here's the catch! In order to maximize this number a use...
stdin
null
2,595
1
[ "3\n6\n1 0\n2 1\n3 1\n4 1\n5 1\n6 0\n5\n1 1\n2 0\n3 1\n1 1\n2 1\n4\n1 1\n2 1\n2 1\n3 1\n\nSAMPLE\n" ]
[ "4\n2\n3\n" ]
[ "3\n6\n1 0\n3 1\n3 1\n4 1\n5 1\n6 0\n5\n1 1\n2 0\n3 1\n1 1\n2 1\n4\n1 1\n2 1\n2 1\n3 1\n\nSAMPLE\n", "3\n6\n2 0\n2 1\n3 1\n4 1\n5 1\n6 0\n5\n1 1\n2 0\n3 1\n1 1\n2 1\n4\n1 1\n2 1\n2 1\n3 1\n\nSAMPLE\n", "3\n6\n2 1\n2 1\n3 1\n4 1\n5 1\n6 0\n5\n1 1\n2 0\n3 0\n1 1\n2 1\n4\n1 1\n2 1\n2 1\n3 1\n\nSAMPLE\n", "3\n6\n...
[ "3\n2\n3\n", "4\n2\n3\n", "4\n1\n3\n", "2\n2\n3\n", "3\n2\n4\n", "2\n3\n3\n", "4\n2\n2\n", "3\n1\n3\n", "3\n3\n3\n", "3\n3\n2\n" ]
CodeContests
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353: * The number of combinations of N sides shown by the dice such that the sum of no two different sides is i. Note that the dice are ...
stdin
null
731
1
[ "6 1000\n", "3 3\n", "4 5\n" ]
[ "149393349\n149393349\n668669001\n668669001\n4000002\n4000002\n4000002\n668669001\n668669001\n149393349\n149393349\n", "7\n7\n4\n7\n7\n", "36\n36\n20\n20\n20\n36\n36\n" ]
[ "8 1000\n", "3 6\n", "1 5\n", "13 1000\n", "18 1000\n", "18 1100\n", "2 3\n", "18 0100\n", "5 3\n", "21 1100\n" ]
[ "172955709\n172955709\n215375670\n215375670\n257477746\n257477746\n670183294\n670183294\n670183294\n257477746\n257477746\n215375670\n215375670\n172955709\n172955709\n", "13\n13\n4\n13\n13\n", "0\n", "497036381\n497036381\n419411018\n419411018\n948498877\n948498877\n80387296\n80387296\n341522806\n341522806\n49...
CodeContests
Problem Statement JAG Kingdom is a strange kingdom such that its $N$ cities are connected only by one-way roads. The $N$ cities are numbered $1$ through $N$. ICPC (International Characteristic Product Corporation) transports its products from the factory at the city $S$ to the storehouse at the city $T$ in JAG Kingdom...
stdin
null
2,700
1
[ "4 4 1 4\n1 2\n3 1\n4 2\n3 4\n7 8 1 7\n1 2\n1 3\n2 4\n3 4\n4 5\n4 6\n5 7\n7 6\n6 4 5 2\n1 2\n1 3\n4 5\n5 6\n10 21 9 10\n9 1\n9 2\n9 3\n9 4\n10 1\n10 2\n10 3\n10 4\n1 5\n2 5\n2 6\n3 6\n3 7\n4 7\n4 8\n1 8\n5 10\n6 10\n7 10\n10 8\n10 9\n2 15 1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 ...
[ "1 2\n2 1\n0 0\n4 6\n15 0\n" ]
[ "4 4 1 4\n1 2\n3 1\n4 2\n3 4\n7 8 1 7\n1 2\n1 3\n2 4\n3 4\n4 5\n4 6\n5 7\n7 6\n6 4 5 2\n1 2\n1 3\n4 5\n5 6\n10 21 9 10\n9 1\n9 2\n9 3\n9 4\n10 1\n10 2\n10 3\n10 4\n1 5\n2 5\n2 6\n3 6\n3 7\n4 7\n4 8\n1 8\n5 10\n6 10\n7 10\n10 8\n10 9\n2 15 1 2\n2 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 ...
[ "1 2\n2 1\n0 0\n4 6\n14 0\n", "1 2\n2 1\n0 0\n4 4\n14 0\n", "1 2\n2 1\n0 0\n3 5\n14 0\n", "1 2\n2 1\n0 0\n4 3\n14 0\n", "2 1\n2 1\n0 0\n4 6\n14 0\n", "1 2\n2 1\n0 0\n4 4\n15 0\n", "2 1\n2 1\n0 0\n4 4\n14 0\n", "1 2\n1 0\n0 0\n3 5\n14 0\n", "1 2\n1 1\n0 0\n4 6\n14 0\n", "1 2\n2 1\n0 0\n3 4\n15 0\n"...
CodeContests
In 21XX, an annual programming contest, Japan Algorithmist GrandPrix (JAG) has become one of the most popular mind sports events. JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tournament chart is represented as a string. '[[a-b]-[c-d]]' is an easy example. In this case, t...
stdin
null
2,068
1
[ "[[m-y]-[a-o]]\no 0\na 1\ny 2\nm 0\n", "[[r-i]-[m-e]]\ne 0\nr 1\ni 1\nm 2\n" ]
[ "Yes\n", "No\n" ]
[ "[[r-i]-[m-e]]\ne 0\nr 1\ni 1\nn 2\n", "[[m-y]-[a-o]]\nn 0\na 1\ny 2\nm 0\n", "[[r-i]-[m-e]]\nd 0\nr 1\ni 1\nn 2\n", "[[r-i]-[m-e]]\nd 0\nr 1\ni 1\nn 3\n", "[[r-i]-[m-e]]\nd 0\nr 1\nh 1\nn 3\n", "[[r-i]-[m-e]]\nd 0\nr 1\ng 1\nn 3\n", "[[r-i]-[m-e]]\nd 0\nr 1\ng 1\nm 3\n", "[[r-i]-[m-e]]\nd -1\nr 1\ng ...
[ "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n" ]
CodeContests
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries. Jessie’s queries ar...
stdin
null
1,430
1
[ "4\nflour-with-eggs 100\nchicken-ham -10\nflour-without-eggs 200\nfish-with-pepper 1100\n6\nf\nflour-with\nflour-with-\nc\nfl\nchik\n" ]
[ "fish-with-pepper\nflour-without-eggs\nflour-with-eggs\nchicken-ham\nflour-without-eggs\nNO\n" ]
[ "4\nflour-with-eggs 100\nchicken-ham -10\nflour-without-eggs 200\nfish-with-pepper 1100\n6\nf\nflour-with\nflour-with-\nc\nfl\nciik\n", "4\nflour-with-eggs 100\nchicken-ham -10\nflour-without-eggs 200\nfish-with-pepper 1100\n6\nf\nflour-with\nflour-with-\nb\nfl\nciik\n", "4\nflour-with-eggs 100\nchicken-ham -10...
[ "fish-with-pepper\nflour-without-eggs\nflour-with-eggs\nchicken-ham\nflour-without-eggs\nNO\n", "fish-with-pepper\nflour-without-eggs\nflour-with-eggs\nNO\nflour-without-eggs\nNO\n", "fisg-with-pepper\nflour-without-eggs\nflour-with-eggs\nNO\nflour-without-eggs\nNO\n", "fisg-with-pepper\nflour-without-eggs\nN...
CodeContests
You are given an undirected graph consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. In addition, each vertex has a label, `A` or `B`. The label of Vertex i is s_i. Edge i bidirectionally connects vertex a_i and b_i. The phantom thief Nusook likes to choose some ...
stdin
null
2,562
1
[ "13 17\nBBABBBAABABBA\n7 1\n7 9\n11 12\n3 9\n11 9\n2 1\n11 5\n12 11\n10 8\n1 11\n1 8\n7 7\n9 10\n8 8\n8 12\n6 2\n13 11\n", "2 3\nAB\n1 1\n1 2\n2 2\n", "4 3\nABAB\n1 2\n2 3\n3 1\n", "13 23\nABAAAABBBBAAB\n7 1\n10 6\n1 11\n2 10\n2 8\n2 11\n11 12\n8 3\n7 12\n11 2\n13 13\n11 9\n4 1\n9 7\n9 6\n8 13\n8 6\n4 10\n8 7...
[ "No\n", "Yes\n", "No\n", "Yes\n" ]
[ "13 17\nBBABBBAABABBA\n7 1\n7 9\n11 12\n3 9\n11 9\n2 1\n11 5\n12 11\n10 8\n1 11\n1 8\n7 7\n9 10\n8 8\n8 12\n6 2\n9 11\n", "13 17\nBBABBBAABABBA\n7 1\n7 9\n11 12\n3 9\n11 9\n2 1\n11 5\n10 11\n10 8\n1 11\n1 8\n7 7\n9 10\n8 8\n8 12\n6 2\n9 11\n", "4 3\nABAB\n1 1\n2 3\n3 1\n", "13 17\nBBABBBAABABBA\n7 1\n7 9\n11 ...
[ "No\n", "Yes\n", "No\n", "No\n", "No\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n" ]
CodeContests
A: Flick input A college student who loves 2D, commonly known as 2D, replaced his long-used Galapagos mobile phone with a smartphone. 2D, who operated the smartphone for the first time, noticed that the character input method was a little different from that of old mobile phones. On smartphones, a method called flick ...
stdin
null
2,819
1
[ "5R2D\n" ]
[ "neko\n" ]
[ "5R3D\n", "5D2R\n", "5T2D\n", "5D3R\n", "5U2D\n", "4D2R\n", "6T2D\n", "3R5D\n", "4R2D\n", "6D2T\n" ]
[ "neso\n", "noke\n", "nako\n", "nose\n", "nuko\n", "toke\n", "hako\n", "seno\n", "teko\n", "hoka\n" ]
CodeContests
Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, w...
stdin
null
530
1
[ "15\nypnxn 279\nkgjgwx 464\nqquhuwq 327\nrxing 549\npmuduhznoaqu 832\ndagktgdarveusju 595\nwunfagppcoi 200\ndhavrncwfw 720\njpcmigg 658\nwrczqxycivdqn 639\nmcmkkbnjfeod 992\nhtqvkgkbhtytsz 130\ntwflegsjz 467\ndswxxrxuzzfhkp 989\nszfwtzfpnscgue 958\npmuduhznoaqu\n", "3\ndwango 2\nsixth 5\nprelims 25\ndwango\n", ...
[ "6348\n", "30\n", "0\n" ]
[ "15\nypnxn 279\nkgjgwx 464\nqquhuwq 327\nrxing 549\npmuduhznoaqu 832\ndagktgdarveusju 595\nwunfagppcoi 200\ndhavrncwfw 720\njpcmigg 658\nwrczqxycivdqn 639\nmcmkkbnjfeod 992\nzstythbkgkvqth 130\ntwflegsjz 467\ndswxxrxuzzfhkp 989\nszfwtzfpnscgue 958\npmuduhznoaqu\n", "1\nabcde 0000\nabcde\n", "15\nypnxn 279\nkgjf...
[ "6348\n", "0\n", "6690\n", "7105\n", "9\n", "6703\n", "6740\n", "6070\n", "6025\n", "12\n" ]
CodeContests
A calculator scholar has discovered a strange life form called an electronic fly that lives in electronic space. While observing the behavior of the electronic flies, the electronic flies at the (x, y, z) point in this space then move to (x', y', z') indicated by the following rules. I found out. <image> However, a1...
stdin
null
2,212
1
[ "2 5 3 7 6 13\n517 1024 746 6561 4303 3125\n0 0 0 0 0 0\n" ]
[ "12\n116640000\n" ]
[ "2 5 5 7 6 13\n517 1024 746 6561 4303 3125\n0 0 0 0 0 0\n", "2 5 5 7 6 13\n517 1334 746 6561 4303 3125\n0 0 0 0 0 0\n", "2 5 5 7 6 13\n517 1024 746 11315 4303 3125\n0 0 0 0 0 0\n", "2 5 5 7 6 13\n913 1334 1228 6561 4303 3125\n0 0 0 0 0 0\n", "2 5 5 7 6 13\n517 1024 746 14921 4303 3125\n0 0 0 0 0 0\n", "2 ...
[ "12\n116640000\n", "12\n140332500\n", "12\n1440000\n", "12\n420997500\n", "12\n581280000\n", "12\n922500\n", "12\n28066500\n", "12\n949280000\n", "12\n1845000\n", "12\n5613300\n" ]
CodeContests
Takahashi and Aoki love calculating things, so they will play with numbers now. First, they came up with one positive integer each. Takahashi came up with X, and Aoki came up with Y. Then, they will enjoy themselves by repeating the following operation K times: * Compute the bitwise AND of the number currently kept b...
stdin
null
1,246
1
[ "2 3 3\n11\n101\n", "10 10 10\n1100110011\n1011001101\n", "5 8 3\n10101\n10101001\n" ]
[ "10000\n10010\n", "10000100000010001000\n10000100000000100010\n", "100000\n10110100\n" ]
[ "5 8 3\n00101\n10101001\n", "5 8 3\n00101\n10100001\n", "5 8 5\n00101\n10110001\n", "5 8 5\n00101\n10110011\n", "5 8 3\n10101\n10100001\n", "5 8 3\n00100\n10101001\n", "5 8 5\n00101\n10000001\n", "5 8 5\n10101\n10110001\n", "10 10 14\n1100110011\n1011001101\n", "5 8 3\n10101\n10111001\n" ]
[ "10000\n10110100\n", "1000\n10100100\n", "1000\n10110100\n", "10010\n11000000\n", "11000\n10100100\n", "100\n10101001\n", "1000\n10000100\n", "101000\n11000100\n", "100001000000000010001000\n100001000000000000100010\n", "110000\n11010100\n" ]
CodeContests
You are given an integer N. For two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B. For example, F(3,11) = 2 since 3 has one digit and 11 has two digits. Find the minimum value of F...
stdin
null
2,647
1
[ "1000003\n", "10000\n", "9876543210\n" ]
[ "7\n", "3\n", "6\n" ]
[ "101914\n", "17346\n", "2771679283\n", "7026\n", "5110764300\n", "472\n", "10211397040\n", "16034112351\n", "010\n", "53937807463\n" ]
[ "5\n", "3\n", "9\n", "4\n", "7\n", "2\n", "6\n", "8\n", "1\n", "10\n" ]
CodeContests
Travelling by train is fun and exciting. But more than that indeed. Young challenging boys often tried to purchase the longest single tickets and to single ride the longest routes of various railway systems. Route planning was like solving puzzles. However, once assisted by computers, and supplied with machine readable...
stdin
null
4,906
1
[ "6 5\n 1 3 10\n 2 3 12\n 3 4 2\n 4 5 13\n 4 6 11\n10 10\n 1 2 11\n 2 3 25\n 2 5 81\n 2 6 82\n 4 5 58\n 5 9 68\n 6 7 80\n 6 9 67\n 8 9 44\n 9 10 21\n 0 0\n", "6 5\n1 3 10\n2 3 12\n3 4 2\n4 5 13\n4 6 11\n10 10\n1 2 11\n2 3 25\n2 5 81\n2 6 82\n4 5 58\n5 9 68\n6...
[ "27\n2 3 4 5\n378\n6 2 5 9 6 7\n", "27\n2 3 4 5\n378\n6 2 5 9 6 7\n" ]
[ "6 5\n1 3 10\n2 3 12\n3 4 2\n4 5 13\n4 6 11\n10 10\n1 2 11\n2 3 25\n2 5 81\n2 6 82\n4 5 58\n4 9 68\n6 7 80\n6 9 67\n8 9 44\n9 10 21\n0 0\n", "6 5\n 1 3 10\n 2 3 12\n 3 4 2\n 2 5 13\n 4 6 11\n10 10\n 1 2 11\n 2 3 25\n 2 5 81\n 2 6 82\n 4 5 58\n 5 9 68\n 6 7 ...
[ "27\n2 3 4 5\n436\n6 2 5 4 9 6 7\n", "38\n5 2 3 4 6\n378\n6 2 5 9 6 7\n", "27\n2 3 4 5\n421\n5 2 6 9 4 5 9 8\n", "27\n2 3 4 5\n459\n5 2 6 9 4 5 9 8\n", "25\n1 3 4 5\n459\n5 2 6 9 4 5 9 8\n", "25\n1 3 4 5\n378\n6 2 5 9 6 7\n", "27\n2 3 4 5\n461\n6 3 2 5 4 9 6 7\n", "25\n1 3 4 5\n438\n6 2 5 9 6 7\n", ...
CodeContests
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III. Constraints * $2 \leq n \leq 100$ * $0 \leq $ the integer assigned to a face $ \leq 100$ Input In the first line, the number of dices $n$ i...
stdin
null
713
1
[ "3\n1 2 3 4 5 6\n6 5 4 3 2 1\n5 4 3 2 1 6\n", "3\n1 2 3 4 5 6\n6 2 4 3 5 1\n6 5 4 3 2 1\n" ]
[ "Yes\n", "No\n" ]
[ "3\n1 2 3 4 5 6\n6 5 4 3 2 1\n5 4 0 2 1 6\n", "3\n1 2 3 4 5 6\n6 2 5 3 5 1\n6 5 4 3 2 1\n", "3\n1 2 3 4 5 6\n5 5 4 3 2 1\n5 4 0 2 1 6\n", "3\n1 2 3 4 5 6\n6 2 5 3 0 1\n6 5 4 3 2 1\n", "3\n1 2 3 3 5 6\n5 5 4 3 2 1\n5 4 0 2 1 6\n", "3\n1 4 3 4 5 6\n6 2 5 3 0 1\n6 5 4 3 2 1\n", "3\n1 2 3 3 5 6\n5 2 4 3 2 1...
[ "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n" ]
CodeContests
Divisor is the Conquerer is a solitaire card game. Although this simple game itself is a great way to pass one’s time, you, a programmer, always kill your time by programming. Your task is to write a computer program that automatically solves Divisor is the Conquerer games. Here is the rule of this game: First, you ra...
stdin
null
427
1
[ "5\n1 2 3 3 7\n4\n2 3 3 3\n0\n" ]
[ "3 3 1 7 2\nNo\n" ]
[ "5\n1 2 3 6 7\n4\n2 3 3 3\n0\n", "5\n1 2 6 6 7\n4\n2 3 3 3\n0\n", "5\n1 3 3 4 7\n4\n2 3 3 3\n0\n", "5\n1 2 3 3 7\n4\n2 3 2 3\n0\n", "5\n1 2 6 6 7\n4\n2 3 2 3\n0\n", "5\n1 2 3 6 7\n0\n2 5 3 3\n0\n", "5\n1 2 6 6 7\n0\n2 3 2 3\n0\n", "5\n1 2 3 9 7\n4\n2 5 3 3\n0\n", "5\n1 2 12 6 7\n0\n2 4 2 3\n0\n", ...
[ "No\nNo\n", "6 6 2 7 1\nNo\n", "7 1 4 3 3\nNo\n", "3 3 1 7 2\n3 3 2 2\n", "6 6 2 7 1\n3 3 2 2\n", "No\n", "6 6 2 7 1\n", "9 3 2 7 1\nNo\n", "12 6 2 1 7\n", "12 3 5 10 1\n" ]
CodeContests
AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two gestures, Rock and Paper, as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the ...
stdin
null
3,278
1
[ "gpg\n", "ggppgggpgg\n" ]
[ "0\n", "2\n" ]
[ "ggpgggppgg\n", "ggp\n", "ggggggpppg\n", "ggppgpgggg\n", "ggppggpggg\n", "gggpggppgg\n", "gggggpppgg\n", "pggpggpggg\n", "ggggpppggg\n", "gggpggpggp\n" ]
[ "2\n", "0\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n" ]
CodeContests
La Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each. Determine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes. Constraints * N is an integer between 1 and 10...
stdin
null
4,859
1
[ "40\n", "3\n", "11\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
[ "17\n", "22\n", "1\n", "19\n", "2\n", "9\n", "18\n", "4\n", "6\n", "15\n" ]
[ "No\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n" ]
CodeContests
C: Shuttle Run Story University H has a unique physical fitness test program, aiming to grow the mindset of students. Among the items in the program, shuttle run is well-known as especially eccentric one. Surprisingly, there are yokans (sweet beans jellies) on a route of the shuttle run. Greedy Homura-chan would like...
stdin
null
906
1
[ "1 3\n1 2\n" ]
[ "2\n" ]
[ "1 3\n1 4\n", "1 3\n1 5\n", "1 3\n1 10\n", "1 0\n0 2\n", "1 3\n1 1\n", "1 3\n1 9\n", "1 0\n0 0\n", "1 3\n0 15\n", "1 3\n2 12\n", "1 3\n2 24\n" ]
[ "4\n", "5\n", "10\n", "2\n", "1\n", "9\n", "0\n", "15\n", "12\n", "24\n" ]
CodeContests
She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since she is delicate, she w...
stdin
null
1,577
1
[ "2\n2\nYNNNNYYY\n4\nNYNNYYNNNYNYYNNN\n" ]
[ "6\n9\n" ]
[ "2\n2\nYNNNNYYY\n2\nNYNNYYNNNYNYYNNN\n", "2\n2\nYYZNNNNY\n2\nYYNNYNNNNYNYYNNN\n", "2\n2\nYYZNNNNY\n4\nNYNNYYNNNYNYYNNN\n", "2\n2\nYYZNNNNY\n4\nNNNYYNYNNNYYONYN\n", "2\n2\nYYZNYNNN\n4\nNNNYYNYNNNYYNNYN\n", "2\n2\nYNNNNYYY\n3\nNYNNYYNNNYNYYNNN\n", "2\n2\nNNNYNZYY\n0\nNNNYYNYNNNYYNNYN\n", "2\n2\nYYZNNNYN...
[ "6\n6\n", "6\n5\n", "6\n9\n", "6\n10\n", "5\n10\n", "6\n8\n", "6\n0\n", "5\n6\n", "6\n4\n", "6\n11\n" ]
CodeContests
A: Alphabet block Wakana Nakawa loves palindromes. Because my name is also a palindrome. Wakana got a set with some alphabet blocks. An alphabet block is a block in which one lowercase alphabet is written for each block, and you can create your favorite character string by changing the order of the blocks and combini...
stdin
null
3,214
1
[ "hcpc\n" ]
[ "1\n" ]
[ "gcpc\n", "bgnc\n", "gcoc\n", "gcnc\n", "cgnc\n", "bcng\n", "bcnh\n", "hncb\n", "bnch\n", "boch\n" ]
[ "1\n", "2\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n" ]
CodeContests
All bandits are afraid of Sheriff. Sheriff constantly fights crime, but when bandits lay low, he gets bored and starts to entertain himself. This time Sheriff gathered all the bandits in his garden and ordered them to line up. After the whistle all bandits should change the order in which they stand. Sheriff gave all...
stdin
null
4,329
1
[ "2\n3\n1 2 3\n5\n2 3 1 5 4\n" ]
[ "1\n6\n" ]
[ "2\n2\n1 2 3\n5\n2 3 1 5 4\n", "2\n3\n1 2 3\n5\n4 3 1 5 2\n", "2\n3\n2 1 3\n5\n4 3 1 5 2\n", "2\n2\n1 2 3\n5\n4 3 1 5 2\n", "2\n1\n1 2 3\n5\n2 3 1 5 4\n", "2\n1\n1 2 3\n5\n4 3 1 5 2\n", "2\n2\n2 1 3\n5\n4 3 1 5 2\n", "2\n2\n1 2 3\n5\n4 3 2 5 1\n" ]
[ "1\n6\n", "1\n5\n", "2\n5\n", "1\n5\n", "1\n6\n", "1\n5\n", "2\n5\n", "1\n6\n" ]
CodeContests
You have a matrix of size N * N with rows numbered through 1 to N from top to bottom and columns through 1 to N from left to right. It contains all values from 1 to N^2, i.e. each value from 1 to N^2 occurs exactly once in the matrix. Now, you start from the cell containing value 1, and from there visit the cell with...
stdin
null
4,765
1
[ "2\n2\n1 3\n2 4\n3\n1 7 9\n2 4 8\n3 6 5\n" ]
[ "4\n12\n" ]
[ "2\n2\n1 3\n2 4\n3\n2 7 9\n1 4 8\n3 6 5\n", "2\n2\n1 3\n2 4\n3\n1 7 9\n3 4 8\n2 6 5\n", "2\n2\n1 3\n2 4\n3\n1 7 9\n2 4 8\n6 3 5\n", "2\n2\n1 3\n2 4\n3\n1 7 5\n2 4 8\n6 3 9\n", "2\n2\n2 3\n1 4\n3\n2 7 9\n1 4 8\n3 6 5\n", "2\n2\n1 3\n2 4\n3\n2 7 9\n1 3 8\n4 6 5\n" ]
[ "4\n13\n", "4\n12\n", "4\n14\n", "4\n16\n", "3\n13\n", "4\n13\n" ]
CodeContests
Given is a positive integer L. Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L. Constraints * 1 ≤ L ≤ 1000 * L is an integer. Input Input is given from Standard Input in the following format: L Output Print the maximum possible volume of a re...
stdin
null
4,539
1
[ "999\n", "3\n" ]
[ "36926037.000000000000\n", "1.000000000000\n" ]
[ "5\n", "8\n", "0\n", "1\n", "2\n", "4\n", "7\n", "13\n", "6\n", "11\n" ]
[ "4.62962962963\n", "18.962962963\n", "0.0\n", "0.037037037037\n", "0.296296296296\n", "2.37037037037\n", "12.7037037037\n", "81.3703703704\n", "8.0\n", "49.2962962963\n" ]
CodeContests
Problem Statement Unseen gang is the team of most wanted criminal. Unseen gang has planted bombs in different street and corner of the city. Gang members are sitting in the other part of the city, far away from the bomb site. They are controlling the bomb by sending the activation signal in the form of encrypted code....
stdin
null
561
1
[ "Vhaveplanted bomb @allthe location intheCITY.\n8\n\nSAMPLE\n" ]
[ "Vhavepla\nnted bom\nb @allth\ne locati\non inthe\nCITY.\n" ]
[ "Vhaveplanted bpmb @allthe location intheCITY.\n8\n\nSAMPLE\n", "Vhaveplanted bpmb ehtlla@ location intheCITY.\n8\n\nRAMQLE\n", "Vhaveplanted bpmb dhtlla@ location intheCITY.\n8\n\nRAMQLE\n", "Vhaveplanted bpmb dhtlla@ location intheCITY/\n8\n\nRAMQLE\n", "Vhbveplanted bpmb dhtlla@ location intheCITY/\n8\n\...
[ "Vhavepla\nnted bpm\nb @allth\ne locati\non inthe\nCITY.\n", "Vhavepla\nnted bpm\nb ehtlla\n@ locati\non inthe\nCITY.\n", "Vhavepla\nnted bpm\nb dhtlla\n@ locati\non inthe\nCITY.\n", "Vhavepla\nnted bpm\nb dhtlla\n@ locati\non inthe\nCITY/\n", "Vhbvepla\nnted bpm\nb dhtlla\n@ locati\non inthe\nCITY/\n", "...
CodeContests
Today RK has to transport his N items of different weights(in calories) to a near city but before that he wants to make sure that the weights of all items are balanced. In order to check this he puts all items on the weight scale and found that weights are not balanced actually. So to deal with it RK designed his own p...
stdin
null
4,175
1
[ "2\n3\n3 6 9\n2\n2 2\n\nSAMPLE\n" ]
[ "9\n4\n" ]
[ "4\n5\n2 3 5 8 18\n5\n2 4 1 6 8\n3\n12 20 5\n3\n6 10 15\n", "10\n20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51\n50\n58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58\n98\n70 60 100 30 70 20 30 50 ...
[ "5\n5\n3\n3\n", "1020\n2900\n980\n8200\n100\n2\n12\n2\n2\n2\n", "700\n819\n4130\n1914\n945\n273\n324\n46\n770\n120\n", "1020\n2900\n980\n100\n100\n2\n12\n2\n2\n2\n", "700\n819\n4130\n1914\n945\n273\n324\n46\n70\n120\n", "1020\n2900\n98\n100\n100\n2\n12\n2\n2\n2\n", "700\n819\n59\n1914\n945\n273\n324\n46...
CodeContests
Dr. Hedro is astonished. According to his theory, we can make sludge that can dissolve almost everything on the earth. Now he's trying to produce the sludge to verify his theory. The sludge is produced in a rectangular solid shaped tank whose size is N × N × 2. Let coordinate of two corner points of tank be (-N/2, -N/...
stdin
null
4,354
1
[ "2\n4\n0\n" ]
[ "24\n64\n" ]
[ "2\n8\n0\n", "2\n6\n0\n", "2\n2\n0\n", "2\n0\n0\n", "2\n14\n0\n", "2\n12\n0\n", "2\n10\n0\n", "2\n18\n0\n", "2\n24\n0\n", "2\n0\n1\n" ]
[ "24\n160\n", "24\n112\n", "24\n24\n", "24\n", "24\n328\n", "24\n264\n", "24\n216\n", "24\n440\n", "24\n608\n", "24\n" ]
CodeContests
<image> Matryoshka is a wooden doll in the shape of a female figure and is a typical Russian folk craft. Matryoshka has a nested structure in which smaller dolls are contained inside a large doll, and is composed of multiple dolls of different sizes. In order to have such a nested structure, the body of each doll has ...
stdin
null
2,172
1
[ "6\n1 1\n4 3\n6 5\n8 6\n10 10\n14 14\n5\n2 2\n5 4\n6 6\n9 8\n15 10\n4\n1 1\n4 3\n6 5\n8 6\n3\n2 2\n5 4\n6 6\n4\n1 1\n4 3\n6 5\n8 6\n4\n10 10\n12 11\n18 15\n24 20\n0\n" ]
[ "9\n6\n8\n" ]
[ "6\n1 1\n4 3\n6 5\n8 6\n10 10\n14 14\n5\n2 1\n5 4\n6 6\n9 8\n15 10\n4\n1 1\n4 3\n6 5\n8 6\n3\n2 2\n5 4\n6 6\n4\n1 1\n4 3\n6 5\n8 6\n4\n10 10\n12 11\n18 15\n24 20\n0\n", "6\n1 1\n4 3\n6 5\n8 6\n10 10\n14 14\n5\n2 2\n5 4\n6 6\n9 8\n15 10\n4\n1 1\n4 3\n6 5\n8 6\n3\n2 2\n5 4\n6 6\n4\n1 2\n4 3\n6 5\n8 6\n4\n10 10\n12 ...
[ "8\n6\n8\n", "9\n6\n8\n", "9\n5\n8\n", "8\n5\n8\n", "7\n5\n8\n", "8\n4\n8\n", "7\n4\n8\n", "9\n4\n8\n", "7\n6\n8\n", "8\n5\n7\n" ]
CodeContests
Traveling around the universe Benny saw some strange numbers. These numbers are called Universal numbers. Benny asks you to help her to calculate the number of Universal numbers on some segments. First of all, you are given 15 numbers called remsi. The number is Universal if and only if it satisfies the following c...
stdin
null
480
1
[ "0 1 0 0 0 0 0 0 1 1 1 2 3 4 5\n1\n13 16\n\nSAMPLE\n" ]
[ "1\n" ]
[ "0 1 1 0 2 2 2 2 0 2 1 1 2 0 0\n1000\n620 999571\n626 999523\n738 999939\n1157 999335\n494 999039\n933 999280\n997 999727\n78 999899\n71 999243\n102 999229\n1042 999118\n1020 999961\n1232 999598\n63 999781\n75 999493\n935 999923\n272 999387\n178 999619\n1179 999259\n695 999322\n975 999012\n676 999325\n1016 999526\n...
[ "1928\n1928\n1915\n1885\n1943\n1896\n1891\n1993\n1995\n1989\n1890\n1890\n1882\n1996\n1993\n1896\n1967\n1980\n1885\n1922\n1893\n1924\n1890\n1958\n1958\n1895\n1887\n2003\n1899\n1958\n1948\n1946\n1902\n1914\n1958\n1890\n1954\n1999\n1891\n1922\n1887\n1958\n1888\n2008\n1955\n1973\n1891\n1885\n1943\n1890\n1914\n1890\n191...
CodeContests
Write a program which manipulates a weighted rooted tree $T$ with the following operations: * $add(v,w)$: add $w$ to all edges from the root to node $u$ * $getSum(u)$: report the sum of weights of all edges from the root to node $u$ The given tree $T$ consists of $n$ nodes and every node has a unique ID from $0$ t...
stdin
null
4,172
1
[ "4\n1 1\n1 2\n1 3\n0\n6\n0 3 1000\n0 2 1000\n0 1 1000\n1 1\n1 2\n1 3\n", "6\n2 1 2\n2 3 5\n0\n0\n0\n1 4\n7\n1 1\n0 3 10\n1 2\n0 4 20\n1 3\n0 5 40\n1 4\n" ]
[ "3000\n5000\n6000\n", "0\n0\n40\n150\n" ]
[ "4\n1 1\n1 2\n1 3\n0\n6\n0 3 1000\n0 2 1000\n0 1 1001\n1 1\n1 2\n1 3\n", "4\n1 1\n1 2\n1 3\n0\n6\n0 3 1000\n0 2 1000\n0 1 1001\n1 0\n1 2\n1 3\n", "6\n2 1 2\n2 3 5\n0\n0\n0\n1 4\n7\n1 1\n0 3 6\n1 2\n0 4 20\n1 3\n0 5 40\n1 4\n", "4\n1 1\n1 2\n1 3\n0\n6\n0 0 1000\n0 2 1000\n0 1 1001\n1 1\n1 2\n1 3\n", "4\n1 1\...
[ "3001\n5001\n6001\n", "0\n5001\n6001\n", "0\n0\n32\n146\n", "2001\n3001\n3001\n", "0\n6002\n7002\n", "0\n6000\n7000\n", "3001\n4001\n4001\n", "0\n6202\n7202\n", "0\n6202\n6202\n", "0\n6222\n6222\n" ]
CodeContests
Chandu is a bad student. Once his teacher asked him to print the reverse of a given string. He took three hours to solve it. The teacher got agitated at Chandu and asked you the same question. Can you solve it? Input: The first line contains an integer T, denoting the number of test cases. Each test case contains a s...
stdin
null
4,027
1
[ "2\nab\naba\n\nSAMPLE\n" ]
[ "ba\naba\n" ]
[ "5\nb\naa\naaa\nabcdefghijklmnopqrstuvwxyz\nababababababa\n", "2\nab\naba\n\nSLMPAE\n", "5\nb\naa\naaa\nabcdefghijklmnopqrstuvwxyz\nabacababababa\n", "2\nba\naba\n\nSLMPAE\n", "5\nb\naa\naaa\nzyxwvutsrqponmlkjihgfedcba\nabacababababa\n", "5\na\naa\naaa\nabcdefghijklmnopqrstuvwxyz\nabacababababa\n", "2\n...
[ "b\naa\naaa\nzyxwvutsrqponmlkjihgfedcba\nababababababa\n", "ba\naba\n", "b\naa\naaa\nzyxwvutsrqponmlkjihgfedcba\nababababacaba\n", "ab\naba\n", "b\naa\naaa\nabcdefghijklmnopqrstuvwxyz\nababababacaba\n", "a\naa\naaa\nzyxwvutsrqponmlkjihgfedcba\nababababacaba\n", "ab\naaa\n", "a\naa\naaa\nzyxwvutsrqponm...
CodeContests
Given is a string S. Each character in S is either a digit (`0`, ..., `9`) or `?`. Among the integers obtained by replacing each occurrence of `?` with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0. Since the answer can be enormous, print the count modulo 10^9+7. Constraints...
stdin
null
2,284
1
[ "7?4\n", "??2??5\n", "?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???\n", "?44\n" ]
[ "0\n", "768\n", "153716888\n", "1\n" ]
[ "74?\n", "??1??5\n", "?6?42???8??29?06243????9??3???7258??5??7???????774????4?1??17?????5?70???76???\n", "??1??6\n", "???67???07?5?????71??1?4????477???????7??5??8527???3??9????34260?92??8???24?6?\n", "6?1???\n", "54?\n", "??15??\n", "???67???07?5?????71??1?4????477???????7??5??8527???3??9????33260?...
[ "1\n", "768\n", "153716829\n", "772\n", "153716660\n", "769\n", "0\n", "770\n", "153716813\n", "153716828\n" ]
CodeContests
The first crossword puzzle was published on December 21, 1913 by Arthur Wynne. To celebrate the centennial of his great-great-grandfather's invention, John "Coward" Wynne1 was struggling to make crossword puzzles. He was such a coward that whenever he thought of a tricky clue for a word, he couldn’t stop worrying if pe...
stdin
null
898
1
[ "2 2\n^(C|I|T|Y)*$\n^(C|O|P|S)*$\n^(F|L|I|P)*$\n^(B|A|C|K)*$\n2 2\n^HE|LL|O*$\n^(P|L|E|A|S|E)*$\n^(H|L)*$\n^EP|IP|EF$\n4 4\n^LONG|TALL|S*ALLY$\n^(R*EV*|OL*U(TIO)*N)*$\n^(STRAWBERRY|F*I*E*L*D*S*|FOREVER)*$\n^P.S.|I|LOVE|YOU$\n^(RE|A|L)((L|OV*E)*)$\n^(LUC*Y*|IN.THE.SKY)(WITH|DI*A*M*ON*D*S*)$\n^(IVE*|GOT|A|F*E*E*L*I*N...
[ "IC\nPC\nHE\nLP\nALLY\nOUNE\nEDIS\nLOVE\nambiguous\nnone\nARKA\nNSAS\n" ]
[ "2 2\n^(C|I|T|Y)*$\n^(C|O|P|S)*$\n^(F|L|I|P)*$\n^(B|A|C|K)*$\n2 2\n^HE|LL|O*$\n^(P|L|E|A|S|E)*$\n^(H|L)*$\n^EP|IP|FE$\n4 4\n^LONG|TALL|S*ALLY$\n^(R*EV*|OL*U(TIO)*N)*$\n^(STRAWBERRY|F*I*E*L*D*S*|FOREVER)*$\n^P.S.|I|LOVE|YOU$\n^(RE|A|L)((L|OV*E)*)$\n^(LUC*Y*|IN.THE.SKY)(WITH|DI*A*M*ON*D*S*)$\n^(IVE*|GOT|A|F*E*E*L*I*N...
[ "IC\nPC\nHE\nLP\nALLY\nOUNE\nEDIS\nLOVE\nambiguous\nnone\nnone\n", "IC\nPC\nHE\nLP\nnone\nambiguous\nnone\nnone\n", "IC\nPC\nnone\nnone\nambiguous\nnone\nnone\n", "IC\nPC\nHE\nLP\nALLY\nOUNE\nEDIS\nLOVE\nnone\nnone\nnone\n", "IC\nPC\nnone\nALLY\nOUNE\nEDIS\nLOVE\nambiguous\nnone\nnone\n", "none\nnone\nnon...
CodeContests
Write a program that takes in a letterclass ID of a ship and display the equivalent string class description of the given ID. Use the table below. Class ID Ship Class B or b BattleShip C or c Cruiser D or d Destroyer F or f Frigate Input The first line contains an integer T, total number of testcases. Then...
stdin
null
673
1
[ "3 \nB\nc\nD\n" ]
[ "BattleShip\nCruiser\nDestroyer\n" ]
[ "3 \nC\nc\nD\n", "3 \nB\nc\nC\n", "3 \nB\nc\nB\n", "3 \nC\nc\nB\n", "3 \nC\nb\nB\n", "3 \nB\nd\nD\n", "3 \nC\nd\nD\n", "3 \nB\nd\nC\n", "3 \nC\nd\nB\n", "3 \nD\nc\nB\n" ]
[ "Cruiser\nCruiser\nDestroyer\n", "BattleShip\nCruiser\nCruiser\n", "BattleShip\nCruiser\nBattleShip\n", "Cruiser\nCruiser\nBattleShip\n", "Cruiser\nBattleShip\nBattleShip\n", "BattleShip\nDestroyer\nDestroyer\n", "Cruiser\nDestroyer\nDestroyer\n", "BattleShip\nDestroyer\nCruiser\n", "Cruiser\nDestro...
CodeContests
Problem Statement Little Elephant from Zoo of Lviv likes bamboo very much. He currently has n stems of bamboo, Hi - height of i-th stem of bamboo (0-based numeration). Today inspector Andrii from World Bamboo Association is visiting the plantation. He doesn't like current situation. He wants the height of i-th stem t...
stdin
null
5,036
1
[ "3\n1\n1\n2\n2\n1 2\n2 1\n3\n3 2 2\n4 5 3\n" ]
[ "-1\n1\n5\n" ]
[ "3\n1\n1\n2\n2\n1 2\n2 1\n1\n3 2 2\n4 5 3\n", "3\n1\n1\n2\n2\n0 2\n2 1\n1\n3 2 2\n4 5 3\n", "3\n1\n1\n2\n2\n2 2\n2 1\n3\n3 2 2\n4 5 3\n", "3\n1\n0\n2\n2\n0 2\n2 0\n1\n3 2 2\n4 5 3\n", "3\n1\n2\n2\n2\n2 2\n2 1\n1\n3 2 2\n4 5 3\n", "3\n1\n1\n0\n2\n1 1\n2 0\n2\n3 0 7\n6 5 5\n", "3\n1\n1\n0\n2\n0 1\n3 1\n1\...
[ "-1\n1\n-1\n", "-1\n-1\n-1\n", "-1\n-1\n5\n", "-1\n2\n-1\n", "0\n-1\n-1\n", "1\n1\n-1\n", "1\n-1\n-1\n", "-1\n-1\n7\n", "-1\n1\n5\n", "0\n1\n-1\n" ]
CodeContests
The game of billiards involves two players knocking 3 balls around on a green baize table. Well, there is more to it, but for our purposes this is sufficient. The game consists of several rounds and in each round both players obtain a score, based on how well they played. Once all the rounds have been played, the tota...
stdin
null
4,727
1
[ "5\n140 82\n89 134\n90 110\n112 106\n88 90\n" ]
[ "1 58\n" ]
[ "5\n140 82\n89 134\n90 110\n177 106\n88 90\n", "5\n140 82\n89 134\n90 110\n289 106\n88 90\n", "5\n140 82\n89 134\n90 110\n289 50\n88 90\n", "5\n140 82\n89 134\n107 110\n289 50\n88 90\n", "5\n140 82\n89 134\n107 110\n289 4\n88 90\n", "5\n140 82\n89 134\n44 110\n184 4\n88 90\n", "5\n140 82\n97 134\n44 110...
[ "1 64\n", "1 176\n", "1 232\n", "1 249\n", "1 295\n", "1 127\n", "1 135\n", "1 172\n", "1 58\n", "2 98\n" ]
CodeContests
You are given a rooted tree with N vertices. The vertices are numbered 0, 1, ..., N-1. The root is Vertex 0, and the parent of Vertex i (i = 1, 2, ..., N-1) is Vertex p_i. Initially, an integer a_i is written in Vertex i. Here, (a_0, a_1, ..., a_{N-1}) is a permutation of (0, 1, ..., N-1). You can execute the followi...
stdin
null
2,167
1
[ "5\n0 1 2 3\n2 4 0 1 3\n", "5\n0 1 2 2\n4 3 1 2 0\n" ]
[ "2\n3\n4\n", "3\n4\n3\n1\n" ]
[ "5\n0 1 0 3\n2 4 0 1 3\n", "5\n0 1 2 2\n2 4 0 1 3\n", "5\n0 1 1 3\n2 4 0 1 3\n", "5\n0 0 2 2\n4 3 1 2 0\n", "5\n0 1 0 2\n4 3 1 2 0\n", "5\n0 0 1 3\n2 4 0 1 3\n", "5\n0 0 2 3\n4 3 1 2 0\n", "5\n0 0 1 2\n2 4 0 1 3\n", "5\n0 1 2 3\n4 3 1 2 0\n", "5\n0 1 2 1\n4 3 1 2 0\n" ]
[ "3\n2\n4\n1\n", "5\n3\n4\n2\n2\n3\n", "2\n2\n4\n", "3\n4\n1\n3\n", "4\n4\n3\n2\n1\n", "3\n2\n1\n4\n", "4\n4\n1\n3\n2\n", "4\n4\n1\n4\n3\n", "4\n4\n3\n2\n2\n", "2\n4\n3\n" ]
CodeContests
Jerry is a little mouse. He is trying to survive from the cat Tom. Jerry is carrying a parallelepiped-like piece of cheese of size A × B × C. It is necessary to trail this cheese to the Jerry's house. There are several entrances in the Jerry's house. Each entrance is a rounded hole having its own radius R. Could you he...
stdin
null
2,849
1
[ "10 6 8\n5\n4\n8\n6\n2\n5\n0 0 0\n" ]
[ "NA\nOK\nOK\nNA\nNA\n" ]
[ "10 6 8\n5\n4\n1\n6\n2\n5\n0 0 0\n", "10 6 8\n5\n4\n0\n0\n2\n5\n0 0 0\n", "10 6 8\n5\n4\n0\n0\n2\n7\n0 0 0\n", "10 6 8\n5\n1\n8\n6\n2\n5\n0 0 0\n", "10 6 4\n5\n4\n0\n-1\n2\n7\n0 0 0\n", "10 6 4\n5\n4\n0\n-1\n4\n7\n0 0 0\n", "10 3 8\n5\n4\n0\n6\n2\n5\n0 0 0\n", "10 6 8\n5\n1\n8\n3\n2\n5\n0 0 0\n", "1...
[ "NA\nNA\nOK\nNA\nNA\n", "NA\nNA\nNA\nNA\nNA\n", "NA\nNA\nNA\nNA\nOK\n", "NA\nOK\nOK\nNA\nNA\n", "OK\nNA\nNA\nNA\nOK\n", "OK\nNA\nNA\nOK\nOK\n", "NA\nNA\nOK\nNA\nOK\n", "NA\nOK\nNA\nNA\nNA\n", "NA\nOK\nOK\nNA\nOK\n", "NA\nNA\nNA\nOK\nOK\n" ]
CodeContests
Ranjit wants to design a algorithm such that, if he enters two numbers, all the numbers between these two numbers are listed(except the number divisible by 5 & 3). BUT the number divisible by both 3 & 5 is also listed (example 30) The Numbers should be separated by a "," sign Example- if the two numbers added are- 25...
stdin
null
2,990
1
[ "25 44\n\nSAMPLE\n" ]
[ "26,28,29,30,31,32,34,37,38,41,43\n" ]
[ "110 125\n", "21 62\n", "25 28\n\nSAMPLE\n", "4 62\n", "2 62\n", "0 62\n", "0 77\n", "1 77\n", "1 3\n", "0 3\n" ]
[ "112,113,116,118,119,120,121,122,124\n", "22,23,26,28,29,30,31,32,34,37,38,41,43,44,45,46,47,49,52,53,56,58,59,60,61\n", "26\n", "7,8,11,13,14,15,16,17,19,22,23,26,28,29,30,31,32,34,37,38,41,43,44,45,46,47,49,52,53,56,58,59,60,61\n", "4,7,8,11,13,14,15,16,17,19,22,23,26,28,29,30,31,32,34,37,38,41,43,44,45,4...
CodeContests
Two sweet dogs, Bernard and Havanese, play the following game. There are P sticks, each of exactly Q meters in length. The dogs move in turns. For each move a dog chooses a stick and splits it into two or more equal parts each having integer length greater than or equal to S meters. Each resulting part is also a stick....
stdin
null
2,191
1
[ "2\n1 15 4\n4 9 5\n\nSAMPLE\n" ]
[ "Bernard\nHavanese\n" ]
[ "10\n1 2 2\n2 1 1 \n1000000000 1000000000 1000000000\n999999999 735134400 1\n999999999 735134400 100\n787965358 999999986 2\n588462355 999999986 2\n994427144 999999986 10\n431525232 1643298664 250000000\n502291145 999999986 250000000\n", "2\n1 15 4\n4 ...
[ "Havanese\nHavanese\nHavanese\nBernard\nBernard\nHavanese\nBernard\nHavanese\nHavanese\nBernard\n", "Bernard\nHavanese\n", "Havanese\nHavanese\nHavanese\nBernard\nHavanese\nHavanese\nBernard\nHavanese\nHavanese\nBernard\n", "Havanese\nHavanese\n", "Havanese\nHavanese\nHavanese\nBernard\nBernard\nHavanese\nB...
CodeContests
Squid loves painting vertices in graphs. There is a simple undirected graph consisting of N vertices numbered 1 through N, and M edges. Initially, all the vertices are painted in color 0. The i-th edge bidirectionally connects two vertices a_i and b_i. The length of every edge is 1. Squid performed Q operations on th...
stdin
null
3,679
1
[ "14 10\n1 4\n5 7\n7 11\n4 10\n14 7\n14 3\n6 14\n8 11\n5 13\n8 3\n8\n8 6 2\n9 7 85\n6 9 3\n6 7 5\n10 3 1\n12 9 4\n9 6 6\n8 2 3\n", "7 7\n1 2\n1 3\n1 4\n4 5\n5 6\n5 7\n2 3\n2\n6 1 1\n1 2 2\n" ]
[ "1\n0\n3\n1\n5\n5\n3\n3\n6\n1\n3\n4\n5\n3\n", "2\n2\n2\n2\n2\n1\n0\n" ]
[ "14 10\n1 4\n5 7\n7 11\n4 10\n14 7\n14 3\n6 14\n8 11\n5 13\n8 3\n8\n8 6 2\n14 7 85\n6 9 3\n6 7 5\n10 3 1\n12 9 4\n9 6 6\n8 2 3\n", "14 10\n1 4\n5 7\n7 11\n2 10\n14 7\n14 3\n6 14\n8 11\n5 13\n8 3\n8\n8 6 2\n14 7 85\n6 9 6\n6 7 5\n10 3 1\n12 9 4\n9 6 6\n8 2 3\n", "14 10\n1 4\n5 7\n7 11\n2 10\n14 7\n14 3\n6 14\n8 ...
[ "1\n0\n3\n1\n5\n5\n3\n3\n6\n1\n3\n4\n5\n3\n", "0\n1\n3\n0\n5\n5\n3\n3\n6\n1\n3\n4\n5\n3\n", "0\n1\n3\n0\n3\n3\n3\n3\n6\n1\n3\n4\n3\n3\n", "0\n0\n6\n0\n6\n6\n6\n6\n0\n0\n6\n0\n6\n6\n", "0\n0\n6\n0\n0\n6\n6\n6\n6\n0\n6\n0\n0\n6\n", "1\n0\n3\n1\n0\n5\n3\n3\n6\n1\n3\n4\n0\n3\n", "2\n2\n2\n2\n2\n1\n0\n", "...
CodeContests
Nathan O. Davis is trying to capture a game and struggling to get a very rare item. This rare item can be obtained by arranging special patterns in a row on a casino slot machine. The slot machine has N reels, and pressing the button once stops the currently rotating leftmost reel. Therefore, you need to press the butt...
stdin
null
1,582
1
[ "1 5 7 11 10\n10\n2 5 7 11 10\n2 4\n2 1 1 256 0\n128 255\n2 0 0 1 0\n1234 5678\n2 1 1 100 0\n99 98\n2 1 1 100 0\n99 99\n2 1 1 10000 0\n1 0\n2 1 1 10000 0\n2 1\n0 0 0 0 0\n" ]
[ "0\n3\n255\n-1\n198\n199\n10000\n-1\n" ]
[ "1 5 7 11 10\n10\n2 5 7 11 10\n2 4\n2 1 1 256 0\n128 255\n2 0 0 1 0\n1234 5678\n2 1 1 100 0\n99 98\n2 1 1 100 0\n99 99\n2 1 1 10000 0\n1 0\n2 1 2 10000 0\n2 1\n0 0 0 0 0\n", "1 5 7 11 10\n10\n2 5 5 11 10\n2 4\n2 1 1 256 0\n128 255\n2 0 0 1 0\n1234 5678\n2 1 1 100 0\n99 98\n2 1 1 100 0\n99 99\n2 1 1 10000 0\n1 0\n...
[ "0\n3\n255\n-1\n198\n199\n10000\n-1\n", "0\n-1\n255\n-1\n198\n199\n10000\n-1\n", "0\n-1\n-1\n-1\n198\n199\n10000\n-1\n", "0\n3\n-1\n-1\n198\n199\n10000\n-1\n", "0\n3\n255\n-1\n198\n199\n-1\n-1\n", "-1\n-1\n255\n-1\n198\n199\n10000\n-1\n", "-1\n-1\n-1\n-1\n198\n199\n10000\n-1\n", "0\n-1\n-1\n-1\n198\n1...
CodeContests
ACT I Handi Bhaiya is a very notorious kid and always troubles his parents and friends. One day his naughtiness lead him to a demon Kali(THE COBRA COMMANDER) who trapped him into a triangular magic cell. Handi Bhaiya parents want their kid back and asks for your help. ACT II You knew that the entire humanity will hate...
stdin
null
4,217
1
[ "4\n15 15 15\n13 13 14\n3 4 5\n10 12 23\n\nSAMPLE\n" ]
[ "YES. It is a equilateral triangle.\nYES. It is a isosceles triangle.\nYES. It is a scalene triangle.\nNO\n" ]
[ "4\n13 15 15\n13 13 14\n3 4 5\n10 12 23\n\nSAMPLE\n", "4\n13 27 15\n13 13 14\n3 4 5\n10 12 23\n\nSAMPLE\n", "4\n1 27 15\n13 13 14\n2 4 5\n10 12 23\n\nSAMPLF\n", "4\n1 27 15\n13 5 14\n2 6 5\n10 12 23\n\nSAMPLF\n", "4\n2 27 15\n13 6 14\n2 6 3\n10 12 23\n\nSAMPLF\n", "4\n2 27 15\n13 6 14\n2 6 3\n10 12 20\n\n...
[ "YES. It is a isosceles triangle.\nYES. It is a isosceles triangle.\nYES. It is a scalene triangle.\nNO\n", "YES. It is a scalene triangle.\nYES. It is a isosceles triangle.\nYES. It is a scalene triangle.\nNO\n", "NO\nYES. It is a isosceles triangle.\nYES. It is a scalene triangle.\nNO\n", "NO\nYES. It is a ...
CodeContests
There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i; Edge i has a weight of Y_i and connects Vertex A_i and B_i. We would like to remove zero o...
stdin
null
217
1
[ "10 9\n81 16 73 7 2 61 86 38 90 28\n6 8 725\n3 10 12\n1 4 558\n4 9 615\n5 6 942\n8 9 918\n2 7 720\n4 7 292\n7 10 414\n", "4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18\n", "6 10\n4 4 1 1 1 7\n3 5 19\n2 5 20\n4 5 8\n1 6 16\n2 3 9\n3 6 16\n3 4 1\n2 6 20\n2 4 19\n1 2 9\n" ]
[ "8\n", "2\n", "4\n" ]
[ "4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 21\n3 4 18\n", "4 4\n2 3 1 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18\n", "4 4\n2 3 5 7\n1 4 7\n1 2 9\n1 3 15\n3 4 18\n", "6 10\n2 4 1 1 1 7\n3 5 19\n2 5 8\n4 5 5\n1 6 16\n2 5 9\n3 6 16\n3 4 1\n2 6 20\n1 4 19\n1 2 9\n", "6 10\n2 8 1 1 1 7\n3 5 19\n2 5 8\n4 5 5\n1 6 16\n2 5 9\n3 6 16\n3...
[ "2\n", "4\n", "1\n", "3\n", "0\n", "8\n", "9\n", "5\n", "4\n", "2\n" ]
CodeContests
You have an unbiased dice which you want to keep rolling until you get N consecutive even numbers. You've rolled the dice M times and surprisingly, all rolls resulted in even numbers. What is the expected number of additional rolls needed until you get N consecutive even numbers? Input: The first line contains the n...
stdin
null
2,153
1
[ "4\n2 0\n2 1\n3 3\n3 2\n\nSAMPLE\n" ]
[ "6.00\n4.00\n0.00\n8.00\n" ]
[ "25\n6 6\n20 7\n17 8\n11 9\n23 9\n22 19\n2 1\n10 8\n20 20\n5 4\n9 8\n4 4\n4 2\n19 11\n6 0\n2 1\n9 8\n23 1\n25 16\n5 1\n22 18\n17 9\n14 17\n17 6\n13 11\n", "10\n7 2\n8 2\n7 7\n7 2\n5 4\n5 3\n3 1\n4 2\n1 0\n12 2\n", "4\n2 0\n2 1\n3 3\n1 2\n\nSAMPLE\n", "25\n6 6\n20 7\n17 8\n11 9\n23 9\n22 19\n0 1\n10 8\n20 20\n...
[ "0.00\n2096896.00\n261632.00\n3072.00\n16776192.00\n7340032.00\n4.00\n1536.00\n0.00\n32.00\n512.00\n0.00\n24.00\n1044480.00\n126.00\n4.00\n512.00\n16777212.00\n66977792.00\n60.00\n7864320.00\n261120.00\n-229376.00\n262016.00\n12288.00\n", "248.00\n504.00\n0.00\n248.00\n32.00\n48.00\n12.00\n24.00\n2.00\n8184.00\n"...
CodeContests
Bangalore City, where peace prevails most of the time. Not everyone is a huge fan of peace, though. Certainly not Mr. XYZ, whose identity is not known to us - yet. Mr. XYZ has somehow managed to bring vampires and zombies to Bangalore City to attack and destroy the city. Fatal Eagle, an ordinary citizen of the city is...
stdin
null
1,083
1
[ "6\n2 3 10 12 15 22\n\nSAMPLE\n" ]
[ "2 10 12 22 46 3 15 18\n" ]
[ "100\n353 298 906 824 501 802 65 72 733 579 837 182 328 650 241 983 680 700 733 539 704 146 170 952 773 227 155 538 83 83 78 442 129 188 327 35 873 388 548 184 652 4 7 536 356 769 579 771 616 549 811 183 182 46 514 282 904 759 385 463 971 770 273 817 402 655 378 969 957 798 583 270 282 636 400 349 201 435 414 839 7...
[ "4 18 46 72 78 104 116 146 170 182 182 184 188 270 282 282 288 298 328 356 378 388 400 402 414 442 498 514 524 536 538 548 616 636 650 652 680 700 704 770 778 796 798 800 802 824 904 906 942 952 958 24044 7 9 35 65 83 83 129 155 169 183 201 217 227 241 273 301 315 327 349 353 385 435 463 501 539 549 579 579 583 655...
CodeContests
Housing maker Yamada House has launched a new featured product, a land for sale in a green home town with a rich environment such as schools and hospitals. This lot is divided into multiple lots and you can buy as many as you like, but the shape of the land with the lots you buy must be rectangular (including squares)....
stdin
null
1,934
1
[ "5 4 6\n1 6\n2 4\n3 3\n4 4\n5 1\n6 2\n0 0 1 0 0\n0 0 0 2 0\n0 0 0 3 0\n0 4 5 0 6\n3 3 1\n1 9\n0 0 1\n0 0 0\n0 0 0\n4 4 4\n1 6\n2 2\n3 4\n4 4\n0 1 0 0\n0 0 0 2\n0 0 3 0\n0 4 0 0\n0 0 0\n" ]
[ "1 1 1 2 2\n1 1 1 2 2\n4 4 3 3 3\n4 4 5 6 6\n1 1 1\n1 1 1\n1 1 1\nNA\n" ]
[ "5 4 6\n1 6\n2 4\n3 3\n4 4\n5 1\n6 2\n0 0 1 0 0\n0 0 0 2 0\n0 0 0 3 0\n0 4 5 0 6\n3 3 1\n1 9\n0 0 1\n0 0 0\n0 0 0\n4 4 4\n1 6\n2 2\n3 4\n4 4\n0 1 1 0\n0 0 0 2\n0 0 3 0\n0 4 0 0\n0 0 0\n", "5 4 6\n1 6\n2 4\n3 3\n4 4\n5 1\n6 2\n0 0 1 0 1\n0 0 0 2 0\n0 0 0 3 0\n0 4 5 0 6\n3 3 1\n1 9\n0 0 1\n0 0 0\n0 0 0\n4 4 4\n1 6\...
[ "1 1 1 2 2\n1 1 1 2 2\n4 4 3 3 3\n4 4 5 6 6\n1 1 1\n1 1 1\n1 1 1\nNA\n", "NA\n1 1 1\n1 1 1\n1 1 1\nNA\n", "NA\n", "NA\nNA\n", "NA\nNA\nNA\n", "NA\n1 1 1\n1 1 1\n1 1 1\nNA\n", "1 1 1 2 2\n1 1 1 2 2\n4 4 3 3 3\n4 4 5 6 6\n1 1 1\n1 1 1\n1 1 1\nNA\n", "NA\n1 1 1\n1 1 1\n1 1 1\nNA\n", "NA\n1 1 1\n1 1 1\n...