Unnamed: 0 int64 0 269 | challenge_id int64 104 5.95k | challenge_slug stringlengths 4 38 | challenge_name stringlengths 5 57 | challenge_body stringlengths 9 4.55k ⌀ | challenge_kind stringclasses 2
values | challenge_preview stringlengths 9 300 ⌀ | challenge_category stringclasses 2
values | challenge_created_at stringdate 2013-01-04 20:28:56 2015-01-19 21:40:20 | challenge_updated_at stringdate 2016-09-01 16:22:55 2022-09-02 10:36:47 | python3_template stringlengths 2 303 ⌀ | python3_template_head stringclasses 2
values | python3_template_tail stringclasses 52
values | problem_statement stringlengths 9 4.55k | difficulty float64 0.4 0.6 | allowed_languages stringclasses 28
values | input_format stringlengths 1 987 ⌀ | output_format stringlengths 1 1.92k ⌀ | sample_input stringlengths 1 284 ⌀ | sample_output stringclasses 52
values | difficulty_tag stringclasses 1
value | editorial_title stringclasses 32
values | editorial_content stringclasses 32
values | editorial_draft float64 0 0 ⌀ | editorial_slug stringclasses 32
values | editorial_published_at stringdate 2013-03-04 16:26:12 2014-04-24 18:24:07 ⌀ | editorial_statistics stringclasses 45
values | editorial_created_at stringdate 2013-03-04 16:26:12 2015-01-19 21:44:31 | editorial_updated_at stringdate 2016-05-12 23:56:02 2020-09-08 16:59:12 | editorial_solution_kind stringclasses 2
values | editorial_solution_code stringlengths 2 13k | editorial_solution_language stringclasses 1
value | editorial_solution_created_at stringdate 2016-04-24 02:02:11 2016-04-24 02:03:27 | editorial_solution_updated_at stringdate 2016-04-24 02:02:11 2020-09-08 16:59:12 | language stringclasses 7
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
200 | 4,360 | jugs-1 | Jugs 1 | In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This problem generalizes that puzzle.
You have two jugs, A and B, and an infinite supply of water. T... | code | In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This problem generalizes that puzzle. | ai | 2014-09-19T17:16:21 | 2016-09-09T09:53:02 | null | null | null | In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This problem generalizes that puzzle.
You have two jugs, A and B, and an infinite supply of water. T... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-09-19T17:16:36 | 2016-05-12T23:56:27 | setter | #include <stdio.h>
#include <stdlib.h>
#define min(a,b) (((a)<(b)) ? (a) : (b) )
typedef struct queueItem
{
unsigned long element;
struct queueItem *next;
} queueItem;
typedef struct Queue
{
queueItem *first, *last;
} Queue;
void queueinit(Queue* q)
{
queueItem *dummy = (queueItem*)... | not-set | 2016-04-24T02:03:06 | 2016-04-24T02:03:06 | C++ |
201 | 4,375 | justtrial | JustTrial | Take a number. Print hello world. | code | null | ai | 2014-09-20T12:48:31 | 2016-09-09T09:53:06 | null | null | null | Take a number. Print hello world. | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-09-20T12:49:46 | 2016-05-12T23:56:26 | setter | hi | not-set | 2016-04-24T02:03:07 | 2016-04-24T02:03:07 | Unknown |
202 | 4,429 | sherlock-and-square | Sherlock and Square | Watson gives a square of side length 1 to Sherlock. Now, after each second, each square of side $L$ will break into four squares each of side $L/2$(as shown in the image below).
![img][123]
Now, Watson asks Sherlock: What will be the sum of length of solid lines after $N$ seconds?
As the number can be large print... | code | Help Sherlock in finding the total side lengths of squares. | ai | 2014-09-24T02:15:22 | 2022-09-02T09:55:08 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER n as parameter.
#
def solve(n):
# Write your code here
| #!/bin/python3
import math
import os
import random
import re
import sys
| if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
n = int(input().strip())
result = solve(n)
fptr.write(str(result) + '\n')
fptr.close()
| Watson gives a square of side length 1 to Sherlock. Now, after each second, each square of some arbitrary side $L$ will break into four squares each of side $L/2$(as shown in the image below).
![img][123]
Now, Watson asks Sherlock: What will be the sum of length of solid lines after $N$ seconds?
As the number can... | 0.55814 | ["c","clojure","cpp","cpp14","cpp20","csharp","erlang","go","haskell","java","java8","java15","javascript","julia","kotlin","lua","objectivec","perl","php","pypy3","python3","ruby","rust","scala","swift","typescript","r"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-09-24T02:15:28 | 2016-12-06T15:12:39 | setter | ###Python 2
```python
MOD=10**9+7
def mpow(a,n):
if n==0: return 1
elif n==1: return a
p=mpow(a,n/2)
if (n&1):
return (p*p*a)%MOD
else: return (p*p)%MOD
t=input()
while t:
n=input()
print (4+2*(mpow(2,n)-1))%MOD
t-=1
```
| not-set | 2016-04-24T02:03:07 | 2016-07-23T18:57:34 | Python |
203 | 3,082 | strange-numbers | Strange numbers | Let $length(A)$ denote the count of digits of a number $A$ in its decimal representation.
John is looking for new methods of determining which numbers are strange all day long.
All non-negative numbers of length 1 are strange. Further, a number $X$ with $length(X) \ge1$ can also be considered strange if and only if... | code | How many strange numbers belong to interval [L, R]? | ai | 2014-06-18T20:01:55 | 2022-09-02T09:54:34 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. LONG_INTEGER l
# 2. LONG_INTEGER r
#
def solve(l, r):
# Write your code here
| #!/bin/python3
import math
import os
import random
import re
import sys
| if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
first_multiple_input = input().rstrip().split()
l = int(first_multiple_input[0])
r = int(first_multiple_input[1])
result = solve(l, r)
fptr.wri... | Let $length(A)$ denote the count of digits of a number $A$ in its decimal representation.
John is looking for new methods of determining which numbers are strange all day long.
All non-negative numbers of length 1 are strange. Further, a number $X$ with $length(X) \ge1$ can also be considered strange if and only if... | 0.492063 | ["c","clojure","cpp","cpp14","cpp20","csharp","erlang","go","haskell","java","java8","java15","javascript","julia","kotlin","lua","objectivec","perl","php","pypy3","python3","ruby","rust","scala","swift","typescript","r"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-09-25T07:39:33 | 2016-12-01T23:56:26 | setter | ###C++
```cpp
#include <iostream>
#include <vector>
using namespace std;
int t;
long long l,r;
vector<long long> V;
const unsigned long long MAX=1e+18;
int length(long long X)
{
int sol=1;
while (X>9){
++sol;
X/=10;
}
return sol;
}
void precalc()
{
V.clear();
for(int i=0;... | not-set | 2016-04-24T02:03:07 | 2016-07-23T17:56:58 | C++ |
204 | 2,692 | euler066 | Project Euler #66: Diophantine equation |
<p>
Consider quadratic Diophantine equations of the form:
</p>
<p style="text-align:center;">
<i>
x
</i>
<sup>
2
</sup>
– D
<i>
y
</i>
<sup>
2
</sup>
= 1
</p>
<p>
For example, when D=13, the minimal solution in
<i>
x
</i>
is 649
<sup>
2
</sup>
– 13×180
<sup>
2
</sup>
= 1.
</p>
<p>
I... | code | null | ai | 2014-06-16T12:28:31 | 2022-09-02T10:36:42 | null | null | null | <sub>This problem is a programming version of [Problem 66](https://projecteuler.net/problem=66) from [projecteuler.net](https://projecteuler.net/)</sub>
Consider quadratic Diophantine equations of the form:
$$x^2 - Dy^2 = 1$$
For example, when $D=13$, the minimal solution in $x$ is $649^2 - 13×180^2 = 1$. It can b... | 0.5 | ["ada","bash","c","clojure","coffeescript","cpp","cpp14","csharp","d","elixir","erlang","fortran","fsharp","go","groovy","haskell","java","java8","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","octave","pascal","perl","php","pypy3","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swi... | Input contains an integer $N$.
**Constraints**
$7 \le N \le 10^4$ | Print the answer corresponding to the test case. | ```raw
7
``` | ```raw
5
``` | Hard | null | null | null | null | null | null | 2014-09-25T16:12:17 | 2016-05-12T23:56:18 | tester | ```python
import math
def gen(n):
n2 = int(math.sqrt(n))
num = 1
den = n2
yield n2
while True:
x = num
num = den
den = (n - den * den) / x
p = int(n2 + 0.5 + num) / den
yield p
num = p * den - num
num, den = den, num
def solve_x(d):
h0,... | not-set | 2016-04-24T02:03:08 | 2016-04-24T02:03:08 | Python |
205 | 4,503 | fibonacci-gcd | Fibonacci GCD | Fibonacci numbers have the following form:
$$Fib_1 = 1 \\\
Fib_2 = 1 \\\
Fib_3 = 2 \\\
\vdots \\\
Fib_n = Fib_{n-2}+Fib_{n-1}$$
We have an array which contains $N$ elements.
We want to find $gcd(Fib_{a_1},Fib_{a_2},Fib_{a_3}, \cdots ,Fib_{a_n} )$
**Input Format**
First line contains $N$, where $N$ denotes ... | code | Find gcd for n fibonacci numbers. | ai | 2014-09-29T13:09:27 | 2022-09-02T09:54:42 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts LONG_INTEGER a as parameter.
#
def solve(a):
# Write your code here
| #!/bin/python3
import math
import os
import random
import re
import sys
| if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
for n_itr in range(n):
a = int(input().strip())
result = solve(a)
fptr.write(str(result) + '\n')
fptr.close()
| Fibonacci numbers have the following form:
$$F_1 = 1 \\\
F_2 = 1 \\\
F_3 = 2 \\\
\vdots \\\
F_n = F_{n-2}+F_{n-1}$$
We have an array $a_1, a_2, \ldots, a_N$ which contains $N$ elements.
We want to find $\gcd(F_{a_1},F_{a_2},F_{a_3}, \cdots ,F_{a_N} )$.
**Input Format**
The first line contains $N$, where $... | 0.5 | ["c","clojure","cpp","cpp14","cpp20","csharp","erlang","go","haskell","java","java8","java15","javascript","julia","kotlin","lua","objectivec","perl","php","pypy3","python3","ruby","rust","scala","swift","typescript","r"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-09-29T13:37:55 | 2016-12-04T15:20:14 | tester | ###Python 2
```python
from fractions import gcd
mod = 10**9+7
class _:
def __init__(a, x=0, y=0): a.x, a.y = x, y
__add__ = lambda a, b: _((a.x+b.x)%mod, (a.y+b.y)%mod)
__mul__ = lambda a, b: _((a.x*b.x+5*a.y*b.y)%mod, (a.x*b.y+a.y*b.x)%mod)
__pow__ = lambda a, b: a if b == 1 else a*a**(b-1) if b&1 ... | not-set | 2016-04-24T02:03:08 | 2016-07-23T18:13:25 | Python |
206 | 4,516 | huskar-tuskar-and-balls | Huskar, Tuskar, and Balls | Huskar and Tuskar are playing a game with balls. There is a tree with $N$ nodes numbered from $1$ to $N$ respectively (Root is $1$). There is a ball on each node. If a node has only one child, the ball on this node will drop onto child node. But if a node has more than one child, Huskar and Tuskar can't decide the way ... | code | There is a tree with N nodes. Each node has a ball in it. Two kids are playing a game. Eeach kid has a node. They delete some edges. After deleting, balls drop down in that tree. If a ball drops into a kid's nodes, they get points. We are trying to maximize the points that they have. | ai | 2014-09-30T18:47:23 | 2019-07-02T13:58:53 | null | null | null | Huskar and Tuskar are playing a game with balls. There is a tree with $N$ nodes numbered from $1$ to $N$ respectively (root is $1$). There is a ball on each node. If a node has only one child, the ball on this node will drop onto the child node. But if a node has more than one child, Huskar and Tuskar can't decide the ... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | Line 1 : Two integers : $N$ and $Q$, the number of the nodes in the tree and the number of queries.
Lines $2...N$ : line $i$, one integer : the parent of node $i$.
Lines $N+1...N+Q$ : line $(N+i)$ , two integers : Huskar's node and Tuskar's node.
**Constraints**
$2 \le N \le 2 \times 10^5$
$1 \le Q \le 2 \t... | You must print $Q$ lines. In each line, two integers for each query : Huskar's points and Tuskar's points. | 6 1
4
1
1
3
3
3 6 | 2 1 | Hard | null | null | null | null | null | null | 2014-10-02T05:25:02 | 2016-12-04T09:00:09 | setter | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 500010;
const int LogN = 21;
int dad[MAXN][LogN];
int N,Q;
stack<int> st;
vector<int> v[MAXN];
int wh[MAXN];
int depth[MAXN];
void iterative( int k ){
st.push(k);
while ( !st.empty() ){
k = st.top();
st.pop();
... | not-set | 2016-04-24T02:03:09 | 2016-04-24T02:03:09 | C++ |
207 | 4,516 | huskar-tuskar-and-balls | Huskar, Tuskar, and Balls | Huskar and Tuskar are playing a game with balls. There is a tree with $N$ nodes numbered from $1$ to $N$ respectively (Root is $1$). There is a ball on each node. If a node has only one child, the ball on this node will drop onto child node. But if a node has more than one child, Huskar and Tuskar can't decide the way ... | code | There is a tree with N nodes. Each node has a ball in it. Two kids are playing a game. Eeach kid has a node. They delete some edges. After deleting, balls drop down in that tree. If a ball drops into a kid's nodes, they get points. We are trying to maximize the points that they have. | ai | 2014-09-30T18:47:23 | 2019-07-02T13:58:53 | null | null | null | Huskar and Tuskar are playing a game with balls. There is a tree with $N$ nodes numbered from $1$ to $N$ respectively (root is $1$). There is a ball on each node. If a node has only one child, the ball on this node will drop onto the child node. But if a node has more than one child, Huskar and Tuskar can't decide the ... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | Line 1 : Two integers : $N$ and $Q$, the number of the nodes in the tree and the number of queries.
Lines $2...N$ : line $i$, one integer : the parent of node $i$.
Lines $N+1...N+Q$ : line $(N+i)$ , two integers : Huskar's node and Tuskar's node.
**Constraints**
$2 \le N \le 2 \times 10^5$
$1 \le Q \le 2 \t... | You must print $Q$ lines. In each line, two integers for each query : Huskar's points and Tuskar's points. | 6 1
4
1
1
3
3
3 6 | 2 1 | Hard | null | null | null | null | null | null | 2014-10-02T05:25:02 | 2016-12-04T09:00:09 | tester | program sparseTableSolution; // Complexity - O(N log N + Q)
uses math;
const MAXN = 500000;
type tEdge = record
v, next: longInt;
end;
var first, depth, dfs_id, dfs_order, max2pow, stack, parent: array[ 1..2 * MAXN ] of longInt;
e: array[ 1..MAX... | not-set | 2016-04-24T02:03:09 | 2016-04-24T02:03:09 | JavaScript |
208 | 4,529 | white-falcon-and-tree | White Falcon And Tree | White falcon has a tree with $N$ nodes. Each node contains a linear function. And $f_u(x)$ is function of a node $u$.
Let us denote the path from node $u$ to node $v$ like this : $"p_1,p_2,p_3,...,p_k"$ where $p_1 = u$ and $p_k = v$.
White falcon also has $Q$ queries. They are in the following format :
1. "$1$ ... | code | Given a tree with N nodes and two queries, maintain the tree under these two queries. | ai | 2014-10-02T18:29:55 | 2022-08-31T08:33:17 | null | null | null | White Falcon has a tree with $N$ nodes. Each node contains a linear function. Let's denote by $f_u(x)$ the linear function contained in the node $u$.
Let's denote the path from node $u$ to node $v$ like this: $p_1,p_2,p_3,\ldots,p_k$, where $p_1 = u$ and $p_k = v$, and $p_i$ and $p_{i+1}$ are connected.
White Fal... | 0.5 | ["ada","bash","c","clojure","coffeescript","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fortran","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","octave","pascal","perl","php","pypy3","python3","r","racket","ruby","rust","sbcl","scala"... | The first line contains $N$, the number of nodes. The following $N$ lines each contain two integers $a$ and $b$ that describe the function $ax + b$.
Following $N - 1$ lines contain edges of the tree.
The next line contains $Q$, the number of queries. Each subsequent line contains one of the queries described above... | For every query of the second kind, print one line containing an integer, the answer for that query.
**Constraints**
$1 \leq N \leq 50000$ (Number of nodes)
$1 \leq Q \leq 50000$ (Number of queries)
$0 \leq a, b, x < 10^9 + 7$
| 2
1 1
1 2
1 2
2
1 2 2 1 1
2 1 2 1 | 3 | Hard | null | null | null | null | null | null | 2014-10-02T18:34:19 | 2016-05-12T23:56:08 | setter | #include <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cassert>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <string>
#include <cmath>
#include <ctime>
#include <queue>
#include <list>
#inc... | not-set | 2016-04-24T02:03:09 | 2016-04-24T02:03:09 | C++ |
209 | 4,529 | white-falcon-and-tree | White Falcon And Tree | White falcon has a tree with $N$ nodes. Each node contains a linear function. And $f_u(x)$ is function of a node $u$.
Let us denote the path from node $u$ to node $v$ like this : $"p_1,p_2,p_3,...,p_k"$ where $p_1 = u$ and $p_k = v$.
White falcon also has $Q$ queries. They are in the following format :
1. "$1$ ... | code | Given a tree with N nodes and two queries, maintain the tree under these two queries. | ai | 2014-10-02T18:29:55 | 2022-08-31T08:33:17 | null | null | null | White Falcon has a tree with $N$ nodes. Each node contains a linear function. Let's denote by $f_u(x)$ the linear function contained in the node $u$.
Let's denote the path from node $u$ to node $v$ like this: $p_1,p_2,p_3,\ldots,p_k$, where $p_1 = u$ and $p_k = v$, and $p_i$ and $p_{i+1}$ are connected.
White Fal... | 0.5 | ["ada","bash","c","clojure","coffeescript","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fortran","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","octave","pascal","perl","php","pypy3","python3","r","racket","ruby","rust","sbcl","scala"... | The first line contains $N$, the number of nodes. The following $N$ lines each contain two integers $a$ and $b$ that describe the function $ax + b$.
Following $N - 1$ lines contain edges of the tree.
The next line contains $Q$, the number of queries. Each subsequent line contains one of the queries described above... | For every query of the second kind, print one line containing an integer, the answer for that query.
**Constraints**
$1 \leq N \leq 50000$ (Number of nodes)
$1 \leq Q \leq 50000$ (Number of queries)
$0 \leq a, b, x < 10^9 + 7$
| 2
1 1
1 2
1 2
2
1 2 2 1 1
2 1 2 1 | 3 | Hard | null | null | null | null | null | null | 2014-10-02T18:34:19 | 2016-05-12T23:56:08 | tester | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#define fo(i,a,b) dfo(int,i,a,b)
#define fr(i,n) dfr(int,i,n)
#define fe(i,a,b) dfe(int,i,a,b)
#define fq(i,n) dfq(int,i,n)
#define nfo(i,a,b) dfo(,i,a,b)
#define nfr(i,n) dfr(,i,n)... | not-set | 2016-04-24T02:03:09 | 2016-04-24T02:03:09 | C++ |
210 | 4,545 | assassins-steps | Assassin's Steps | Training to be an assassin is not easy, especially when training under someone as accomplished as Master <a href="https://www.facebook.com/manavcool.sethi">Al-Manav</a>. An assassin must learn to how to take the correct steps while walking stealthily in order to become a master assassin. Therefore, a particular trainin... | code | null | ai | 2014-10-05T09:09:55 | 2016-09-09T09:54:14 | null | null | null | Training to be an assassin is not easy, especially when training under someone as accomplished as Master <a href="https://www.facebook.com/manavcool.sethi">Al-Manav</a>. An assassin must learn to how to take the correct steps while walking stealthily in order to become a master assassin. Therefore, a particular trainin... | 0.5 | ["bash","c","cpp","java","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-10-05T09:11:21 | 2018-08-11T06:11:38 | setter | #include <cstdio>
using namespace std;
int main ()
{
int t,A,B,i;
double p[100002],product,expected,min;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&A,&B);
for (int j=0;j<A;j++)
{
scanf("%lf",&p[j]);
}
... | not-set | 2016-04-24T02:03:09 | 2016-04-24T02:03:09 | C++ |
211 | 4,545 | assassins-steps | Assassin's Steps | Training to be an assassin is not easy, especially when training under someone as accomplished as Master <a href="https://www.facebook.com/manavcool.sethi">Al-Manav</a>. An assassin must learn to how to take the correct steps while walking stealthily in order to become a master assassin. Therefore, a particular trainin... | code | null | ai | 2014-10-05T09:09:55 | 2016-09-09T09:54:14 | null | null | null | Training to be an assassin is not easy, especially when training under someone as accomplished as Master <a href="https://www.facebook.com/manavcool.sethi">Al-Manav</a>. An assassin must learn to how to take the correct steps while walking stealthily in order to become a master assassin. Therefore, a particular trainin... | 0.5 | ["bash","c","cpp","java","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-10-05T09:11:21 | 2018-08-11T06:11:38 | tester | import java.util.Scanner;
public class AssassinSteps {
public static double calculateMinSteps(int A, int B, double prob[]) {
double sol = Double.MAX_VALUE;
double p = 1;
for (int c = 1; c<=A; c++) {
p *= prob[c-1];
int D = A-c;
... | not-set | 2016-04-24T02:03:09 | 2016-04-24T02:03:09 | Python |
212 | 4,546 | street-walk | Street Walk | Ram needs to cross the jungle, But in the jungle many paths are dangerous and cannot be taken. Consider the jungle as a n*n grid where, where grid positions are marked as '.' if it is safe else 'x'.Ram starts at the origin of the grid i.e. 0,0 and wants to reach the end of the grid i.e. n-1,n-1.He can only move down or... | code | null | ai | 2014-10-05T09:42:29 | 2016-09-09T09:54:14 | null | null | null | Ram needs to cross the jungle, But in the jungle many paths are dangerous and cannot be taken. Consider the jungle as a n*n grid where, where grid positions are marked as '.' if it is safe else 'x'.Ram starts at the origin of the grid i.e. 0,0 and wants to reach the end of the grid i.e. n-1,n-1.He can only move down or... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-10-05T10:28:53 | 2017-01-05T15:58:24 | setter |
#include<iostream>
using namespace std;
int mod=1000000007;
int main()
{
static int t,i,j,way[1001][1001],n;
char c[1001][1001];
cin>>t;
while (t--)
{
cin>>n;
for (i=0;i<n;i++)
{
cin>>c[i];
}
... | not-set | 2016-04-24T02:03:09 | 2016-04-24T02:03:09 | C++ |
213 | 4,571 | the-dragon-warrior | The Dragon Warrior |
Po has one last task to achieve ultimate glory and be termed The Dragon Warrior of Kung Fu. Po has Tigress, Crane, Mantis, Viper and Monkey to help him with this. Po needs to gain atleast Q calories of energy by the end of this task to defeat Tai Lung. Help us find out if he does !
There are K items hidden in the cel... | code | null | ai | 2014-10-07T09:27:20 | 2016-09-09T09:54:23 | null | null | null |
Po has one last task to achieve ultimate glory and be termed The Dragon Warrior of Kung Fu. Po has Tigress, Crane, Mantis, Viper and Monkey to help him with this. Po needs to gain atleast Q calories of energy by the end of this task to defeat Tai Lung. Help us find out if he does !
There are K items hidden in the cel... | 0.5 | ["bash","c","cpp","java","python","python3","java8","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-10-07T09:30:41 | 2016-05-12T23:56:02 | setter | #include<stdio.h>
#include<iostream>
#include<algorithm>
#include <cstring>
#include <vector>
using namespace std;
int k, a, z, q;
int dp[51][51][51];
vector <int> x;
vector <int> y;
int rec(int p, int r, int s)
{
int &res = dp[p][r][s];
if (res == -1)... | not-set | 2016-04-24T02:03:10 | 2016-04-24T02:03:10 | C++ |
214 | 4,582 | devu-and-sub-sequence | Devu and Subsequence | Devu is newbie to the computer programming, So he wants your help in solving a problem. Problem can be described as below:<br>
Given two lists $A$ and $B$ having same length, Find the largest subsequence of list $A$, whose sum is greater than or equal to corresponding subsequence of list $B$. Corresonding subsequence ... | code | Help Devu find the largest subsequence. | ai | 2014-10-07T17:06:44 | 2019-07-02T13:58:55 | null | null | null | Devu is a newbie to computer programming, so he wants your help in solving a problem. The problem can be described as below:<br>
Given two lists $A$ and $B$ having the same length, find the length of longest subsequence of list $A$, whose sum is greater than or equal to the corresponding subsequence of list $B$. Corre... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | The first line contains an integer $N$, i.e. the length of the lists.<br>
The second line contains $N$ integers corresponding to list $A$.<br>
The second line contains $N$ integers corresponding to list $B$.
**Constraints**
$1 \le N \le 10^5$<br>
$0 \le A[i] \le 10^7$<br>
$0 \le B[i] \le 10^7$<br> | Print the answer in a single line. | 3
100 100 5
2 2 1000 | 2 | Hard | null | null | null | null | null | null | 2014-10-07T17:06:54 | 2016-12-27T13:38:00 | setter | #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int N;
cin>>N;
int C[N];
for(int i = 0 ; i< N ; i++)
cin>>C[i];
for(int i = 0 ; i< N ; i++)
{
... | not-set | 2016-04-24T02:03:10 | 2016-04-24T02:03:10 | C++ |
215 | 4,585 | devu-and-lucky-numbers | Devu and Lucky Numbers | Devu believes in God, So he thinks that few numbers are lucky and while others are unlucky. Devu considers a number as lucky iff $4$,$5$ and $6$ are the only digits occuring in the number.To calculate his luck factor for today, he wants to add all the lucky numbers. So, your task is pretty simple.
Given three numbers... | code | Help Devu in adding lucky numbers. | ai | 2014-10-07T19:39:07 | 2016-09-09T09:54:28 | null | null | null | You are given three integers $x$, $y$ and $z$. You have to find the sum of all numbers whose digits are made of only $4$, $5$ and $6$, that have at most $x$ fours in decimal representation, at most $y$ fives in decimal representation and at most $z$ sixes in decimal representation. As summation can be very large, print... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | Hard | null | null | null | null | null | null | 2014-10-07T19:39:54 | 2016-12-19T22:04:42 | setter | #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7 ;
int x , y , z ;
int dp[101][101][101] ,cnt[101][101][101];
int solve1(int x,int y,int z){
if(x <= 0 ... | not-set | 2016-04-24T02:03:10 | 2016-04-24T02:03:10 | C++ | ||||
216 | 4,595 | furys-network | Fury's Network | **S.H.I.E.L.D** is an espionage and law-enforcement agency headed by Colonel Nick Fury. Over the years, HYDRA secretly infiltrated **S.H.I.E.L.D** and used the agency to their advantage in many ways. They recruited a large sum of all the agents and silently killed off anyone who got in their way. Soon, Nick Fury found ... | code | A problem for Inscription 2014 organised by NITK. | ai | 2014-10-08T13:14:00 | 2016-09-09T09:54:31 | null | null | null | **S.H.I.E.L.D** is an espionage and law-enforcement agency headed by Colonel Nick Fury. Over the years, HYDRA secretly infiltrated **S.H.I.E.L.D** and used the agency to their advantage in many ways. They recruited a large sum of all the agents and silently killed off anyone who got in their way. Soon, Nick Fury found ... | 0.5 | ["bash","c","cpp","java","csharp","python","python3","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-10-08T13:16:40 | 2017-05-23T11:09:29 | setter | #include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define MAX 100001
#define DMAX 262145
using namespace std;
struct node
{
int sum,u;
long long sqsum;
long long cubsum;
bool ch,rep;
}seg[DMAX];
struct rx
{
in... | not-set | 2016-04-24T02:03:10 | 2016-04-24T02:03:10 | C++ |
217 | 4,715 | totient-until-the-end | Totient Until The End | Saito promises to stay by Louise's side until the end. Louise wants to test the strength of Saito's promise by having him calculate the *totient* until the end.
The *totient of $N$*, written as $\phi(N)$, is the number of integers $K$ such that $1 \le K \le N$ and $\gcd(K,N) = 1$. It is clear that when the function $\... | code | Find the totient until the end. | ai | 2014-10-12T18:19:26 | 2019-07-02T13:58:55 | null | null | null | Saito promises to stay by Louise's side until the end. Louise wants to test the strength of Saito's promise by having him calculate the *totient* until the end.
The *totient of $N$*, written as $\phi(N)$, is the number of integers $K$ such that $1 \le K \le N$ and $\gcd(K,N) = 1$. It is clear that when the function $\... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | Hard | null | null | null | null | null | null | 2014-10-12T22:20:22 | 2017-01-02T18:12:24 | setter | #include <stdio.h>
#define N 2000000
#define alok(n,t) ((t*)malloc((n)*sizeof(t)))
#include <algorithm>
using namespace std;
int pf[N+1];
int ex[N+1];
int rm[N+1];
int *n = alok(1111, int);
int *m = alok(1111, int);
int pi[N+1];
int pis[11111];
int tk[N+1];
int p... | not-set | 2016-04-24T02:03:11 | 2016-04-24T02:03:11 | C++ | ||||
218 | 4,715 | totient-until-the-end | Totient Until The End | Saito promises to stay by Louise's side until the end. Louise wants to test the strength of Saito's promise by having him calculate the *totient* until the end.
The *totient of $N$*, written as $\phi(N)$, is the number of integers $K$ such that $1 \le K \le N$ and $\gcd(K,N) = 1$. It is clear that when the function $\... | code | Find the totient until the end. | ai | 2014-10-12T18:19:26 | 2019-07-02T13:58:55 | null | null | null | Saito promises to stay by Louise's side until the end. Louise wants to test the strength of Saito's promise by having him calculate the *totient* until the end.
The *totient of $N$*, written as $\phi(N)$, is the number of integers $K$ such that $1 \le K \le N$ and $\gcd(K,N) = 1$. It is clear that when the function $\... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | Hard | null | null | null | null | null | null | 2014-10-12T22:20:22 | 2017-01-02T18:12:24 | tester | #include <unordered_map>
using namespace std;
unordered_map<int,int> d,updList;
unordered_map<int,int>::iterator it;
int p[2000001];
int toAdd[200],toDelete[200];
inline void addToDict(int key,int value)
{
value+=updList[key];
if(!value)updList.erase(key);
else... | not-set | 2016-04-24T02:03:11 | 2016-04-24T02:03:11 | C++ | ||||
219 | 4,732 | pairwise-sum-and-divide | Pairwise Sum and Divide | You are given an array of numbers. Let us denote the array with $A[]$. Your task is very simple. You need to find the value returned by the function $\text{fun}(A)$.
fun(A)
sum = 0
for i = 1 to A.length
for j = i+1 to A.length
sum = sum + Floor((A[i]+A[j])/(A[i]*A[j]))
... | code | Find the sum of ( a_i + a_j ) / (a_i * a_j) | ai | 2014-10-13T21:22:42 | 2022-09-02T09:55:05 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY a as parameter.
#
def solve(a):
# Write your code here
| #!/bin/python3
import math
import os
import random
import re
import sys
| if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
a_count = int(input().strip())
a = list(map(int, input().rstrip().split()))
result = solve(a)
fptr.write(str(result) + '\n')
fptr.close()
| You are given an array of numbers. Let us denote the array with $A[]$. Your task is very simple. You need to find the value returned by the function $\text{fun}(A)$.
fun(A)
sum = 0
for i = 1 to A.length
for j = i+1 to A.length
sum = sum + Floor((A[i]+A[j])/(A[i]*A[j]))
... | 0.541985 | ["c","clojure","cpp","cpp14","cpp20","csharp","erlang","go","haskell","java","java8","java15","javascript","julia","kotlin","lua","objectivec","perl","php","pypy3","python3","ruby","rust","scala","swift","typescript","r"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-10-13T21:23:13 | 2016-12-13T17:10:36 | setter | ###C++
```cpp
#include<stdio.h>
#include<assert.h>
#include<algorithm>
using namespace std;
typedef long long int ll;
ll A[210004];
void solve()
{
ll n;
scanf("%lld",&n);
assert(n>=1 && n<=200000);
ll ones=0,twos=0,ans=0;
for(int i=1;i<=n;i++){
scanf("%lld",&A[i]);
assert(A[i]>=1... | not-set | 2016-04-24T02:03:11 | 2016-07-23T18:56:06 | C++ |
220 | 4,736 | line-segments | Line Segments | Adigha is in trouble with line segments. He can not do his homework and needs someones
help. Can you help him?
You are given $N$ line segments. All of them lie on the same line. We will describe $i$-*th* line segment with two integers, $A$<sub>$i$</sub> and $B$<sub>$i$</sub>. This means it starts at $A$<sub>$i$</sub> ... | code | We have N line segments in a plane and all of them are parallel to each other. We will pick a subset with K elements from these line segments. There must be no coincident pairs in that subset.
We are trying to maximize K. | ai | 2014-10-14T09:44:05 | 2019-07-02T13:58:56 | null | null | null | You are given $N$ line segments. All of them lie on the same line. We will describe the $i^{th}$ line segment with two integers, $A_i$ and $B_i$. This means it starts at $A_i$ and ends at $B_i$. It will be denoted as $(A_i;B_i)$.
Let's say a pair of line segments is ***good***, if one of them is not covering the oth... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | Hard | null | null | null | null | null | null | 2014-10-14T10:25:27 | 2016-05-12T23:58:26 | setter | #include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
const int MAXN = 100010;
int seg[5*MAXN];
ii LineS[MAXN];
ii subseq[MAXN];
int N;
int comparator( ii a , ii b ){
if ( a.first != b.first ) return a.first < b.first;
return a.second > b.second;
}
int update( int k , int b , in... | not-set | 2016-04-24T02:03:11 | 2016-04-24T02:03:11 | C++ | ||||
221 | 4,736 | line-segments | Line Segments | Adigha is in trouble with line segments. He can not do his homework and needs someones
help. Can you help him?
You are given $N$ line segments. All of them lie on the same line. We will describe $i$-*th* line segment with two integers, $A$<sub>$i$</sub> and $B$<sub>$i$</sub>. This means it starts at $A$<sub>$i$</sub> ... | code | We have N line segments in a plane and all of them are parallel to each other. We will pick a subset with K elements from these line segments. There must be no coincident pairs in that subset.
We are trying to maximize K. | ai | 2014-10-14T09:44:05 | 2019-07-02T13:58:56 | null | null | null | You are given $N$ line segments. All of them lie on the same line. We will describe the $i^{th}$ line segment with two integers, $A_i$ and $B_i$. This means it starts at $A_i$ and ends at $B_i$. It will be denoted as $(A_i;B_i)$.
Let's say a pair of line segments is ***good***, if one of them is not covering the oth... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | Hard | null | null | null | null | null | null | 2014-10-14T10:25:27 | 2016-05-12T23:58:26 | tester | program lineSegments;
type tSegment = record
l, r: longInt;
end;
var a: array[ 1..100000 ] of tSegment;
function less( const a, b: tSegment ): boolean;
begin
if ( a.l <> b.l ) then
exit( a.l < b.l );
exit( a.r > b.r ... | not-set | 2016-04-24T02:03:11 | 2016-04-24T02:03:11 | JavaScript | ||||
222 | 4,879 | chief-hopper | Chief Hopper | Chief's bot is playing an old DOS-based game. There are $N+1$ buildings in the game - indexed from $0$ to $N$ and are placed left-to-right. It is guaranteed that building with index $0$ will be of height $0$ unit. For buildings with index $i$ ($i \in [1, N]$) height will be $h_i$ units.
<br>
At beginning Chief's bot... | code | Find the
minimum units of energy with which bot should start to
successfully complete the game. | ai | 2014-10-22T02:37:45 | 2022-08-31T08:14:38 | #
# Complete the 'chiefHopper' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY arr as parameter.
#
def chiefHopper(arr):
# Write your code here
| #!/bin/python3
import math
import os
import random
import re
import sys
| if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
result = chiefHopper(arr)
fptr.write(str(result) + '\n')
fptr.close()
| Chief's bot is playing an old DOS based game. There is a row of buildings of different heights arranged at each index along a number line. The bot starts at building $0$ and at a height of $0$. You must determine the minimum energy his bot needs at the start so that he can jump to the top of each building without hi... | 0.588235 | ["ada","bash","c","clojure","coffeescript","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fortran","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","octave","pascal","perl","php","pypy3","python3","r","racket","ruby","rust","sbcl","scala"... | The first line contains an integer $n$, the number of buildings.
The next line contains $n$ space-separated integers $arr[1]..arr[n]$, the heights of the buildings. | 5
3 4 3 2 4
**sample Output**
4
**Sample Input**
3
4 4 4
| 4
| Hard | null | null | null | null | null | null | 2014-10-22T02:37:52 | 2018-05-07T19:45:45 | setter | ###C++
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
vector <long long int> Arr(n);
for (int i=0;i<n;i++) {
cin>>Arr[i];
}
long long int beg = Arr[n-1]/2 + Arr[n-1]%2;
for (int i = n-2;i>=0;i--) {
beg = (Arr[i] + beg)/2 + (Arr[i] + beg... | not-set | 2016-04-24T02:03:13 | 2016-07-23T14:27:28 | C++ | |
223 | 4,879 | chief-hopper | Chief Hopper | Chief's bot is playing an old DOS-based game. There are $N+1$ buildings in the game - indexed from $0$ to $N$ and are placed left-to-right. It is guaranteed that building with index $0$ will be of height $0$ unit. For buildings with index $i$ ($i \in [1, N]$) height will be $h_i$ units.
<br>
At beginning Chief's bot... | code | Find the
minimum units of energy with which bot should start to
successfully complete the game. | ai | 2014-10-22T02:37:45 | 2022-08-31T08:14:38 | #
# Complete the 'chiefHopper' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY arr as parameter.
#
def chiefHopper(arr):
# Write your code here
| #!/bin/python3
import math
import os
import random
import re
import sys
| if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
result = chiefHopper(arr)
fptr.write(str(result) + '\n')
fptr.close()
| Chief's bot is playing an old DOS based game. There is a row of buildings of different heights arranged at each index along a number line. The bot starts at building $0$ and at a height of $0$. You must determine the minimum energy his bot needs at the start so that he can jump to the top of each building without hi... | 0.588235 | ["ada","bash","c","clojure","coffeescript","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fortran","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","octave","pascal","perl","php","pypy3","python3","r","racket","ruby","rust","sbcl","scala"... | The first line contains an integer $n$, the number of buildings.
The next line contains $n$ space-separated integers $arr[1]..arr[n]$, the heights of the buildings. | 5
3 4 3 2 4
**sample Output**
4
**Sample Input**
3
4 4 4
| 4
| Hard | null | null | null | null | null | null | 2014-10-22T02:37:52 | 2018-05-07T19:45:45 | tester | ###C++
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long linf = 0x3f3f3f3f3f3f3f3fLL;
const int N = 111111;
int n;
int h[N];
int check(long long x) {
long long energy = x;
for(int i = 1; i <= n; i++) {
energy += energy - h[i];
if(energy >= linf) return 1;
if(ene... | not-set | 2016-04-24T02:03:13 | 2016-07-23T14:30:35 | C++ | |
224 | 4,912 | receive-the-signal | Receive The Signal | Lagnajeet is standing at the position 0 on a number line. Sunil is sending a list of commands through Wi-Fi to Lagnajeet's smartphone and Lagnajeet follows them.
Each command is one of the following two types:
Go 1 unit towards the positive direction, denoted as '+'
Go 1 unit towards the negative direction, denoted a... | code | null | ai | 2014-10-24T19:30:33 | 2016-09-09T09:57:04 | null | null | null | Lagnajeet is standing at the position 0 on a number line. Sunil is sending a list of commands through Wi-Fi to Lagnajeet's smartphone and Lagnajeet follows them.
Each command is one of the following two types:
Go 1 unit towards the positive direction, denoted as '+'
Go 1 unit towards the negative direction, denoted a... | 0.4 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-10-24T19:30:48 | 2016-05-12T23:58:14 | setter | http://ideone.com/MgyHDW | not-set | 2016-04-24T02:03:13 | 2016-04-24T02:03:13 | Unknown |
225 | 4,932 | burger-happiness | Burger Happiness | In Burger Town new burger restaurants will be opened! Concretely, $N$ restaurants will open in $N$ days, while restaurant $i$ will be opened on day $i$ and will be located at $X_i$. The town should be imagined as an one dimensional line in which every object's location can be described by the $x$ coordinate.
Tim has j... | code | Tim is currently hunting for happiness by eating burgers after a disappointing programming contest result. Help him maximizing his happiness, given some conditions. | ai | 2014-10-25T21:24:48 | 2022-09-02T10:00:36 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts 2D_INTEGER_ARRAY restaurants as parameter.
#
def solve(restaurants):
# Write your code here
| #!/bin/python3
import math
import os
import random
import re
import sys
| if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
restaurants = []
for _ in range(n):
restaurants.append(list(map(int, input().rstrip().split())))
result = solve(restaurants)
fptr.write(str(result) + '\n')
fptr.close()
| In Burger Town new burger restaurants will be opened! Concretely, $N$ restaurants will open in $N$ days, while restaurant $i$ will be opened on day $i$ and will be located at $X_i$. The town should be imagined as an one dimensional line in which every object's location can be described by the $x$ coordinate.
Tim has j... | 0.5 | ["c","clojure","cpp","cpp14","cpp20","csharp","erlang","go","haskell","java","java8","java15","javascript","julia","kotlin","lua","objectivec","perl","php","pypy3","python3","ruby","rust","scala","swift","typescript","r"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-10-25T21:27:45 | 2016-12-03T05:18:13 | setter | #include <cstdio>
#include <cstring>
#include <algorithm>
#include <cassert>
using namespace std;
typedef long long ll;
const int MAX_N = 1e5;
const ll INF = 1LL << 62;
const int MAX_A = 1e6;
const int MAX_X = 1e9;
const int MAX_B = 1e6;
int N;
int X[MAX_N], A[MAX_N]... | not-set | 2016-04-24T02:03:13 | 2016-04-24T02:03:13 | C++ |
226 | 4,972 | save-middle-earth-1 | Save Middle Earth | Frodo Baggins is on his mission to destroy The One Ring. He has entered the deadly Shelob's lair and is now challenged by the mighty spider Shelob. Both Frodo and Shelob get equal number of swords of varying lengths which are stacked behind them.
The challenge is this: Both of them pull out their topmost sword. The le... | code | null | ai | 2014-10-28T12:26:58 | 2016-09-09T09:57:30 | null | null | null | Frodo Baggins is on his mission to destroy The One Ring. He has entered the deadly Shelob's lair and is now challenged by the mighty spider Shelob. Both Frodo and Shelob get equal number of swords of varying lengths which are stacked behind them.
The challenge is this: Both of them pull out their topmost sword. The le... | 0.5 | ["bash","c","cpp","java","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-10-28T12:29:15 | 2016-05-12T23:58:10 | setter | //CSI OPC
//SIMPLE SEARCH
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
bool isprime(int n)
{
int c=0;
for(int i=2; i<=sqrt(n); i++)
{
if(n%i==0)
c++;
if(c>0)
break;
... | not-set | 2016-04-24T02:03:14 | 2016-04-24T02:03:14 | C++ |
227 | 5,012 | the-philosopher-box | The Philosopher Box | <p><em>n</em> philosophers were sitting at a table trying to find the key to open the
box that unleashes all the secrets of the world .</p>
<p>Each philosopher has a part of the key but none of them knows the whole full
key to open the box .</p>
<p>Each of the philosophers write down their keys on a piece of paper and... | code | Help the philosopher to unleash the truth | ai | 2014-10-31T11:22:35 | 2016-09-09T09:57:47 | null | null | null | <p><em>n</em> philosophers were sitting at a table trying to find the key to open the
box that unleashes all the secrets of the world .</p>
<p>Each philosopher has a part of the key but none of them knows the whole full
key to open the box .</p>
<p>Each of the philosophers write down their keys on a piece of paper and... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-10-31T11:25:48 | 2016-05-12T23:58:07 | setter | import sys
tt="qwertyuiopasdfghjklzxcvbnm?" #all accepted characters
tt=list(tt)
t=int(raw_input())
seta=set() #Set A contains intersection of all strings without '?'
setb=set() #Set B contains intersection of all strings with '?'
seta_i=False #Flag to check if there is atleast a single str... | not-set | 2016-04-24T02:03:14 | 2016-04-24T02:03:14 | Python |
228 | 5,040 | joey-and-divisibilty | Joey and Divisibilty | Joey is crazy about divisibility. He wants you to give the smallest natural number
which is divisible by **n** and is solely made of digits from **0-d**, where **1<=d<=9**
__Example__
if Joey tells you that n=8 and d=1, then your output should be 1000 as
there is no natural number smaller than 1000 which is made of ... | code | null | ai | 2014-11-01T15:50:15 | 2016-09-09T09:57:58 | null | null | null | Joey is crazy about divisibility. He wants you to give the smallest natural number
which is divisible by **n** and is solely made of digits from **0-d**, where **1<=d<=9**
__Example__
if Joey tells you that n=8 and d=1, then your output should be 1000 as
there is no natural number smaller than 1000 which is made of ... | 0.5 | ["bash","c","cpp","java","csharp","python","python3","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-11-01T17:57:46 | 2016-05-12T23:58:05 | setter |
//#define LOCAL //uncomment for testing from local file
#include <iostream>
#include <cstring>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <... | not-set | 2016-04-24T02:03:14 | 2016-04-24T02:03:14 | C++ |
229 | 5,072 | playing-board-games | Playing Board Games | Pingu recently got addicted to board games. Pingu was playing game called Box fitting. He has a $'4\times N'$ board and has lots of boxes of size $'1\times 4'$ and $'4 \times 1'$. He has a large number of boxes of both types(consider infinite for all practical purposes). Now in this game he needs to place the boxes in ... | code | null | ai | 2014-11-03T08:43:34 | 2016-09-09T09:58:09 | null | null | null | Pingu recently got addicted to board games. Pingu was playing game called Box fitting. He has a $'4\times N'$ board and has lots of boxes of size $'1\times 4'$ and $'4 \times 1'$. He has a large number of boxes of both types(consider infinite for all practical purposes). Now in this game he needs to place the boxes in ... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-11-03T09:51:53 | 2018-08-04T22:15:15 | setter | #include <bits/stdc++.h>
#define ll long long
#define matrix(x,n,m) vector<vector<ll> > x(n,vector<ll> (m,0))
using namespace std;
ll mod=1000000007;
void multiply(vector<vector<ll> > &a , vector<vector<ll> > b)
{
matrix(temp,4,4);
for(int i=0;i<4;i++)
for(in... | not-set | 2016-04-24T02:03:15 | 2016-04-24T02:03:15 | C++ |
230 | 5,100 | challange1 | Бодлого1 | #ШАТАР
Шатрын хөлөгний 2 буудал координатаараа өгөгдөв. (Буудлын координат гэдэг нь багана болон нүдний дугаарыг илтгэх 1-ээс 8 хүртэлх хоёр тоо.)
Шатрын хөлөгний өгөгдсөн хоёр буудал ижил өнгөтэй юу. Тийм бол YES, үгүй бол NO гэж хэвлэ.
Input
Нэг мөрөнд 4 тоо зайгаар тусгаарлагдан өгөгдөнө.
Output
YES/NO
Example
I... | code | null | ai | 2014-11-06T09:38:14 | 2019-11-23T09:47:02 | null | null | null | #ШАТАР
Шатрын хөлөгний 2 буудал координатаараа өгөгдөв. (Буудлын координат гэдэг нь багана болон нүдний дугаарыг илтгэх 1-ээс 8 хүртэлх хоёр тоо.)
Шатрын хөлөгний өгөгдсөн хоёр буудал ижил өнгөтэй юу. Тийм бол YES, үгүй бол NO гэж хэвлэ.
Input
Нэг мөрөнд 4 тоо зайгаар тусгаарлагдан өгөгдөнө.
Output
YES/NO
Example
I... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-11-06T09:39:02 | 2016-05-12T23:57:59 | setter | б өйыбө быө ыбө ыбйө йыө й | not-set | 2016-04-24T02:03:15 | 2016-04-24T02:03:15 | Unknown |
231 | 5,100 | challange1 | Бодлого1 | #ШАТАР
Шатрын хөлөгний 2 буудал координатаараа өгөгдөв. (Буудлын координат гэдэг нь багана болон нүдний дугаарыг илтгэх 1-ээс 8 хүртэлх хоёр тоо.)
Шатрын хөлөгний өгөгдсөн хоёр буудал ижил өнгөтэй юу. Тийм бол YES, үгүй бол NO гэж хэвлэ.
Input
Нэг мөрөнд 4 тоо зайгаар тусгаарлагдан өгөгдөнө.
Output
YES/NO
Example
I... | code | null | ai | 2014-11-06T09:38:14 | 2019-11-23T09:47:02 | null | null | null | #ШАТАР
Шатрын хөлөгний 2 буудал координатаараа өгөгдөв. (Буудлын координат гэдэг нь багана болон нүдний дугаарыг илтгэх 1-ээс 8 хүртэлх хоёр тоо.)
Шатрын хөлөгний өгөгдсөн хоёр буудал ижил өнгөтэй юу. Тийм бол YES, үгүй бол NO гэж хэвлэ.
Input
Нэг мөрөнд 4 тоо зайгаар тусгаарлагдан өгөгдөнө.
Output
YES/NO
Example
I... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-11-06T09:39:02 | 2016-05-12T23:57:59 | tester | бөйбыөйыб өбый өыб өыб йөыб өыбй | not-set | 2016-04-24T02:03:15 | 2016-04-24T02:03:15 | Unknown |
232 | 5,106 | rahul-and-chemistry | Rahul and Chemistry | Rahul hates Chemistry and he wants to get his experiment done as quickly as possible.
The experiment is to combine adjacent elements until you get one element with minimum cost. Cost of combining elements is explained later.
So you are given an array with $N$ elements where $w_i$ is the weight of the ith element an... | code | null | ai | 2014-11-07T09:32:10 | 2016-09-09T09:58:22 | null | null | null | Rahul hates Chemistry and he wants to get his experiment done as quickly as possible.
The experiment is to combine adjacent elements until you get one element with minimum cost. Cost of combining elements is explained later.
So you are given an array with $N$ elements where $w_i$ is the weight of the ith element an... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-11-07T09:51:03 | 2017-03-18T22:25:40 | setter | #include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<cstring>
#include<numeric>
#include<string>
#include<functional>
#include<complex>
using namespace std;
#define ll l... | not-set | 2016-04-24T02:03:15 | 2016-04-24T02:03:15 | C++ |
233 | 5,108 | painting-balls-1 | Painting Balls | Rahul once decided to paint things up to pass his time. Rahul had $N$ balls kept in a linear fashion all of them are initially not-colored. He has two types of paints _RED_ and _BLUE_. Now he wants to paint the balls such that there are *atmost* $2$ positions where a _RED_ colored ball touches a _BLUE_ colored ball. He... | code | null | ai | 2014-11-07T10:44:05 | 2016-09-09T09:58:23 | null | null | null | Rahul once decided to paint things up to pass his time. Rahul had $N$ balls kept in a linear fashion all of them are initially not-colored. He has two types of paints _RED_ and _BLUE_. Now he wants to paint the balls such that there are *atmost* $2$ positions where a _RED_ colored ball touches a _BLUE_ colored ball. He... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-11-07T10:44:17 | 2016-05-12T23:57:58 | setter | #include <iostream>
using namespace std;
int main()
{
long long n,t;
cin>>t;
while(t--)
{
cin>>n;
cout<<2+ n*(n-1)<<endl;
}
return 0;
}
| not-set | 2016-04-24T02:03:15 | 2016-04-24T02:03:15 | C++ |
234 | 5,126 | if-anweisung | if Anweisung | Prüfe die Zahl | code | if Anweisung | ai | 2014-11-09T18:47:03 | 2016-09-09T09:58:29 | null | null | null | Prüfe die Zahl | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-11-09T18:49:40 | 2016-05-12T23:57:56 | tester | #include <iostream.h>
#include <conio.h>
main()
{
char pin1='0', pin2='8', pin3='1', pin4='5';
char e1, e2, e3, e4;
pinInput:
cout << "Geheimzahl bitte eingeben: ";
e1 = getch();
cout << "*";
e2 = getch();
cout << "*";
e3 = getch();
cout << "*";
e4 = getch();
cout << "*";
... | not-set | 2016-04-24T02:03:15 | 2016-04-24T02:03:15 | C++ |
235 | 5,138 | superman-celebrates-diwali | Superman Celebrates Diwali | Superman has come to india with his girlfriend to celebrate diwali. Unfortunately a fire accident has happened. There are N buildings each of same height H before him which is in fire. Since it's diwali time,some floors may be free as they might have went to their hometown for celebration. He reaches the top of the bui... | code | maximal sum possible by picking values from 2D matrix under some restrictions | ai | 2014-11-10T11:53:03 | 2022-08-31T08:14:47 | null | null | null | Superman has been invited to India to celebrate Diwali. Unfortunately, on his arrival he learns that he has been invited mainly to help rescue people from a fire accident that has happened in a posh residential locale of New Delhi, where rescue is proving to be especially difficult. As he reaches the place of the fire,... | 0.5 | ["ada","bash","c","clojure","coffeescript","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fortran","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","octave","pascal","perl","php","pypy3","python3","r","racket","ruby","rust","sbcl","scala"... | Input starts with three values: the number of buildings $N$, the height of the buildings $H$, and the height Superman will lose when he switches buildings $I$.
These are followed by $N$ lines. Each $i^{th}$ line starts with a non negative integer $u$ indicating how many people are in the $i$<sup>th</sup> building. Ea... | Output the maximum number of people Superman can save. | 4 15 2
5 1 1 1 4 10
8 9 5 7 7 3 9 8 8
5 9 5 6 4 3
0 | 12 | Hard | null | null | null | null | null | null | 2014-11-10T18:01:23 | 2016-12-04T00:09:39 | setter | ###C++
```cpp
# include <iostream>
# include <fstream>
# include <sstream>
# include <algorithm>
# include <numeric>
# include <cstdio>
# include <cmath>
# include <cstdlib>
# include <cstring>
# include <vector>
# include <list>
# include <set>
# include <map>
# include <stack>
# include <queue>
# include... | not-set | 2016-04-24T02:03:15 | 2016-07-23T15:16:12 | C++ |
236 | 5,146 | hcf-lcm | HCF-LCM | **Input Format**
First line contains the number of test cases, $T$. Next $2*T$ lines follow, each containing total number of elements $N$ in the first line and $N$ spaced positive integers, $a_i$ in the second line.
**Output Format**
Output $T$ lines each line in the format:
H:L
where $H$ is the highest ... | code | Given $N$ numbers, find the HCF and LCM of all numbers. | ai | 2014-11-11T00:01:37 | 2016-09-09T09:58:36 | null | null | null | **Input Format**
First line contains the number of test cases, $T$. Next $2*T$ lines follow, each containing total number of elements $N$ in the first line and $N$ spaced positive integers, $a_i$ in the second line.
**Output Format**
Output $T$ lines each line in the format:
H:L
where $H$ is the highest ... | 0.5 | ["bash","c","cpp","java","python","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-11-11T00:03:08 | 2016-05-12T23:57:54 | setter | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define gi(n) cin >> n
#define pi(n) cout << n
#define MAX 111111
ll a[MAX];
ll GCD(ll a, ll b) { return (b==0 ? a : GCD (b , a%b) ) ; }
... | not-set | 2016-04-24T02:03:16 | 2016-04-24T02:03:16 | C++ |
237 | 5,146 | hcf-lcm | HCF-LCM | **Input Format**
First line contains the number of test cases, $T$. Next $2*T$ lines follow, each containing total number of elements $N$ in the first line and $N$ spaced positive integers, $a_i$ in the second line.
**Output Format**
Output $T$ lines each line in the format:
H:L
where $H$ is the highest ... | code | Given $N$ numbers, find the HCF and LCM of all numbers. | ai | 2014-11-11T00:01:37 | 2016-09-09T09:58:36 | null | null | null | **Input Format**
First line contains the number of test cases, $T$. Next $2*T$ lines follow, each containing total number of elements $N$ in the first line and $N$ spaced positive integers, $a_i$ in the second line.
**Output Format**
Output $T$ lines each line in the format:
H:L
where $H$ is the highest ... | 0.5 | ["bash","c","cpp","java","python","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-11-11T00:03:08 | 2016-05-12T23:57:54 | tester | from fractions import *
def lcm(x,y):
return (x*y)/gcd(x,y)
t=input()
for i in range(t):
n=input()
a=map(int,raw_input().split())
print str(reduce(gcd,a)) + ':' + str(reduce(lcm,a)%500) | not-set | 2016-04-24T02:03:16 | 2016-04-24T02:03:16 | Python |
238 | 5,147 | stocks-prediction | Stock Prediction | Statement goes here. We support markdown + latex. Note that to insert new line, end a line with at least 2 spaces.
**Input format**
blah blah.
**Output format**
blah blah.
**Constraints**
...
...
**Note** (optional)
...
**Sample Input #00**
abc
def...
**Sample Output #00**
pqr
... | code | null | ai | 2014-11-11T04:24:29 | 2016-09-01T16:43:12 | null | null | null | George is very concerned about the stock options his company has granted him, because the company's stock price has fluctuated unpredictably and has often failed to meet expectations. With this in mind, George has decided to sell his options. Before doing so, he would like to perform a series of calculations.
Stock ... | 0.571429 | ["haskell","clojure","scala","erlang","sbcl","ocaml","fsharp","racket","elixir"] | The first list contains an integer $n$ which represents the length of the array $A$. The second line contains $n$ space-separated integers, $a_0, a_1, \ldots, a_{n-1}$, which represent the element of array $A$. The next line contains the number of queries $Q$. Each of the subsequent $Q$ lines contain two integers $d$ a... | For each query output the length of the longest subarray with the required properties.
**Constraints**
$1 \le n \le 5\cdot 10^4$
$1 \le A[i] \le 10^9, 0 \le i < n$
$1 \le Q \le 10^5$
$0 \le d < n$
$0 \le M \le 10^9$ | 5
3 5 2 6 1
2
0 2
2 3 | 2
3 | Hard | null | null | null | null | null | null | 2014-11-18T07:57:12 | 2016-12-24T15:53:12 | setter | import java.io.{BufferedReader, FileReader, InputStreamReader, Reader}
object Solution {
class Query(_index: Int, _margin: Int) {
def index = _index
def margin = _margin
}
def parseQuery(s: String): Query = {
val elements = s.split(' ').map(Integer.parseInt).toList
... | not-set | 2016-04-24T02:03:17 | 2016-04-24T02:03:17 | Python |
239 | 5,147 | stocks-prediction | Stock Prediction | Statement goes here. We support markdown + latex. Note that to insert new line, end a line with at least 2 spaces.
**Input format**
blah blah.
**Output format**
blah blah.
**Constraints**
...
...
**Note** (optional)
...
**Sample Input #00**
abc
def...
**Sample Output #00**
pqr
... | code | null | ai | 2014-11-11T04:24:29 | 2016-09-01T16:43:12 | null | null | null | George is very concerned about the stock options his company has granted him, because the company's stock price has fluctuated unpredictably and has often failed to meet expectations. With this in mind, George has decided to sell his options. Before doing so, he would like to perform a series of calculations.
Stock ... | 0.571429 | ["haskell","clojure","scala","erlang","sbcl","ocaml","fsharp","racket","elixir"] | The first list contains an integer $n$ which represents the length of the array $A$. The second line contains $n$ space-separated integers, $a_0, a_1, \ldots, a_{n-1}$, which represent the element of array $A$. The next line contains the number of queries $Q$. Each of the subsequent $Q$ lines contain two integers $d$ a... | For each query output the length of the longest subarray with the required properties.
**Constraints**
$1 \le n \le 5\cdot 10^4$
$1 \le A[i] \le 10^9, 0 \le i < n$
$1 \le Q \le 10^5$
$0 \le d < n$
$0 \le M \le 10^9$ | 5
3 5 2 6 1
2
0 2
2 3 | 2
3 | Hard | null | null | null | null | null | null | 2014-11-18T07:57:12 | 2016-12-24T15:53:12 | tester | /**
* Created by Bo You on 2014/12/2.
*/
object Solution {
class Node(val l: Int, val r: Int, val minValue: Int, val maxValue: Int)
def build(a: Array[Int], n: Int, sz: Int, ng: Int): Array[Node] = {
def iter(cur: Int, ans: List[Node]): List[Node] = {
if (cur == ng) {
... | not-set | 2016-04-24T02:03:17 | 2016-04-24T02:03:17 | Python |
240 | 5,264 | white-falcon-and-sequence | White Falcon and Sequence | null | code | null | ai | 2014-11-20T13:26:55 | 2019-07-02T13:59:01 | null | null | null | White Falcon has a sequence of integers $A$. You need to choose two contiguous disjoint subsequences of $A$, let's say $x$ and $y$, of the same size, $n$.
After that you will calculate the sum given by $\sum x_i y_{n-i+1}$ (1-indexed)
White Falcon asks you to choose such two $x$ and $y$ that maximizes the above sum... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | Hard | null | null | null | null | null | null | 2014-11-20T13:29:01 | 2016-12-10T18:29:59 | setter | #include <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cassert>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <string>
#include <cmath>
#include <ctime>
#include <queue>
#include <list>
#inc... | not-set | 2016-04-24T02:03:17 | 2016-04-24T02:03:17 | C++ | ||||
241 | 5,300 | putting-numbers | Putting Numbers | null | code | Counting is funny! | ai | 2014-11-23T23:56:16 | 2016-09-09T09:59:44 | null | null | null | My little brothers David and Goliath are learning to count up to large numbers, then they are playing a game that consist to put all the numbers from 1 to N in a table. The numbers are plastic and are in two boxes, they take it out and put it on the table in a straight line in ascending order. A box has numbers from 1 ... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | The only line of input contains three integers N, p and k (2000 <= N <= 10^9) (1000 <= p,k < N) with k != p. | Print a line with the number if different ways to put the numbers from 1 to N modulo 10^9 + 7 (1000000007). | 6 2 3 | 2 | Hard | null | null | null | null | null | null | 2014-11-23T23:57:13 | 2016-05-12T23:57:42 | setter | #include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define N 1000005
#define ll long long
const ll mod = 1000000007;
ll fact[N];
ll GCDext(ll a, ll b, ll &x, ll &y){
ll g = a; x = 1; y = 0;
if(b!=0){
g = GCDext(b, a%b, y, x);
y -= (a/b)*x;
}
return g;
}
ll invMod(ll a, ll m, ll &in... | not-set | 2016-04-24T02:03:17 | 2016-04-24T02:03:17 | C++ |
242 | 5,369 | minimum-multiple | Minimum Multiple | null | code | Find the least multiple of a subarray | ai | 2014-12-01T17:45:55 | 2016-09-01T16:43:08 | null | null | null | Calculi is Lambda's older brother. Lambda is mischievous and always annoys Calculi by asking silly questions. This time around, Lambda would like to surprise Calculi by asking a challenging and interesting question. To that end, Lambda gives Calculi an array of $N$ integers, $A = \{a_0, a_1,\ldots, a_{N-1}\}$, followe... | 0.571429 | ["haskell","clojure","scala","erlang","sbcl","ocaml","fsharp","racket","elixir"] | The first line contains an integer, $N$, which represents the length of array, $A$.
In second line, there are $N$ space-separated integers, $a_0, a_1,\ldots, a_{N-1}$, representing the elements of $A$.
In third line, there is another integer, $K$, which is the count of queries to follow.
Then follows $K$ lines, ... | For each query of type `Q l r`, print the value of $M \% (10^9+7)$ on a new line. | 5
2 5 6 1 9
7
Q 0 4
U 1 2
Q 0 2
Q 3 4
Q 2 4
U 3 8
Q 2 3 | 90
30
9
18
24 | Hard | null | null | null | null | null | null | 2014-12-01T17:50:45 | 2016-12-02T06:01:22 | setter | module Main where
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Control.Arrow ((&&&))
p :: Int
p = 10^(9::Int)+7
primeFactors :: Map.Map Int [(Int, Int)]
primeFactors =
Map.fromList. zip [1..]. map (map (head &&& length). group. factoriz... | not-set | 2016-04-24T02:03:18 | 2016-04-24T02:03:18 | Python |
243 | 5,396 | fibonacci-lcm | Fibonacci LCM | null | code | Find the LCM of Fibonacci numbers | ai | 2014-12-03T19:42:44 | 2022-09-02T09:54:43 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY f as parameter.
#
def solve(f):
# Write your code here
| #!/bin/python3
import math
import os
import random
import re
import sys
| if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
f_count = int(input().strip())
f = []
for _ in range(f_count):
f_item = int(input().strip())
f.append(f_item)
result = solve(f)
fptr.write(str(result) + '\n')
fptr.close()
| After Derek (of district 5) discovered how to compute the greatest common divisor (gcd) of Fibonacci numbers, he now tried to answer the next obvious question: how does one compute the *least common multiple* (lcm) of Fibonacci numbers? Unfortunately, Derek found out that this wasn't as easy as the original problem, so... | 0.5 | ["c","clojure","cpp","cpp14","cpp20","csharp","erlang","go","haskell","java","java8","java15","javascript","julia","kotlin","lua","objectivec","perl","php","pypy3","python3","ruby","rust","scala","swift","typescript","r"] | Hard | null | null | null | null | null | null | 2014-12-03T20:34:25 | 2016-07-23T18:16:55 | setter | ###C++
```cpp
#include <stdio.h>
#include <stdlib.h>
#include <tr1/unordered_map>
#include <tr1/unordered_set>
#include <algorithm>
#define mod 1000000007
#define L 10000000
#define ll long long
using namespace std;
ll ipow(ll b, ll e) {
if (e == 1) return b;
if (e & 1) return ipow(b, e - 1) * b % mod;
... | not-set | 2016-04-24T02:03:18 | 2016-07-23T18:14:29 | C++ | ||||
244 | 5,396 | fibonacci-lcm | Fibonacci LCM | null | code | Find the LCM of Fibonacci numbers | ai | 2014-12-03T19:42:44 | 2022-09-02T09:54:43 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY f as parameter.
#
def solve(f):
# Write your code here
| #!/bin/python3
import math
import os
import random
import re
import sys
| if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
f_count = int(input().strip())
f = []
for _ in range(f_count):
f_item = int(input().strip())
f.append(f_item)
result = solve(f)
fptr.write(str(result) + '\n')
fptr.close()
| After Derek (of district 5) discovered how to compute the greatest common divisor (gcd) of Fibonacci numbers, he now tried to answer the next obvious question: how does one compute the *least common multiple* (lcm) of Fibonacci numbers? Unfortunately, Derek found out that this wasn't as easy as the original problem, so... | 0.5 | ["c","clojure","cpp","cpp14","cpp20","csharp","erlang","go","haskell","java","java8","java15","javascript","julia","kotlin","lua","objectivec","perl","php","pypy3","python3","ruby","rust","scala","swift","typescript","r"] | Hard | null | null | null | null | null | null | 2014-12-03T20:34:25 | 2016-07-23T18:16:55 | tester | ###C++
```cpp
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <ctime>
#include <unordered_... | not-set | 2016-04-24T02:03:18 | 2016-07-23T18:16:55 | C++ | ||||
245 | 5,443 | house-arrest | House Arrest | null | code | Help Jejeman find the best lot for his house arrest. | ai | 2014-12-06T14:38:05 | 2016-09-09T10:00:39 | null | null | null | After suddenly getting an illness that required him to use a wheel chair, the Supreme Court decided to put Jejeman under house arrest instead of the normal prison.
According to the Constitution, the lot (the house including the garden and everything) where Jejeman will be banished to will have some constraints.
First... | 0.5 | ["c","cpp","java","python3","python","cpp14"] | The first line of input contains $C$, the number of test cases. The following lines describe the test cases.
Each test case consists of one line containing two integers, $A$ and $P$, as discussed above.
| For each test case, output `WALA` if there is no polygon satisfying all the above.
Otherwise, write $M$ in the first line, where $M$ is the number of corners of the polygon. In the next $M$ lines, write the coordinates $(x_i, y_i)$ of the corners (in either order around the polygon). Naturally, $(x_M, y_M)$ is assume... | 3
4 8
3 8
1 20 | 4
1 1
1 -1
-1 -1
-1 1
6
0 0
2 0
2 1
1 1
1 2
0 2
WALA | Hard | null | null | null | null | null | null | 2014-12-06T18:10:41 | 2017-10-05T00:13:30 | setter | ```c++
#include <stdio.h>
#include <math.h>
#include <set>
using namespace std;
#define ll long long
#define BD (2000000000000000LL-10) // 2*10^15 - 10
#define DL 1000000000000000LL // 10^15
// computes the integer square root
ll isqrt(ll n) {
ll s = int(sqrt(n));
while (s * s < n) s += 1;
while (s * s > ... | not-set | 2016-04-24T02:03:19 | 2017-10-05T00:13:30 | C++ |
246 | 5,493 | the-tide-is-high | The Tide is High | null | code | Compute the productivity of an archipelago when the tide is high. | ai | 2014-12-08T06:31:36 | 2016-12-01T08:20:54 | null | null | null | It is widely known that the Philippines has 7107 islands. But of course, that doesn't account for when some islands are covered during high tide and when some islands spring out during low tide. So it's definitely not a fixed number. Let's just say the Philippines has at least 7000 islands to be safe. In fact, there ar... | 0.5 | ["c","cpp","java","python","python3","java8","cpp14"] | The first line of input contains $T$, the number of test cases. The following lines describe the test cases.
The first line of each test case contains two integers $W$ and $L$ denoting the width and the length of the map. The next $W$ lines each contain $L$ characters where each character is either a `#` or a `~`, des... | For each test case, output a single line containing $L$ integers, where the $x^{\text{th}}$ integer is the productivity of the area *during high tide* if the $x^{\text{th}}$ column of land has the lowest height.
**Constraints**
$1 \le T \le 20$
$L \ge 1$
$W \ge 1$
**Subtask 1** (11 points each):
$1 \le L\c... | 4
3 2
~~
~~
~~
3 3
~~~
~#~
~~~
5 7
~~~~~~~
#######
~~~~~~~
~~~~##~
####~~~
7 15
~~~~~~~~~~~~~~~
~#~~#~~##~~###~
~##~#~#~~#~~#~~
~#~##~#~~#~~#~~
~#~~#~#~~#~~#~~
~#~~#~~##~~###~
~~~~~~~~~~~~~~~
| 0 0
1 0 1
49 35 29 31 37 43 56
179 144 168 168 144 179 170 173 173 170 179 147 102 147 179
| Hard | null | null | null | null | null | null | 2014-12-18T06:39:57 | 2017-10-09T21:05:39 | setter | ```c++
#include <stdio.h>
#define L 100011
#define ll long long
char g[L];
ll lps[L];
ll rps[L];
int parent[L];
int size[L];
int find(int n) {
return parent[n] < 0 ? n : parent[n] = find(parent[n]);
}
void onion(int i, int j) {
if (parent[i] == parent[j]) {
parent[i]--;
}
if (parent[i] > pare... | not-set | 2016-04-24T02:03:21 | 2017-10-09T21:05:40 | C++ |
247 | 5,493 | the-tide-is-high | The Tide is High | null | code | Compute the productivity of an archipelago when the tide is high. | ai | 2014-12-08T06:31:36 | 2016-12-01T08:20:54 | null | null | null | It is widely known that the Philippines has 7107 islands. But of course, that doesn't account for when some islands are covered during high tide and when some islands spring out during low tide. So it's definitely not a fixed number. Let's just say the Philippines has at least 7000 islands to be safe. In fact, there ar... | 0.5 | ["c","cpp","java","python","python3","java8","cpp14"] | The first line of input contains $T$, the number of test cases. The following lines describe the test cases.
The first line of each test case contains two integers $W$ and $L$ denoting the width and the length of the map. The next $W$ lines each contain $L$ characters where each character is either a `#` or a `~`, des... | For each test case, output a single line containing $L$ integers, where the $x^{\text{th}}$ integer is the productivity of the area *during high tide* if the $x^{\text{th}}$ column of land has the lowest height.
**Constraints**
$1 \le T \le 20$
$L \ge 1$
$W \ge 1$
**Subtask 1** (11 points each):
$1 \le L\c... | 4
3 2
~~
~~
~~
3 3
~~~
~#~
~~~
5 7
~~~~~~~
#######
~~~~~~~
~~~~##~
####~~~
7 15
~~~~~~~~~~~~~~~
~#~~#~~##~~###~
~##~#~#~~#~~#~~
~#~##~#~~#~~#~~
~#~~#~#~~#~~#~~
~#~~#~~##~~###~
~~~~~~~~~~~~~~~
| 0 0
1 0 1
49 35 29 31 37 43 56
179 144 168 168 144 179 170 173 173 170 179 147 102 147 179
| Hard | null | null | null | null | null | null | 2014-12-18T06:39:57 | 2017-10-09T21:05:39 | tester | ```c++
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <string>
#include <cstring>
using namespace std;
char s[100005];
int f[100005];
int num[100005];
long long save[100005];
inline long long sqr(long long x) {
return x * x;
}
int getf(... | not-set | 2016-04-24T02:03:21 | 2017-10-09T21:05:40 | C++ |
248 | 5,452 | confidentialegassem-8 | Confidential Message | null | code | Yuo received a message but it was jumbled by some confidential process. | ai | 2014-12-06T18:54:29 | 2016-12-01T08:20:40 | null | null | null | Yuo is a new student in his class.
The girls in his class apparently communicate information using a confidential process to somehow jumble the message.
Each jumbled message has a corresponding sequence of integers attached to it: $s_1, \ldots, s_N$. To "unjumble" the message, look at the last $s_1$ letters of the ju... | 0.5 | ["c","cpp","java","python","python3","java8","cpp14"] | The first line of input contains an integer $T$, the number of test cases.
Each test case consists of three lines. The first line contains two integers $L$ and $N$, where $L$ is the length of the jumbled message (and of course, also the length of the unjumbled message). The second line contains a string $J$, the jumbl... | For each test case, output a single line containing a string: the unjumbled message.
**Constraints**
$1 \le T \le 3$
$1 \le s_i \le L$
**Subtask 1** (8 points each):
$1 \le L, N \le 20$
**Subtask 2** (8 points each):
$1 \le L, N \le 1000$
**Subtask 3** (10 points each):
$1 \le L, N \le 100000$
... | 3
44 5
ireallyreallyreallyreallyreallyreallylikeyou
44 44 2 44 44
6 3
setter
6 3 6
13 8
elevenplustwo
3 13 11 8 9 6 7 2
| ireallyreallyreallyreallyreallyreallylikeyuo
tester
twelveplusone
| Hard | null | null | null | null | null | null | 2014-12-18T08:34:21 | 2018-02-06T17:43:56 | setter | ```cpp
#include <stdio.h>
#include <math.h>
#define LIM 100011
#define SLIM 1011
struct Piece {
int i, length;
bool back;
Piece() {}
Piece(int i, int length, bool back): i(i), length(length), back(back) {}
int kth(int k) {
return back ? i - k : i + k;
}
int end() {
return ... | not-set | 2016-04-24T02:03:21 | 2018-02-06T17:43:56 | C++ |
249 | 5,452 | confidentialegassem-8 | Confidential Message | null | code | Yuo received a message but it was jumbled by some confidential process. | ai | 2014-12-06T18:54:29 | 2016-12-01T08:20:40 | null | null | null | Yuo is a new student in his class.
The girls in his class apparently communicate information using a confidential process to somehow jumble the message.
Each jumbled message has a corresponding sequence of integers attached to it: $s_1, \ldots, s_N$. To "unjumble" the message, look at the last $s_1$ letters of the ju... | 0.5 | ["c","cpp","java","python","python3","java8","cpp14"] | The first line of input contains an integer $T$, the number of test cases.
Each test case consists of three lines. The first line contains two integers $L$ and $N$, where $L$ is the length of the jumbled message (and of course, also the length of the unjumbled message). The second line contains a string $J$, the jumbl... | For each test case, output a single line containing a string: the unjumbled message.
**Constraints**
$1 \le T \le 3$
$1 \le s_i \le L$
**Subtask 1** (8 points each):
$1 \le L, N \le 20$
**Subtask 2** (8 points each):
$1 \le L, N \le 1000$
**Subtask 3** (10 points each):
$1 \le L, N \le 100000$
... | 3
44 5
ireallyreallyreallyreallyreallyreallylikeyou
44 44 2 44 44
6 3
setter
6 3 6
13 8
elevenplustwo
3 13 11 8 9 6 7 2
| ireallyreallyreallyreallyreallyreallylikeyuo
tester
twelveplusone
| Hard | null | null | null | null | null | null | 2014-12-18T08:34:21 | 2018-02-06T17:43:56 | tester | ```cpp
#include<bits/stdc++.h>
using namespace std;
struct {
int sz, prior, lSon, rSon;
bool rev;
char c;
} t[300001];
int newNode(char c) {
static int tw = 0;
tw++;
t[tw].sz = 1;
t[tw].prior = rand();
t[tw].c = c;
return tw;
}
void push(int v) {
if (t[v].rev) {
t[v... | not-set | 2016-04-24T02:03:21 | 2018-02-06T17:43:56 | C++ |
250 | 5,206 | waver1 | Waver's Flight | Clock Tower is the official headquarters of the Mage's Association. Lord El-Melloi is a powerful magus who teaches here. Waver, an average magus who studies at Clock Tower was humiliated by his lecturer, Lord El-Melloi. In retaliation he stole an artifact belonging to his lecturer. He now needs to escape the Clock Towe... | code | Given a weighted tree and some additional edges, find the shortest distances to leaves of the tree from all vertices, where you can only traverse the extra edges a limited number of times. | ai | 2014-11-17T05:38:37 | 2019-07-02T13:59:00 | null | null | null | Waver needs to get out of the Clock Tower immediately. The Clock Tower is a tree of $N$ vertices numbered $1$ through $N$. Additionally, there are $E$ shortcut edges. Using shortcuts arouses suspicion, therefore Waver has decided that he will use shortcuts at most $K$ times. He needs to get to an exit to leave the plac... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | The first line contains three integers: $N$ (the number of vertices), $E$ (the number of shortcut edges), and $K$ (the number of times shortcut edges can be used).
The next $N-1$ lines contain three integers, $a$, $b$, and $w$ each, indicating that vertices $a$ and $b$ are connected by a tree edge of weight $w$.
$E... | Output must consist of $N$ lines, where the $i$<sup>$th$</sup> line has a single integer denoting the least units of time Waver needs to the exit from vertex $i$. | 6 2 1
1 5 25
5 4 1
6 4 11
4 3 10
2 3 100
3 4 7
5 1 3 | 0
0
14
4
3
0 | Hard | null | null | null | null | null | null | 2014-12-19T09:13:09 | 2017-02-10T15:51:45 | setter | #include <iostream>
#include <cassert>
#include <cstdio>
#include <vector>
#include <tuple>
using namespace std;
#define inc(i,a,b) for(int i=a;i<=b;++i)
#define dec(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define mt ... | not-set | 2016-04-24T02:03:21 | 2016-04-24T02:03:21 | C++ |
251 | 5,206 | waver1 | Waver's Flight | Clock Tower is the official headquarters of the Mage's Association. Lord El-Melloi is a powerful magus who teaches here. Waver, an average magus who studies at Clock Tower was humiliated by his lecturer, Lord El-Melloi. In retaliation he stole an artifact belonging to his lecturer. He now needs to escape the Clock Towe... | code | Given a weighted tree and some additional edges, find the shortest distances to leaves of the tree from all vertices, where you can only traverse the extra edges a limited number of times. | ai | 2014-11-17T05:38:37 | 2019-07-02T13:59:00 | null | null | null | Waver needs to get out of the Clock Tower immediately. The Clock Tower is a tree of $N$ vertices numbered $1$ through $N$. Additionally, there are $E$ shortcut edges. Using shortcuts arouses suspicion, therefore Waver has decided that he will use shortcuts at most $K$ times. He needs to get to an exit to leave the plac... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | The first line contains three integers: $N$ (the number of vertices), $E$ (the number of shortcut edges), and $K$ (the number of times shortcut edges can be used).
The next $N-1$ lines contain three integers, $a$, $b$, and $w$ each, indicating that vertices $a$ and $b$ are connected by a tree edge of weight $w$.
$E... | Output must consist of $N$ lines, where the $i$<sup>$th$</sup> line has a single integer denoting the least units of time Waver needs to the exit from vertex $i$. | 6 2 1
1 5 25
5 4 1
6 4 11
4 3 10
2 3 100
3 4 7
5 1 3 | 0
0
14
4
3
0 | Hard | null | null | null | null | null | null | 2014-12-19T09:13:09 | 2017-02-10T15:51:45 | tester | /*
* Bidhan Roy
* University of Dhaka
*/
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for(auto i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w",stdout);
#define read(x) freopen(x,"r",stdin);
#define all(x) x... | not-set | 2016-04-24T02:03:21 | 2016-04-24T02:03:21 | C++ |
252 | 5,617 | contiguous-subsequences | Contiguous subsequences | null | code | null | ai | 2014-12-19T19:33:59 | 2016-09-09T10:02:13 | null | null | null | Yash got a sequence of n positive integers ! He likes contiguous subsequences whose sum(mod)p = 0. He asks you to write a program to count them for him. | 0.5 | ["c","cpp","java","cpp14"] | The first line contains T, the number of testcases.
T testcases follow. Each testcase consists of 2 lines.
The first line contains n and p separated by a single space.
And the second line contains n space separated integers. | For each test case, output the number of contiguous subsequenences whose sum(mod)p = 0 in a newline.
Constraints
1 ≤ T ≤ 20
1 ≤ n ≤ 10^6
1 ≤ k ≤ 100
1 ≤ a[i] ≤ 10^4 | 2
4 3
1 2 3 4
5 2
1 2 1 2 1 | 4
6 | Hard | null | null | null | null | null | null | 2014-12-19T19:43:55 | 2017-07-20T10:40:47 | setter | <pre><p> #include <bits/stdc++.h> </p>
using namespace std;
typedef long long LL;
int main(){
LL test,n,k,x;
cin >> test;
while(test --)
{
cin >> n >> k;
LL sum[n+3],cnt[k+3];
sum[0] = 0;
memset(cnt, 0, sizeof cnt);
cnt[0] = 1;
for(int i = 1; i <= n; i ++)
{
... | not-set | 2016-04-24T02:03:22 | 2016-04-24T02:03:22 | C++ |
253 | 5,617 | contiguous-subsequences | Contiguous subsequences | null | code | null | ai | 2014-12-19T19:33:59 | 2016-09-09T10:02:13 | null | null | null | Yash got a sequence of n positive integers ! He likes contiguous subsequences whose sum(mod)p = 0. He asks you to write a program to count them for him. | 0.5 | ["c","cpp","java","cpp14"] | The first line contains T, the number of testcases.
T testcases follow. Each testcase consists of 2 lines.
The first line contains n and p separated by a single space.
And the second line contains n space separated integers. | For each test case, output the number of contiguous subsequenences whose sum(mod)p = 0 in a newline.
Constraints
1 ≤ T ≤ 20
1 ≤ n ≤ 10^6
1 ≤ k ≤ 100
1 ≤ a[i] ≤ 10^4 | 2
4 3
1 2 3 4
5 2
1 2 1 2 1 | 4
6 | Hard | null | null | null | null | null | null | 2014-12-19T19:43:55 | 2017-07-20T10:40:47 | tester | <pre><p> #include <bits/stdc++.h> </p>
using namespace std;
int main(){
long long t;
cin>>t;
while(t--)
{
long long int n,k,i,j;
cin>>n>>k;
long long int x,sum[n+3],cnt[k+3];
sum[0]=0;
memset(cnt,0,sizeof(cnt));
cnt[0]=1;
... | not-set | 2016-04-24T02:03:22 | 2016-04-24T02:03:22 | C++ |
254 | 5,595 | dijkstrashortreach | Dijkstra: Shortest Reach 2 | null | code | Learn to use Dijkstra's shortest path algorithm ! | ai | 2014-12-19T07:54:20 | 2022-08-31T08:14:24 | #
# Complete the 'shortestReach' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts following parameters:
# 1. INTEGER n
# 2. 2D_INTEGER_ARRAY edges
# 3. INTEGER s
#
def shortestReach(n, edges, s):
# Write your code here
| #!/bin/python3
import math
import os
import random
import re
import sys
| if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
edges = []
for _ in range(m):... | Given an undirected graph and a starting node, determine the lengths of the shortest paths from the starting node to all other nodes in the graph. If a node is unreachable, its distance is -1. Nodes will be numbered consecutively from $1$ to $n$, and edges will have varying distances or lengths.
For example, consid... | 0.5 | ["c","clojure","cpp","cpp14","cpp20","csharp","erlang","go","haskell","java","java8","java15","javascript","julia","kotlin","lua","objectivec","perl","php","pypy3","python3","r","ruby","rust","scala","swift","typescript"] | The first line contains $t$, the number of test cases.
Each test case is as follows:
- The first line contains two space-separated integers $n$ and $m$, the number of nodes and edges in the graph.
- Each of the next $m$ lines contains three space-separated integers $x$, $y$, and $r$, the beginning and ending node... | For each of the $t$ test cases, print a single line consisting $n-1$ space separated integers denoting the shortest distance to the $n-1$ nodes from starting position $s$ in increasing order of their labels, excluding $s$.
For unreachable nodes, print $-1$. | 1
4 4
1 2 24
1 4 20
3 1 3
4 3 12
1 | 24 3 15 | Hard | null | null | null | null | null | null | 2014-12-21T08:52:49 | 2018-04-11T16:09:48 | setter | ###C++
```cpp
#define INF 99999999
#define pb push_back
#define mp make_pair
using namespace std;
vector<pair<'int','int'> >adj[10009];
vector<int> dijkstra(vector<int>d,int s,int n) {
d.clear();
d.resize(n+1);
for(int i=0;i<=n;i++)
d[i]=INF;
set<pair<int,int> >q;
q.clear();
bool ... | not-set | 2016-04-24T02:03:22 | 2017-05-25T10:14:52 | C++ |
255 | 5,643 | wet-shark-and-kth-largest-number | Kth Number | null | code | null | ai | 2014-12-23T04:00:41 | 2019-07-02T13:59:23 | null | null | null | You are given an array of $N$ positive integers, $A_1, A_2, \ldots, A_n$. You have to answer $Q$ queries. Each query consists of two integers $L$ and $K$.
For each query, you have to consider all the elements of array greater than or equal to $L$, in _original order of occurrence_ in array $A$ and then find the $K^{th... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | The first line contains two integers $N$ and $Q$. The next line contains $N$ space separated integers, representing the array, $A_1,\ A_2,\ \ldots,\ A_n$.
Each of the next $Q$ lines contain two space separated integers $L$ and $K$.
**Constraints**:
$1\le N \le 10^5$
$1 \le Q \le 10^5$
$1 \le A_i \le 10^5$
$1 \le ... | Output $Q$ lines, the answer for each query. | 10 4
1 9 2 8 3 7 4 6 5 10
4 4
3 2
1 6
8 1 | 4
8
7
9 | Hard | null | null | null | null | null | null | 2014-12-23T04:01:38 | 2016-12-03T15:01:31 | setter | #include <bits/stdc++.h>
using namespace std;
vector <int> indices[100005]; int arr[100005];
struct node
{
node * first; node * second; int count;
node (node * a, node * b, int c){first=a; second=b; count=c;}
};
node * root = new node (NULL, NULL, 0);
node * x[100005];... | not-set | 2016-04-24T02:03:22 | 2016-04-24T02:03:22 | C++ |
256 | 5,574 | k-repeated-1s | K repeated 1s | null | code | null | ai | 2014-12-16T17:47:44 | 2016-09-09T10:01:44 | null | null | null | One day Sanchit decided to write all numbers starting from 1 in binary format. The list goes like this 1,10,11,100,... and so on. Now he gets bored of this list and decides to remove all the numbers having atleast k consecutive ones and prepare a new list. He then thought if a number n is given to him can he find the n... | 0.5 | ["c","cpp","java","csharp","ruby","python","perl","pascal","python3","objectivec","cpp14"] | First line of each input is T and k separated by spaces where T is number of test cases and k is explained above. T lines folow. Each line contains one number n. | You have to output n<sup>th</sup> binary number for each case. Each case must be in a new line. | 5 2
1
2
3
4
5 | 1
10
100
101
1000 | Hard | null | null | null | null | null | null | 2014-12-26T13:25:55 | 2017-01-08T09:31:26 | setter | #include<stdio.h>
int main()
{
int t,k,p,l;
long long int n,i,j;
long long int a[2001],ans[2001];
scanf("%d %d",&t,&k);
p=0;
l=1;
while(p<k)
{
a[p]=l;
l*=2;
p++;
}
for(i=k;i<2000;i++)
... | not-set | 2016-04-24T02:03:23 | 2016-04-24T02:03:23 | C++ |
257 | 5,692 | detective-and-santa | Detective and Santa | null | code | null | ai | 2014-12-26T16:37:56 | 2016-09-09T10:03:10 | null | null | null | Its Chritmas ! You and your friend are waiting for Santa. But he hasnt come yet. You are getting paranoid of his archenemy. One of your friend mentioned that the everyone in the town has been facing weird problems with their computer, whom thet call 'The Monster', recently.On Chritmas afternoon, you received a note fro... | 0.5 | ["c","cpp","java","cpp14"] | The 1st line contain an integer T, the number of test cases.Followed by T lines, each having an integer P which is number of digits. | Largest Best number having P digits of password. If no such number exists, then print '-1'
Constraints
1<=T<=20
1<=P<=100000 | 3
1
8
15 | -1
55533333
555555555555555
| Hard | null | null | null | null | null | null | 2014-12-26T16:39:11 | 2016-05-12T23:57:03 | setter | <pre>
<p>#include <bits/stdc++.h></p>
using namespace std;
int main()
{
int n,test,k,kstart; ... | not-set | 2016-04-24T02:03:23 | 2016-04-24T02:03:23 | C++ |
258 | 5,698 | search-numbers | Search Numbers | null | code | null | ai | 2014-12-26T20:58:57 | 2016-09-09T10:03:12 | null | null | null | Mohit has just learnt multiplying two integers. Such that
**A(multiply)B=C**.
To make the problem hard he will select *A* in the range *1 to P* and *B* in the range *1 to Q*. Help him to find the number of methods. | 0.5 | ["c","cpp","java","cpp14"] | First line of the input is the number of test cases *T*. It is followed by T lines. Each line has three space separated integers, the numbers *C*, *P* and *Q*. | For each test case output a single integer, the number of ways.
**Constraints**
1 <= T <= 50
1 <= C <= 10^12
1 <= P <= 10^12
1 <= Q <= 10^12 | 4
4 7 9
5 2 10
5 5 6
2 8 1 | 3
1
2
1 | Hard | null | null | null | null | null | null | 2014-12-26T21:02:42 | 2016-05-12T23:57:02 | setter | <pre>
<p>#include<stdio.h></p>
<p>#include<math.h></p>
void solve(unsigned long long ,unsigned long long ,unsigned long long);
int main()
{
unsigned long long N,M,Z;
int test_case;
scanf("%d",&test_case);
while(test_case--)
{
scanf("%llu",&Z); ... | not-set | 2016-04-24T02:03:23 | 2016-04-24T02:03:23 | C++ |
259 | 5,697 | floyd-city-of-blinding-lights | Floyd : City of Blinding Lights | null | code | Learn to use Floyd Warshall's algorithm ! | ai | 2014-12-26T20:38:53 | 2022-08-31T08:14:27 | #!/bin/python3
import math
import os
import random
import re
import sys
| if __name__ == '__main__':
road_nodes, road_edges = map(int, input().rstrip().split())
road_from = [0] * road_edges
road_to = [0] * road_edges
road_weight = [0] * road_edges
for i in range(road_edges):
road_from[i], road_to[i], road_weight[i] = map(int, input().rstrip().split())
q = i... | Given a directed weighted graph where weight indicates distance, for each query, determine the length of the shortest path between nodes. There may be many queries, so efficiency counts.
For example, your graph consists of $5$ nodes as in the following:

{
int n,m,i,x,y,r,a,b,j,k,q;
cin>>n>>m;
int adj[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
adj[i][j]=INF;
}
}
for(i=0;i<n;i++)
adj[i][i]=0;
int floyd[n][n];
for(i=0;i<m;i++)
{
cin>>x>>y>>r;
adj[x-1][y-1]=r;
}
... | not-set | 2016-04-24T02:03:24 | 2016-07-23T13:53:58 | C++ | |
260 | 5,715 | fibonacci-sum | Fibonacci Sum | null | code | null | ai | 2015-01-01T17:41:06 | 2016-09-09T10:03:19 | null | null | null | The series defined below is called fibonacci series.
1,1,2,3,5,8
Recursively it is defined as follow:-
Fib[1]=1
Fib[2]=1
Fib[i]=Fib[i-1]+Fib[i-2] ,i>2
Let us define a function Sum(N)
Sum(N)=Fib[1]+Fib[2]+..Fib[N]
You are given the value of N, you need to out Sum(N)%1000000007 | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | The only line of the input will contain N.
1<=N<=10^16 | For each N print Sum(N)%1000000007 i.e the sum of the series(Fib[1]+Fib[2]+..Fib[N])%1000000007. | 2
| 2
| Hard | null | null | null | null | null | null | 2015-01-01T17:42:25 | 2016-05-12T23:56:59 | setter | #include <iostream>
#include <cstdio>
using namespace std;
#define mod 1000000007
#define rep(i,a,N) for(int i=a;i<N;++i)
typedef long long ll;
void multiply(ll F[2][2], ll M[2][2]){
ll x = (F[0][0]*M[0][0])%mod + (F[0][1]*M[1][0])%mod;
ll y = (F[0][0]*M[0][1])%mod + (F[0][... | not-set | 2016-04-24T02:03:24 | 2016-04-24T02:03:24 | C++ |
261 | 5,717 | toposut | Topological Sort : Uniqueness Test | null | code | Perform the uniqueness test ! | ai | 2015-01-01T21:43:48 | 2016-09-09T10:03:20 | null | null | null | Given a directed, unweighted and acyclic graph, it is required to test the graph, whether in it, an ordering of all the vertices of the graph exists, such that :
* If there is a path from u to v, then v appears after u in the ordering.
is the __only one__ that exists in the graph or __not__.
Print in a single line `... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | First line has two integers $N$, denoting the number of nodes in the graph and $M$, denoting the number of edges in the graph.
The next $M$ lines each consist of three space separated integers $x$ $y$, where $x$ and $y$ denote the two nodes between which the directed edge $(x->y)$ exists.
**Constraints**
$2 \l... | Print a single line consisting either `YES` or `NO` according to the question. | 6 6
5 1
6 1
6 3
3 4
4 2
5 2 | NO | Hard | null | null | null | null | null | null | 2015-01-02T21:48:03 | 2016-05-12T23:56:58 | setter | '#'define pb push_back
using namespace std;
vector<'int'>adj[9000];
bool mat[9000][9000];
void dfs(int s,bool vis[],stack<'int'> &stk)
{
vis[s]=true;
for(int i=0;i<adj[s].size();i++)
{
int v=adj[s][i];
if(!vis[v])
{
dfs(v,vis,stk);
}
}
stk.push(s);
}
bool check(int n,int topo[])
{
for(... | not-set | 2016-04-24T02:03:24 | 2016-04-24T02:03:24 | C++ |
262 | 5,734 | knapres | Knapsack (Greedy) : Greedy Results | null | code | Exactly how greedy are you ! | ai | 2015-01-03T21:07:42 | 2016-09-09T10:03:26 | null | null | null | Take a look at the following video to understand greedy knapsack algorithm.
* The Knapsack problem is a pretty famous combinatorial problem which states the following
* Given a set of items, each with a mass and a value, find the number of each item to include in a collection so that the total weight is less than or ... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | First line consists of a single integer __T__, denoting the number of test cases.
First line of each test case, contains a single integer __N__, denoting the number of items.
The next two lines containing __N__ space separated integes each, where the first line deontes the weights of N items, and the second line deno... | For each test case, print a single lines containing two integer, first, an integer deonting the result of first strategy and second, an integer (integeral part of the floating point value), denoting answer to the second strategy. | 1
5
12 1 2 1 4
4 2 2 1 10
15 | 15 17 | Hard | null | null | null | null | null | null | 2015-01-03T23:16:05 | 2016-05-12T23:56:57 | setter | #include <iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct obj
{
int wt,v;
};
bool cmp(struct obj a,struct obj b)
{
double ratio1 = a.v*1.0 / a.wt;
double ratio2 = b.v*1.0 / b.wt;
if(ratio1 > ratio2)
return 1;
else
return 0;
}
int ... | not-set | 2016-04-24T02:03:24 | 2016-04-24T02:03:24 | C++ |
263 | 5,827 | compare-pairs | Compare pairs | null | code | null | ai | 2015-01-09T11:49:39 | 2016-09-09T10:03:57 | null | null | null | Count the number of Comparison in an array. A comparsion in an array is a pair of *indices(x,y)* such that **a[x] > a[y] and x < y**.
In this problem you are given 2 arrays C and D and you have to return number of such
pairs such that **c[x] > d[y] and x < y**. | 0.4 | ["c","cpp","java","cpp14"] | First line contains n denoting the total number of elements.The next line contains n
space separated integers of array C.This line is again followed by n space separated
integers of array D. | Print the total number of pairs according to comparison.
**Constraints:**
1<=n<=200000
1<=C[i]<=10<sup>6</sup>
1<=D[i]<=10<sup>6</sup> | 3
3 4 5
1 2 3 | 2 | Hard | null | null | null | null | null | null | 2015-01-09T12:32:04 | 2016-05-12T23:56:51 | setter |
<p>#include<bits/stdc++.h></p>
using namespace std;
long long tree[200005];
int A[200005];
int B[200005];
long long query(int idx)
{
long long res = 0;
while ( idx > 0 ) {
res += tree[idx];
idx -= (idx & (-idx));
}
return res;
}
void update(int idx) ... | not-set | 2016-04-24T02:03:25 | 2016-04-24T02:03:25 | C++ |
264 | 5,681 | zeroshark-and-magician | ZeroShark and Magician | null | code | ZeroShark meets magician!?! | ai | 2014-12-25T20:21:37 | 2019-07-02T13:59:26 | null | null | null | ZeroShark has $T$ numbers, $n_1, ..., n_T$, that he wants a magic trick to be performed on.
Wet Shark will take each of these numbers, and do magic tricks on them.
Wet Shark will perform the following magic trick: For an integer $x$, Wet Shark will replace this integer with a new integer $x_1$, randomly chosen from $... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | The first line contains an integer $T (1 \le T \le 100)$, representing the number of integers ZeroShark wants a magic trick to be performed on.
The next $T$ lines of the input contain integers $1 \le n_1, ..., n_T \le 3 \cdot 10^5$, representing the integers Wet Shark wants magic tricks performed on.
| Output $T$ lines, each containing the expected value of $i$ for each starting value $x = n_i$. Your answers will be considered correct if their absolute or relative error does not exceed $10^{-5}$.
| 2
2
3 | 1.5
1.8333333333333333 | Hard | null | null | null | null | null | null | 2015-01-10T04:04:15 | 2018-08-28T12:00:13 | setter | tcs = int(input())
tc = [int(input()) for _ in range(tcs)]
n = max(tc)
dp = [0] * (n + 1)
x = 0
sumx = 0
for i in range(1, n+1):
x = 1/i * sumx + 1
sumx += x
dp[i] = x
for i in tc:
print(dp[i])
| not-set | 2016-04-24T02:03:25 | 2016-04-24T02:03:25 | Unknown |
265 | 5,809 | mcmdp | Matrix Chain Multiplication (DP) : Just Short Of Optimal | null | code | Learn the optimal matrix chain multiplication using DP ! | ai | 2015-01-08T08:56:26 | 2016-09-09T10:03:51 | null | null | null | Given a sequence of __N__ matrices A[i], i=1 to N+1, multiply them so that the product of the matrices, in order, is unambiguous and needs __Just Short of Optimal__ number of scalar multiplication.
__Just Short of Optimal__ is defined as the __second most optimal__ number of scalar multiplications.
It is assured that... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14"] | First line contains an integer __T__
First line of each test case contains a single integer __N__ .
The next line contains __N+1__ space separated integers denoting the dimensions of matrices in the order specified above.
__Contraints:__
1<= T <=10
3<= N <= 150
1<= Dimensions of Matrices <= 60
| For each test case, print a single integer denoting the __Just Short of Optimal__ number of scalar multiplications involved for the given matrices. | 1
3
10 30 5 60
| 27000 | Hard | null | null | null | null | null | null | 2015-01-10T07:33:53 | 2016-05-12T23:56:50 | setter |
#include <iostream>
#include<limits.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int t,n,i,j,k,L;
cin>>t;
while(t--)
{
cin>>n;
int a[n+1];
for(i=0;i<=n;i++)
{
cin>>a[i];
}
int m[n+1][n+1];
for(i=1;i<=n;i++)
m[i][i]=0;
for (L=2; L<n; L++)
{
... | not-set | 2016-04-24T02:03:25 | 2016-04-24T02:03:25 | C++ |
266 | 5,847 | sprinklers | Sprinklers | null | code | Help John to set up sprinklers in the most efficient way | ai | 2015-01-11T06:45:24 | 2019-07-02T13:59:29 | null | null | null | Roses are planted in a row and numbered from $1$ to $N$.
The distance between two consecutive roses is $1$ meter.
John wants to automate the watering of these plants and wants to set up some sprinklers in the ground.
The cost for setting up each sprinkler is $S$ coins.
John chooses several roses behind which it is all... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","r","racket","rust","swift","cpp14"] | Hard | null | null | null | null | null | null | 2015-01-11T06:59:31 | 2017-01-17T18:50:12 | setter | #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 2000000001;
int greedySetup(int n, vector<int> & p, int expand)
{
int j = 0;
while (j + 1<p.size() && p[j + 1] - expand <= 1) ++j;
... | not-set | 2016-04-24T02:03:25 | 2016-04-24T02:03:25 | C++ | ||||
267 | 5,879 | calculate-the-medians | Calculate The Medians | null | code | null | ai | 2015-01-14T07:12:20 | 2019-07-02T13:59:30 | null | null | null | <sub>*Time limits* for this challenges is two times of the [default one](https://www.hackerrank.com/environment).</sub>
The math teacher loves the concept of median very much. One day, he comes up with a question about medians and wants the students to solve it.
He provides his students with two arrays of integers,
... | 0.5 | ["haskell","clojure","scala","erlang","sbcl","ocaml","racket","fsharp"] | The first line contains two integers, $n$ and $m$, indicating lengths of the two arrays $A$ and $B$, respectively.<br>
The second line contains $n$ integers, representing the array $A$.<br>
The third line contains $m$ integers, representing the array $B$.<br>
The fourth line contains an integer $k$, indicating the numb... | For each query, output the answer in a single line.
**Constraints**
- $1 \le n, m \le 50000$
- $1 \le a_i, b_j \le 10^9\ , i \in [1, n], j \in [1, m]$
- $1 \le k \le 20000$
- $1 \le x \le y \le n$
- $1 \le z \le w \le m$
- The absolute error between your and expected output should not exceed $10^{-6}$. | 5 6
4 3 9 7 8
1 8 3 6 5 2
4
1 5 1 6
1 1 2 4
1 2 3 4
3 5 4 6 | 5.0
5.0
3.5
6.5 | Hard | null | null | null | null | null | null | 2015-01-14T07:13:52 | 2016-12-27T13:25:38 | setter | **Solution with partition trees**
import Control.Applicative
import Control.Monad
import Data.Int
import Data.List
import qualified Data.Vector as V
import Text.Printf
data Tree = Node (V.Vector Int32) Tree Tree
| Leaf Int32
type Struct = (Tree, V.Vector Int32)
buildStruct :: [Int32] -> Struc... | not-set | 2016-04-24T02:03:25 | 2016-04-24T02:03:25 | Python |
268 | 5,879 | calculate-the-medians | Calculate The Medians | null | code | null | ai | 2015-01-14T07:12:20 | 2019-07-02T13:59:30 | null | null | null | <sub>*Time limits* for this challenges is two times of the [default one](https://www.hackerrank.com/environment).</sub>
The math teacher loves the concept of median very much. One day, he comes up with a question about medians and wants the students to solve it.
He provides his students with two arrays of integers,
... | 0.5 | ["haskell","clojure","scala","erlang","sbcl","ocaml","racket","fsharp"] | The first line contains two integers, $n$ and $m$, indicating lengths of the two arrays $A$ and $B$, respectively.<br>
The second line contains $n$ integers, representing the array $A$.<br>
The third line contains $m$ integers, representing the array $B$.<br>
The fourth line contains an integer $k$, indicating the numb... | For each query, output the answer in a single line.
**Constraints**
- $1 \le n, m \le 50000$
- $1 \le a_i, b_j \le 10^9\ , i \in [1, n], j \in [1, m]$
- $1 \le k \le 20000$
- $1 \le x \le y \le n$
- $1 \le z \le w \le m$
- The absolute error between your and expected output should not exceed $10^{-6}$. | 5 6
4 3 9 7 8
1 8 3 6 5 2
4
1 5 1 6
1 1 2 4
1 2 3 4
3 5 4 6 | 5.0
5.0
3.5
6.5 | Hard | null | null | null | null | null | null | 2015-01-14T07:13:52 | 2016-12-27T13:25:38 | tester | import scala.collection.mutable.TreeSet
/**
* Created by Bo You (stoundmire) on 2015/3/4.
*/
object Solution {
def combine(a: Array[Int], b: Array[Int]): Array[Int] = {
val s = new TreeSet[Int]()
for (x <- a) {
s.add(x)
}
for (x <- b) {
... | not-set | 2016-04-24T02:03:25 | 2016-04-24T02:03:25 | Python |
269 | 5,951 | audit-sale | Audit Sale | null | code | Calculate your maximum expected sale price. | ai | 2015-01-19T21:40:20 | 2019-07-02T13:59:31 | null | null | null | After carefully auditing your portfolio, you notice you have $N$ securities left over from previous trades. You have only one unit of each of these $N$ securities, and you want to sell *at most* $M$ of these to avoid extra accounting.
As an experienced portfolio manager, you rely on your previous body of work to predi... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","go","javascript","erlang","sbcl","d","ocaml","pascal","python3","groovy","objectivec","fsharp","visualbasic","lolcode","smalltalk","tcl","java8","r","racket","rust","swift","cpp14","pypy","pypy3"] | The first line contains three space-separated integers: $N$ (the number of lone securities you have), $M$ (the maximum number of securities you wish to sell), and $K$ (the minimum number of securities you can definitely sell), respectively.
Each line $i$ of the $N$ subsequent lines contains two space-separated integer... | Print a single integer denoting the maximum amount of money expected from $M$ sales, multiplied by $100$. | 3 2 1
5 10
6 60
8 40 | 1160 | Hard | null | null | null | null | null | null | 2015-01-19T21:44:31 | 2016-12-17T11:23:04 | setter | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100010;
int n, m, k;
vector<pair<int, pair<int, int> > > v;
int hSum[N], hpSum[N];
//hSum[i] stores sum of mamimum K pricw values till i
//hpSum[i] stores sum of maximum (M - K) price * probability val... | not-set | 2016-04-24T02:03:27 | 2016-06-13T12:53:53 | C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.