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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 337 | randomsumexpected | Random Sum - Expected Sum | Given an a list D of N integers, and an integer T, two numbers L and R are randomly chosen such that 0 ≤ L ≤ R < N.
What is the expected sum of the subarray {d[L]...d[R]} given that (sum{d[L],...d[R]} <= T)?
**Input Format:**
The first line will contain two numbers: N and T. N lines follow, each containing one numbe... | code | What is the expected sum of a randomly chosen range of numbers? | ai | 2013-01-29T20:58:30 | 2016-09-09T09:28:39 | null | null | null | Given an a list D of N integers, and an integer T, two numbers L and R are randomly chosen such that 0 ≤ L ≤ R < N.
What is the expected sum of the subarray {d[L]...d[R]} given that (sum{d[L],...d[R]} <= T)?
**Input Format:**
The first line will contain two numbers: N and T. N lines follow, each containing one numbe... | 0.495261 | ["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 | Random Sum - Expected Sum Solution by <a href ="https://www.hackerrank.com/sidsgr88">Siddharth Bora</a> | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | randexpsum | 2013-03-04T16:26:12 | {"contest_participation":6014,"challenge_submissions":421,"successful_submissions":210} | 2013-03-04T16:26:12 | 2016-05-13T00:04:48 | tester | using namespace std;
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <algo... | not-set | 2016-04-24T02:02:11 | 2016-04-24T02:02:11 | C++ |
1 | 556 | n-puzzle | N Puzzle | N Puzzle is a sliding blocks game that takes place on a k * k grid with ((k * k) - 1) tiles each numbered from 1 to N. Your task is to reposition the tiles to their proper order.
**Input Format**
The first line of the input contains an integer k, the size of the square grid. k * k lines follow each line containing an... | game | N Puzzle is a sliding blocks game that takes place on a k * k grid with (k * k) - 1 tiles each numbered from 1 to N. Place the tiles in their proper order using minimum number of moves. | ai | 2013-04-06T14:13:29 | 2022-08-31T18:04:25 | null | null | null | N Puzzle is a sliding blocks game that takes place on a k * k grid with ((k * k) - 1) tiles each numbered from 1 to N. Your task is to reposition the tiles to their proper order.
**Input Format**
The first line of the input contains an integer k, the size of the square grid. k * k lines follow each line containing an... | 0.456522 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","tcl","typescript","visualbasic","kotlin","p... | null | null | null | null | Hard | May 20-20 Hack Editorial: N - Puzzle | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | may-2020-editorial-npuzzle | 2013-06-10T13:14:35 | {"contest_participation":3663,"challenge_submissions":135,"successful_submissions":0} | 2013-06-10T13:14:35 | 2016-05-13T00:04:45 | setter | #include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#define INRANGE(i, a, b) (i >= a && i < b)
using namespace std;
class SlidingBlock
{
public:
vector < int > disc;
int n;
int cost;
... | not-set | 2016-04-24T02:02:11 | 2016-04-24T02:02:11 | C++ |
2 | 746 | game-of-throne-ii | Game Of Thrones - II | This follows from [Game of Thrones - I](https://www.hackerrank.com/contests/july13/challenges/game-of-thrones).
Now that the king knows how to find out whether a given word has an [anagram](https://en.wikipedia.org/wiki/Anagram) which is a [palindrome](http://en.wikipedia.org/wiki/Palindrome) or not, he encounters ano... | code | Can you help the king find the number of ways his door can be unlocked? | ai | 2013-07-02T17:07:43 | 2022-09-02T09:54:54 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts STRING s as parameter.
#
def solve(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')
s = input()
result = solve(s)
fptr.write(str(result) + '\n')
fptr.close()
| This follows from [Game of Thrones - I](https://www.hackerrank.com/contests/july13/challenges/game-of-thrones).
Now that the king knows how to find out whether a given word has an [anagram](https://en.wikipedia.org/wiki/Anagram) which is a [palindrome](http://en.wikipedia.org/wiki/Palindrome) or not, he encounters ano... | 0.501678 | ["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 | 20/20 Hack July Editorial: Game of Thrones - 2 | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | july-2020-editorial-game-of-thrones-ii | 2013-07-22T04:35:37 | {"contest_participation":4325,"challenge_submissions":1181,"successful_submissions":695} | 2013-07-22T04:35:37 | 2016-12-02T19:33:05 | setter | ###Python 2
```python
#!/usr/bin/py
from collections import Counter
mod = 10**9 + 7
def hasPalindrome(word):
x = Counter(word)
count = 0
for i in x:
if x[i]%2!=0:
count += 1
if count > 1:
return False
else:
return True
def getfactmod(b):
... | not-set | 2016-04-24T02:02:12 | 2016-07-23T18:36:16 | Python |
3 | 746 | game-of-throne-ii | Game Of Thrones - II | This follows from [Game of Thrones - I](https://www.hackerrank.com/contests/july13/challenges/game-of-thrones).
Now that the king knows how to find out whether a given word has an [anagram](https://en.wikipedia.org/wiki/Anagram) which is a [palindrome](http://en.wikipedia.org/wiki/Palindrome) or not, he encounters ano... | code | Can you help the king find the number of ways his door can be unlocked? | ai | 2013-07-02T17:07:43 | 2022-09-02T09:54:54 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts STRING s as parameter.
#
def solve(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')
s = input()
result = solve(s)
fptr.write(str(result) + '\n')
fptr.close()
| This follows from [Game of Thrones - I](https://www.hackerrank.com/contests/july13/challenges/game-of-thrones).
Now that the king knows how to find out whether a given word has an [anagram](https://en.wikipedia.org/wiki/Anagram) which is a [palindrome](http://en.wikipedia.org/wiki/Palindrome) or not, he encounters ano... | 0.501678 | ["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 | 20/20 Hack July Editorial: Game of Thrones - 2 | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | july-2020-editorial-game-of-thrones-ii | 2013-07-22T04:35:37 | {"contest_participation":4325,"challenge_submissions":1181,"successful_submissions":695} | 2013-07-22T04:35:37 | 2016-12-02T19:33:05 | tester | ###C++
```cpp
#include <cstdio>
#include <cstring>
#include <bits/stdc++.h>
using namespace std;
int t;
const long long mod = 1000000007;
long long pow(long long osn){
long long res = 1, tmp = osn;
int m = int(mod - 2);
while(m){
if(m % 2){
res = (res * tmp) % mod;
... | not-set | 2016-04-24T02:02:12 | 2016-07-23T18:36:38 | C++ |
4 | 791 | kth-ancestor | Kth Ancestor | A tree of P nodes is an un-directed connected graph having P-1 edges. Let us denote R as the root node. If A is a node such that it is at a distance of L from R, and B is a node such that it is at at distance of L+1 from
R and A is connected to B, then we call A as the parent of B.
Similarly, if A is at a distance o... | code | Figure out the K-th parent of a node at any instant. | ai | 2013-08-01T18:06:31 | 2022-08-31T08:14:29 | null | null | null | A tree of $P$ nodes is an un-directed connected graph having $P-1$ edges. Let us denote $R$ as the root node. If $A$ is a node such that it is at a distance of $L$ from $R$, and $B$ is a node such that it is at at distance of $L+1$ from
$R$ and $A$ is connected to $B$, then we call $A$ as the parent of $B$.
Similarl... | 0.435294 | ["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 contain an integer $T$ denoting the number of test cases. $T$ test cases follow. First line of each test case contains an integer $P$, the number of nodes in the tree.
$P$ lines follows each containing two integers $X$ and $Y$ separated by a single space denoting $Y$ as the parent of $X$. If $Y$ is $0$, ... | For each query of type $2$, output the $K$<sup>th</sup> parent of $X$. If $K$<sup>th</sup> parent doesn't exist, output $0$ and if the node doesn't exist, output $0$.
| 2
7
2 0
5 2
3 5
7 5
9 8
8 2
6 8
10
0 5 15
2 15 2
1 3
0 15 20
0 20 13
2 13 4
2 13 3
2 6 10
2 11 1
2 9 1
1
10000 0
3
0 10000 4
1 4
2 4 1
| 2
2
5
0
0
8
0
| Hard | Kth Parent : August 2020 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | aug-2020-editorial-kth-parent | 2013-08-13T08:25:00 | {"contest_participation":3656,"challenge_submissions":458,"successful_submissions":180} | 2013-08-13T08:25:00 | 2016-12-02T15:06:47 | setter | ###C++
```cpp
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <algorithm>
#include <cassert>
using namespace std;
#define INF 2147483... | not-set | 2016-04-24T02:02:12 | 2016-07-23T13:56:04 | C++ |
5 | 803 | help-mike | Help Mike | Harvey Specter has agreed to take Mike Ross to a meeting filled with brilliant scientists at NSA Headquarters. But, as always, it's not going to be easy for Mike. He has to solve a puzzle given by Harvey.
Harvey gives two numbers N and K and defines a set A.<br>
*A = { x : x is a [natural number](https://en.wikipedi... | code | Help Mike attend the NSA meeting | ai | 2013-08-13T09:29:32 | 2022-09-02T09:54:27 | #
# Complete the 'solve' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER k
#
def solve(n, k):
# 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])
k = int(first_multiple_input[1])
result = solve(n, k)
fptr.wri... | Harvey Specter has agreed to take Mike Ross to a meeting filled with brilliant scientists at NSA Headquarters. But, as always, it's not going to be easy for Mike. He has to solve a puzzle given by Harvey.
Harvey gives two numbers N and K and defines a set A.<br>
*A = { x : x is a [natural number](https://en.wikipedi... | 0.579365 | ["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 | Help Mike - Sept 2020 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | sep-2020-editorial-help-mike | 2013-09-16T13:48:37 | {"contest_participation":3240,"challenge_submissions":1167,"successful_submissions":494} | 2013-09-16T13:48:37 | 2016-12-03T12:59:31 | setter | ###C++
```cpp
#include<bits/stdc++.h>
using namespace std;
#define print(p) cout<<p<<endl;
int main()
{
int T;
long long int N,K,i;
cin>>T;
while(T--)
{
cin>>N>>K;
long long int arr[K];
arr[0] = N/K;
for(i=1 ; i< K ; i++)
arr[i] = (int)(... | not-set | 2016-04-24T02:02:13 | 2016-07-23T17:46:38 | C++ |
6 | 803 | help-mike | Help Mike | Harvey Specter has agreed to take Mike Ross to a meeting filled with brilliant scientists at NSA Headquarters. But, as always, it's not going to be easy for Mike. He has to solve a puzzle given by Harvey.
Harvey gives two numbers N and K and defines a set A.<br>
*A = { x : x is a [natural number](https://en.wikipedi... | code | Help Mike attend the NSA meeting | ai | 2013-08-13T09:29:32 | 2022-09-02T09:54:27 | #
# Complete the 'solve' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER k
#
def solve(n, k):
# 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])
k = int(first_multiple_input[1])
result = solve(n, k)
fptr.wri... | Harvey Specter has agreed to take Mike Ross to a meeting filled with brilliant scientists at NSA Headquarters. But, as always, it's not going to be easy for Mike. He has to solve a puzzle given by Harvey.
Harvey gives two numbers N and K and defines a set A.<br>
*A = { x : x is a [natural number](https://en.wikipedi... | 0.579365 | ["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 | Help Mike - Sept 2020 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | sep-2020-editorial-help-mike | 2013-09-16T13:48:37 | {"contest_participation":3240,"challenge_submissions":1167,"successful_submissions":494} | 2013-09-16T13:48:37 | 2016-12-03T12:59:31 | tester | ###Python 2
```python
#!/usr/bin/py
import math
T = input()
1 <= T <= 100
for t in range(T):
N, K = map(int, raw_input().strip().split(" "))
assert 1 <= N <= 10**9
assert 1 <= K <= 10**4
assert K <= N
n_by_k = math.floor(N/K)
n_mod_k = N%K
count_less_than_k = K/2 if K % 2 ... | not-set | 2016-04-24T02:02:13 | 2016-07-23T17:46:49 | Python |
7 | 800 | chocolate-game | Chocolate Game | Laurel and Hardy have N piles of chocolates with each pile containing some number of chocolates. The piles are arranged from left to right in a non decreasing order based on the number of chocolates in each pile. They play the following game.
For every continuous subsequence of chocolate piles (at least 2 piles form ... | code | Count continuous sub-sequences for winning Chocolate Game. | ai | 2013-08-09T20:02:16 | 2022-08-31T08:15:06 | #
# Complete the 'chocolateGame' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY arr as parameter.
#
def chocolateGame(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')
arr_count = int(input().strip())
arr = list(map(int, input().rstrip().split()))
result = chocolateGame(arr)
fptr.write(str(result) + '\n')
fptr.close()
| Laurel and Hardy have $n$ piles of chocolates with each pile containing some number of chocolates. The piles are arranged from left to right in a non decreasing order based on the number of chocolates in each pile. They play the following game.
For every continuous subsequence of chocolate piles (at least 2 piles for... | 0.487805 | ["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 an integer $n$ denoting the number of piles.
The second line contains the number of chocolates in each pile, arranged from left to right and separated by a single space between them.
| A single integer denoting the number of continuous subsequences of chocolate piles in which Laurel will win.
| 5
1 1 2 2 3
| 5
| Hard | 2020 September Editorial: Chocolate Game | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | chocolate-game | 2013-09-24T09:33:08 | {"contest_participation":3240,"challenge_submissions":230,"successful_submissions":51} | 2013-09-24T09:33:08 | 2016-07-23T16:18:17 | setter | ###C++
```cpp
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <vector>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <iostream>
#in... | not-set | 2016-04-24T02:02:13 | 2016-07-23T16:18:18 | C++ |
8 | 836 | sherlock-puzzle | Sherlock Puzzle | Sherlock Holmes is bored to death as there aren't any interesting cases to solve. Dr Watson finding it impossible to be around Sherlock goes out to get some fresh air. Just as he lays his feet out of the door, he is thrown right back into his house by the explosion in front of his apartment. The metropolitan police arr... | code | Help Sherlock get close to his Arch Nemesis, Jim Moriarty. | ai | 2013-08-24T15:49:01 | 2022-09-02T09:54:36 | null | null | null | Sherlock Holmes is bored to death as there aren't any interesting cases to solve. Dr Watson finding it impossible to be around Sherlock goes out to get some fresh air. Just as he lays his feet out of the door, he is thrown right back into his house by the explosion in front of his apartment. The metropolitan police arr... | 0.567568 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | null | null | null | null | Hard | 2020 September Editorial: Sherlock Puzzle | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | sep2020-sherlock-puzzle | 2013-09-24T09:42:06 | {"contest_participation":3240,"challenge_submissions":292,"successful_submissions":72} | 2013-09-24T09:42:06 | 2016-07-23T17:59:56 | setter | ###C++
```cpp
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <vector>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <iostream>
#in... | not-set | 2016-04-24T02:02:13 | 2016-07-23T17:59:56 | C++ |
9 | 1,049 | angry-children-2 | Angry Children 2 | Bill Gates is on one of his philanthropic journeys to a village in Utopia. He has **N** packets of candies and would like to distribute one packet to each of the **K** children in the village (each packet may contain different number of candies). To avoid a fight between the children, he would like to pick **K** out o... | code | Select K elements from N elements such that the sum absolute value of differences of adjacent elements is minimized | ai | 2013-10-08T12:22:10 | 2022-08-31T08:14:42 | #
# Complete the 'angryChildren' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER k
# 2. INTEGER_ARRAY packets
#
def angryChildren(k, packets):
# 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())
k = int(input().strip())
packets = []
for _ in range(n):
packets_item = int(input().strip())
packets.append(packets_item)
result = angryChildren(k, packets)
fptr.write(str(re... | Bill Gates is on one of his philanthropic journeys to a village in Utopia. He has brought a box of packets of candies and would like to distribute one packet to each of the children. Each of the packets contains a number of candies. He wants to minimize the cumulative difference in the number of candies in the packet... | 0.532895 | ["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 an integer $n$.
The second line contains an integer $k$.
Each of the next $n$ lines contains an integer $packets[i]$.
| A single integer representing the minimum achievable unfairness sum.
**Sample Input 0**
7
3
10
100
300
200
1000
20
30
**Sample Output 0**
40
**Explanation 0**
Bill Gates will choose packets having 10, 20 and 30 candies. The unfairness sum is $|10-20| + |20-30| + |10-30| = 40... | Hard | Angry Children 2 : Oct 2020 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | oct-2020-angry-children-ii | 2013-10-29T06:01:32 | {"contest_participation":7868,"challenge_submissions":2266,"successful_submissions":1120} | 2013-10-29T06:01:32 | 2018-05-14T17:07:47 | setter | ###Python 2
```python
n = input()
k = input()
assert 1 <= n <= 10**5
assert 1 <= k <= n
lis = []
for i in range(n):
lis.append(input())
lis.sort()
sum_lis = []
for i in lis:
assert 0 <= i <= 10**9
val = 1-k
answer = 0
sum_lis.append(lis[0])
for i in range(1,n):
sum_lis.append(su... | not-set | 2016-04-24T02:02:13 | 2016-07-23T14:51:01 | Python | ||
10 | 1,049 | angry-children-2 | Angry Children 2 | Bill Gates is on one of his philanthropic journeys to a village in Utopia. He has **N** packets of candies and would like to distribute one packet to each of the **K** children in the village (each packet may contain different number of candies). To avoid a fight between the children, he would like to pick **K** out o... | code | Select K elements from N elements such that the sum absolute value of differences of adjacent elements is minimized | ai | 2013-10-08T12:22:10 | 2022-08-31T08:14:42 | #
# Complete the 'angryChildren' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER k
# 2. INTEGER_ARRAY packets
#
def angryChildren(k, packets):
# 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())
k = int(input().strip())
packets = []
for _ in range(n):
packets_item = int(input().strip())
packets.append(packets_item)
result = angryChildren(k, packets)
fptr.write(str(re... | Bill Gates is on one of his philanthropic journeys to a village in Utopia. He has brought a box of packets of candies and would like to distribute one packet to each of the children. Each of the packets contains a number of candies. He wants to minimize the cumulative difference in the number of candies in the packet... | 0.532895 | ["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 an integer $n$.
The second line contains an integer $k$.
Each of the next $n$ lines contains an integer $packets[i]$.
| A single integer representing the minimum achievable unfairness sum.
**Sample Input 0**
7
3
10
100
300
200
1000
20
30
**Sample Output 0**
40
**Explanation 0**
Bill Gates will choose packets having 10, 20 and 30 candies. The unfairness sum is $|10-20| + |20-30| + |10-30| = 40... | Hard | Angry Children 2 : Oct 2020 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | oct-2020-angry-children-ii | 2013-10-29T06:01:32 | {"contest_participation":7868,"challenge_submissions":2266,"successful_submissions":1120} | 2013-10-29T06:01:32 | 2018-05-14T17:07:47 | tester | ###C++
```cpp
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<assert.h>
using namespace std;
#define Max_N 100001
typedef long long int ll;
long long int sum[Max_N];
int N,K,input[Max_N];
ll min(ll a,ll b)
{
if(a>b) return b;
else return a;
}
int main()
{
int val;
scanf("%d%d",&... | not-set | 2016-04-24T02:02:13 | 2016-07-23T14:51:25 | C++ | ||
11 | 1,084 | period | Period | You are given 2 integers **a** and **b**. Let a number be defined as . As we know  will be an irrational number when b is non-zero. In this problem, we call it the AC number. We define
. As we know  will be an irrational number when b is non-zero. In this problem, we call ... | 0.564516 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | Hard | Period : Oct 2020 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | oct-2020-editorial-period | 2013-10-29T06:13:09 | {"contest_participation":7868,"challenge_submissions":564,"successful_submissions":106} | 2013-10-29T06:13:09 | 2016-07-23T18:18:41 | setter | ###C++
```cpp
#include<iostream>
#include<queue>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<stack>
#include<cstring>
#include<map>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define pb push_back
#define mp make_pair
bool isPri... | not-set | 2016-04-24T02:02:13 | 2016-07-23T18:18:32 | C++ | ||||
12 | 1,084 | period | Period | You are given 2 integers **a** and **b**. Let a number be defined as . As we know  will be an irrational number when b is non-zero. In this problem, we call it the AC number. We define
. As we know  will be an irrational number when b is non-zero. In this problem, we call ... | 0.564516 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | Hard | Period : Oct 2020 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | oct-2020-editorial-period | 2013-10-29T06:13:09 | {"contest_participation":7868,"challenge_submissions":564,"successful_submissions":106} | 2013-10-29T06:13:09 | 2016-07-23T18:18:41 | tester | ###C++
```cpp
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int mul(ll x,ll y,int p) {
return x * y % p;
}
int powermod(ll x,ll y,int p) { //x ^ y mod p
if (x == 0) {
return 0;
}
if (y ... | not-set | 2016-04-24T02:02:13 | 2016-07-23T18:18:41 | C++ | ||||
13 | 1,090 | missile-defend | HackerX | **Update:** A slight modification in the problem statement (see below)
Evil Nation A is angry and plans to launch **N** guided-missiles at the peaceful Nation B in an attempt to wipe out all of Nation B's people. Nation A's missile _i_ will arrive in nation B at time t<sub>i</sub>. Missile _i_ communicates with its ... | code | Find the minimum number of hackerX missiles you must launch to keep Nation B safe. | ai | 2013-10-16T17:50:34 | 2022-08-31T08:14:32 | #
# Complete the 'missileDefend' function below.
#
# The function is expected to return an INTEGER.
# The function accepts 2D_INTEGER_ARRAY missiles as parameter.
#
def missileDefend(missiles):
# 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())
missiles = []
for _ in range(n):
missiles.append(list(map(int, input().rstrip().split())))
result = missileDefend(missiles)
fptr.write(str(result) + '\n')
fptr.close()
| **Update:** A slight modification in the problem statement (see below)
Evil Nation A is angry and plans to launch **N** guided-missiles at the peaceful Nation B in an attempt to wipe out all of Nation B's people. Nation A's missile _i_ will arrive in nation B at time t<sub>i</sub>. Missile _i_ communicates with its ... | 0.538462 | ["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"] | null | null | null | null | Hard | hackerX : Oct 20/20 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | oct-2020-editorial-hackerx | 2013-10-30T05:56:08 | {"contest_participation":7868,"challenge_submissions":955,"successful_submissions":110} | 2013-10-30T05:56:08 | 2016-07-23T14:05:03 | setter | ###C++
```cpp
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <vector>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <numeric>
#include <iomanip>
#include <sstream>
#in... | not-set | 2016-04-24T02:02:13 | 2016-07-23T14:04:43 | C++ |
14 | 1,090 | missile-defend | HackerX | **Update:** A slight modification in the problem statement (see below)
Evil Nation A is angry and plans to launch **N** guided-missiles at the peaceful Nation B in an attempt to wipe out all of Nation B's people. Nation A's missile _i_ will arrive in nation B at time t<sub>i</sub>. Missile _i_ communicates with its ... | code | Find the minimum number of hackerX missiles you must launch to keep Nation B safe. | ai | 2013-10-16T17:50:34 | 2022-08-31T08:14:32 | #
# Complete the 'missileDefend' function below.
#
# The function is expected to return an INTEGER.
# The function accepts 2D_INTEGER_ARRAY missiles as parameter.
#
def missileDefend(missiles):
# 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())
missiles = []
for _ in range(n):
missiles.append(list(map(int, input().rstrip().split())))
result = missileDefend(missiles)
fptr.write(str(result) + '\n')
fptr.close()
| **Update:** A slight modification in the problem statement (see below)
Evil Nation A is angry and plans to launch **N** guided-missiles at the peaceful Nation B in an attempt to wipe out all of Nation B's people. Nation A's missile _i_ will arrive in nation B at time t<sub>i</sub>. Missile _i_ communicates with its ... | 0.538462 | ["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"] | null | null | null | null | Hard | hackerX : Oct 20/20 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | oct-2020-editorial-hackerx | 2013-10-30T05:56:08 | {"contest_participation":7868,"challenge_submissions":955,"successful_submissions":110} | 2013-10-30T05:56:08 | 2016-07-23T14:05:03 | tester | ###C++
```cpp
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
pair<int,int> a[100005];
set<int> have;
int main() {
int n;
scanf("%d",&n);
for (int i = 0; i < n; ++i) {
int x,y;
scanf("%d%d",&x,&y);
a[i] = make_pair(x + y,x - y);
}
s... | not-set | 2016-04-24T02:02:13 | 2016-07-23T14:05:04 | C++ |
15 | 1,042 | flip | Find The Operations | You are given a square grid of size N, with rows numbered from 0 to N - 1 starting from the top and columns numbered from 0 to N - 1 starting from the left.
A cell (u, v) refers to the cell that is on the u<sup>th</sup> row and the v<sup>th</sup> column. Each cell contains an integer - 0 or 1. You can pick any cell... | code | Let's try to modify a 0-1 grid. | ai | 2013-10-07T10:39:47 | 2022-09-02T09:54:42 | null | null | null | You are given a square grid of size N, with rows numbered from 0 to N - 1 starting from the top and columns numbered from 0 to N - 1 starting from the left.
A cell (u, v) refers to the cell that is on the u<sup>th</sup> row and the v<sup>th</sup> column. Each cell contains an integer - 0 or 1. You can pick any cell... | 0.5 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | null | null | null | null | Hard | Find The Operations : Nov 20/20 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | nov-2020-editorial-find-the-operations | 2013-11-27T06:59:25 | {"contest_participation":3343,"challenge_submissions":160,"successful_submissions":76} | 2013-11-27T06:59:25 | 2016-12-08T11:34:28 | setter | ###C++
```cpp
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <memory.h>
#include <sstream>
#include <complex>
#include <cassert>
#defin... | not-set | 2016-04-24T02:02:14 | 2016-07-23T18:03:16 | C++ |
16 | 1,042 | flip | Find The Operations | You are given a square grid of size N, with rows numbered from 0 to N - 1 starting from the top and columns numbered from 0 to N - 1 starting from the left.
A cell (u, v) refers to the cell that is on the u<sup>th</sup> row and the v<sup>th</sup> column. Each cell contains an integer - 0 or 1. You can pick any cell... | code | Let's try to modify a 0-1 grid. | ai | 2013-10-07T10:39:47 | 2022-09-02T09:54:42 | null | null | null | You are given a square grid of size N, with rows numbered from 0 to N - 1 starting from the top and columns numbered from 0 to N - 1 starting from the left.
A cell (u, v) refers to the cell that is on the u<sup>th</sup> row and the v<sup>th</sup> column. Each cell contains an integer - 0 or 1. You can pick any cell... | 0.5 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | null | null | null | null | Hard | Find The Operations : Nov 20/20 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | nov-2020-editorial-find-the-operations | 2013-11-27T06:59:25 | {"contest_participation":3343,"challenge_submissions":160,"successful_submissions":76} | 2013-11-27T06:59:25 | 2016-12-08T11:34:28 | tester | ###C++
```cpp
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 402;
int a[N][N],b[N];
vector<int> result;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n, d,i,j,k;
... | not-set | 2016-04-24T02:02:14 | 2016-07-23T18:04:21 | C++ |
17 | 779 | oil-well | Oil Well | Mr. Road Runner bought a piece of land in the middle of a desert for a nominal amount. It turns out that the piece of land is now worth millions of dollars as it has an oil reserve under it. Mr. Road Runner contacts the ACME corp to set up the oil wells on his land. Setting up oil wells is a costly affair and the charg... | code | Given RxC matrix with 0/1. Rearrange the cells having 1 so that the manhattan disctance sum of adjacent cells in this list is minimal. Fidn the sum | ai | 2013-07-25T18:13:47 | 2022-08-31T08:14:52 | #
# Complete the 'oilWell' function below.
#
# The function is expected to return an INTEGER.
# The function accepts 2D_INTEGER_ARRAY blocks as parameter.
#
def oilWell(blocks):
# 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')
first_multiple_input = input().rstrip().split()
r = int(first_multiple_input[0])
c = int(first_multiple_input[1])
blocks = []
for _ in range(r):
blocks.append(list(map(int, input().rstrip().split())))
result... | Mr. Road Runner bought a piece of land in the middle of a desert for a nominal amount. It turns out that the piece of land is now worth millions of dollars as it has an oil reserve under it. Mr. Road Runner contacts the ACME corp to set up the oil wells on his land. Setting up oil wells is a costly affair and the charg... | 0.547945 | ["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 of the input contains two space separated integers *r* *c*.
*r* lines follow each containing *c* space separated integers.
1 indicates that the block is suitable for setting up an oil well, whereas 0 isn't.
r c
M11 M12 ... M1c
M21 M22 ... M2c
...
Mr1 Mr2 ... Mrc
| Print the minimum value E as the answer.
| 3 4
1 0 0 0
1 0 0 0
0 0 1 0
| 3
| Hard | November 2020 Editorial: Oil Well | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | nov2020-oil-well | 2013-11-27T09:48:45 | {"contest_participation":3343,"challenge_submissions":405,"successful_submissions":60} | 2013-11-27T09:48:45 | 2016-07-23T15:04:07 | setter | ###C++
```cpp
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1000000000;
const int N = 52;
int dp[N][N][N][N], a[N][N];
int ab(int x) {
return (x > 0)?x:(-x);
}
int dis(int x1,int y1,int x2,int y2) {
return ma... | not-set | 2016-04-24T02:02:14 | 2016-07-23T15:04:07 | C++ |
18 | 625 | random | Random | Given an array 'D' with n elements: d[0], d[1], ..., d[n-1], you can perform the following two steps on the array.
1. Randomly choose two indexes (l, r) with l < r, swap (d[l], d[r])
2. Randomly choose two indexes (l, r) with l < r, reverse (d[l...r]) (both inclusive)
After you perform the first operation **a... | code | Expected value of a random sub array? | ai | 2013-04-26T18:31:55 | 2022-09-02T09:55:42 | null | null | null | Given an array 'D' with n elements: d[0], d[1], ..., d[n-1], you can perform the following two steps on the array.
1. Randomly choose two indexes (l, r) with l < r, swap (d[l], d[r])
2. Randomly choose two indexes (l, r) with l < r, reverse (d[l...r]) (both inclusive)
After you perform the first operation **a... | 0.422619 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | Hard | November 2020 Editorial - Random | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | nov2020-random | 2013-11-27T11:19:54 | {"contest_participation":3343,"challenge_submissions":129,"successful_submissions":52} | 2013-11-27T11:19:54 | 2016-07-23T19:18:26 | setter | ###C++
```cpp
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <bitset>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <sstream>
#inc... | not-set | 2016-04-24T02:02:14 | 2016-07-23T19:18:26 | C++ | ||||
19 | 1,574 | hacker-country | Hacker Country | There are *N* cities in the Hacker Country. There is a unique directed road connecting each pair of different cities directly. However, each road has its own cost which you must pay for passing it each time. You are planning to visit the country. Here are the conditions to be satisfied:
+ You can start at any city y... | code | What is the minimum cost of a road trip in Hacker Country? | ai | 2013-12-20T08:10:24 | 2022-08-31T08:14:32 | #
# Complete the 'hackerCountry' function below.
#
# The function is expected to return a STRING.
# The function accepts 2D_INTEGER_ARRAY tolls as parameter.
#
def hackerCountry(tolls):
# 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())
tolls = []
for _ in range(n):
tolls.append(list(map(int, input().rstrip().split())))
result = hackerCountry(tolls)
fptr.write(result + '\n')
fptr.close()
| There are *N* cities in *Hacker Country*. Each pair of cities are directly connected by a unique directed road, and each road has its own toll that must be paid every time it is used. You're planning a road trip in *Hacker Country*, and its itinerary must satisfy the following conditions:
+ You can start in any city... | 0.533333 | ["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 is an integer, $N$ (number of cities).
The $N$ subsequent lines of $N$ space-separated integers each describe the respective tolls or traveling from city $i$ to city $j$; in other words, the $j^{th}$ integer of the $i^{th}$ line denotes the toll for traveling from city $i$ to city $j$.
**Note:** As... | Print the *minimum cost* as a rational number $p \ / \ q$ (tolls paid over roads traveled). The *greatest common divisor* of $p$ and $q$ should be $1$. | 2
0 1
2 0 | 3/2 | Hard | Hacker Country : Codesprint 5 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | codesprint5-hacker-country | 2014-01-21T11:07:30 | {"contest_participation":12558,"challenge_submissions":482,"successful_submissions":103} | 2014-01-21T11:07:30 | 2016-07-23T14:03:54 | setter | ###C++
```cpp
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
using namespace std;
const int N = 505;
int d[N][N],a[N][N];
int cmp(const pair<int,int> &a,const pair<int,int> &b) { // a - b
return a.first * b.second - a.second * b.first;
}
int gcd(int a... | not-set | 2016-04-24T02:02:15 | 2016-07-23T14:03:41 | C++ |
20 | 1,574 | hacker-country | Hacker Country | There are *N* cities in the Hacker Country. There is a unique directed road connecting each pair of different cities directly. However, each road has its own cost which you must pay for passing it each time. You are planning to visit the country. Here are the conditions to be satisfied:
+ You can start at any city y... | code | What is the minimum cost of a road trip in Hacker Country? | ai | 2013-12-20T08:10:24 | 2022-08-31T08:14:32 | #
# Complete the 'hackerCountry' function below.
#
# The function is expected to return a STRING.
# The function accepts 2D_INTEGER_ARRAY tolls as parameter.
#
def hackerCountry(tolls):
# 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())
tolls = []
for _ in range(n):
tolls.append(list(map(int, input().rstrip().split())))
result = hackerCountry(tolls)
fptr.write(result + '\n')
fptr.close()
| There are *N* cities in *Hacker Country*. Each pair of cities are directly connected by a unique directed road, and each road has its own toll that must be paid every time it is used. You're planning a road trip in *Hacker Country*, and its itinerary must satisfy the following conditions:
+ You can start in any city... | 0.533333 | ["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 is an integer, $N$ (number of cities).
The $N$ subsequent lines of $N$ space-separated integers each describe the respective tolls or traveling from city $i$ to city $j$; in other words, the $j^{th}$ integer of the $i^{th}$ line denotes the toll for traveling from city $i$ to city $j$.
**Note:** As... | Print the *minimum cost* as a rational number $p \ / \ q$ (tolls paid over roads traveled). The *greatest common divisor* of $p$ and $q$ should be $1$. | 2
0 1
2 0 | 3/2 | Hard | Hacker Country : Codesprint 5 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | codesprint5-hacker-country | 2014-01-21T11:07:30 | {"contest_participation":12558,"challenge_submissions":482,"successful_submissions":103} | 2014-01-21T11:07:30 | 2016-07-23T14:03:54 | tester | ###C++
```cpp
#include <iostream>
#include <cstdio>
using namespace std;
const int maxN = 600;
const int inf = 1000000000;
int g[maxN][maxN], d[maxN][maxN];
int n;
long long gcd(long long a, long long b) {
if (a == 0 || b == 0) {
return a + b;
}
if (a > b) {
return gcd(a %... | not-set | 2016-04-24T02:02:15 | 2016-07-23T14:03:54 | C++ |
21 | 1,667 | matrix-tracing | Matrix Tracing | A word from the English dictionary is taken and arranged as a matrix. e.g. "MATHEMATICS"
MATHE
ATHEM
THEMA
HEMAT
EMATI
MATIC
ATICS
There are many ways to trace this matrix in a way that helps you construct this word. You start tracing the matrix from the top-left position and at each iteration, you eith... | code | How many ways can you trace a given matrix? - 30 Points | ai | 2014-01-14T08:25:46 | 2022-09-02T09:54:13 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER m
#
def solve(n, m):
# 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])
result = solve(n, m)
fptr.wri... | A word from the English dictionary is taken and arranged as a matrix. e.g. "MATHEMATICS"
MATHE
ATHEM
THEMA
HEMAT
EMATI
MATIC
ATICS
There are many ways to trace this matrix in a way that helps you construct this word. You start tracing the matrix from the top-left position and... | 0.563758 | ["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 | Matrix Tracing : Codesprint 5 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | codesprint5-matrix-tracing | 2014-01-23T06:50:58 | {"contest_participation":12558,"challenge_submissions":2521,"successful_submissions":1331} | 2014-01-23T06:50:58 | 2016-07-23T16:33:25 | setter | ###Python 2
```python
#!/usr/bin/py
mod = 10**9 + 7
def getfactmod(b):
val = 1
for i in range(1,b):
val =((val%mod)*((i+1)%mod))%mod
return val
def getpowermod(a,b):
if b==0:
return 1
if b == 1:
return a
temp = getpowermod(a,b/2)
if b%2==0:
return ((temp%mod)**2)%mod
else:
... | not-set | 2016-04-24T02:02:15 | 2016-07-23T16:33:12 | Python | ||||
22 | 1,667 | matrix-tracing | Matrix Tracing | A word from the English dictionary is taken and arranged as a matrix. e.g. "MATHEMATICS"
MATHE
ATHEM
THEMA
HEMAT
EMATI
MATIC
ATICS
There are many ways to trace this matrix in a way that helps you construct this word. You start tracing the matrix from the top-left position and at each iteration, you eith... | code | How many ways can you trace a given matrix? - 30 Points | ai | 2014-01-14T08:25:46 | 2022-09-02T09:54:13 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER m
#
def solve(n, m):
# 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])
result = solve(n, m)
fptr.wri... | A word from the English dictionary is taken and arranged as a matrix. e.g. "MATHEMATICS"
MATHE
ATHEM
THEMA
HEMAT
EMATI
MATIC
ATICS
There are many ways to trace this matrix in a way that helps you construct this word. You start tracing the matrix from the top-left position and... | 0.563758 | ["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 | Matrix Tracing : Codesprint 5 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | codesprint5-matrix-tracing | 2014-01-23T06:50:58 | {"contest_participation":12558,"challenge_submissions":2521,"successful_submissions":1331} | 2014-01-23T06:50:58 | 2016-07-23T16:33:25 | tester | ###C++
```cpp
#include <bits/stdc++.h>
using namespace std;
const int sz = 2e6;
const long long mod = 1e9+7;
long long fact[sz];
long long _pow(int a, int b) {
if(b == 0)
return 1ll;
long long ret = _pow(a, b/2);
ret = (ret*ret) % mod;
ret = (ret+mod)% mod;
if(b%2 == 1)
... | not-set | 2016-04-24T02:02:15 | 2016-07-23T16:33:25 | C++ | ||||
23 | 959 | recalling-early-days-gp-with-trees | Recalling Early Days GP with Trees | [Chinese Version](https://hr-testcases.s3.amazonaws.com/959/959-chinese.md)<br/>
[Russian Version](https://hr-testcases.s3.amazonaws.com/959/959_rus.md)<br/>
You are given a [tree](http://en.wikipedia.org/wiki/Tree_(graph_theory)) with N nodes and each has a value associated with it. You are given Q queries, each of w... | code | Answer the queries performed on trees. | ai | 2013-09-25T18:56:57 | 2022-08-31T08:33:17 | null | null | null | [Chinese Version](https://hr-testcases.s3.amazonaws.com/959/959-chinese.md)<br/>
[Russian Version](https://hr-testcases.s3.amazonaws.com/959/959_rus.md)<br/>
You are given a [tree](http://en.wikipedia.org/wiki/Tree_(graph_theory)) with N nodes and each has a value associated with it. You are given Q queries, each of w... | 0.409091 | ["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"... | null | null | null | null | Hard | Recalling Early Days with GP Trees : 101 Hack January Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | 101-hack-jan-recalling-early-days-with-gp-trees | 2014-02-03T12:29:31 | {"contest_participation":1791,"challenge_submissions":71,"successful_submissions":23} | 2014-02-03T12:29:31 | 2016-05-13T00:03:45 | setter | //Author : Devendra Agarwal
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;
#define MaxN 100001 //Maximum Nodes
typedef long long int ll;
int N,R,level[MaxN],Parent[MaxN],Dist_DFSL[MaxN],Dist_DFSR[M... | not-set | 2016-04-24T02:02:15 | 2016-04-24T02:02:15 | C++ |
24 | 959 | recalling-early-days-gp-with-trees | Recalling Early Days GP with Trees | [Chinese Version](https://hr-testcases.s3.amazonaws.com/959/959-chinese.md)<br/>
[Russian Version](https://hr-testcases.s3.amazonaws.com/959/959_rus.md)<br/>
You are given a [tree](http://en.wikipedia.org/wiki/Tree_(graph_theory)) with N nodes and each has a value associated with it. You are given Q queries, each of w... | code | Answer the queries performed on trees. | ai | 2013-09-25T18:56:57 | 2022-08-31T08:33:17 | null | null | null | [Chinese Version](https://hr-testcases.s3.amazonaws.com/959/959-chinese.md)<br/>
[Russian Version](https://hr-testcases.s3.amazonaws.com/959/959_rus.md)<br/>
You are given a [tree](http://en.wikipedia.org/wiki/Tree_(graph_theory)) with N nodes and each has a value associated with it. You are given Q queries, each of w... | 0.409091 | ["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"... | null | null | null | null | Hard | Recalling Early Days with GP Trees : 101 Hack January Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | 101-hack-jan-recalling-early-days-with-gp-trees | 2014-02-03T12:29:31 | {"contest_participation":1791,"challenge_submissions":71,"successful_submissions":23} | 2014-02-03T12:29:31 | 2016-05-13T00:03:45 | tester |
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <vector>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <numeric>... | not-set | 2016-04-24T02:02:15 | 2016-04-24T02:02:15 | C++ |
25 | 1,058 | cube-summation | Cube Summation | [Chinese Version](https://hr-testcases.s3.amazonaws.com/1058/1058-chinese.md)<br/>
[Russian Version](https://hr-testcases.s3.amazonaws.com/1058/1058_rus.md)<br/>
You are given a 3-D Matrix in which each block contains 0 initially. The first block is defined by the coordinate (1,1,1) and the last block is defined by th... | code | Update and query a 3-d matrix | ai | 2013-10-10T09:07:12 | 2022-08-31T08:33:13 | #
# Complete the 'cubeSum' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts following parameters:
# 1. INTEGER n
# 2. STRING_ARRAY operations
#
def cubeSum(n, operations):
# 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()
matSize = int(first_multiple_input[0])
m = int(first_multiple_input[1])
ops = []
for _ in range... | [Chinese Version](https://hr-testcases.s3.amazonaws.com/1058/1058-chinese.md)<br/>
[Russian Version](https://hr-testcases.s3.amazonaws.com/1058/1058_rus.md)<br/>
Define a 3-D Matrix in which each block contains 0 initially. The first block is defined by the coordinates (1,1,1) and the last block is defined by the coor... | 0.56 | ["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"... | Hard | Cube Summation : 101 Hack January Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | 101-hack-jan-cube-summation | 2014-02-05T18:23:32 | {"contest_participation":1791,"challenge_submissions":401,"successful_submissions":276} | 2014-02-05T18:23:32 | 2016-05-13T00:03:42 | setter |
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long matrix[101][101][101];
void update(long long n,long long x,long long y,long long z,long long val) {
long long y1,x1;
while(z <= n) {
x1 = x;
... | not-set | 2016-04-24T02:02:15 | 2016-04-24T02:02:15 | C++ | ||||
26 | 1,058 | cube-summation | Cube Summation | [Chinese Version](https://hr-testcases.s3.amazonaws.com/1058/1058-chinese.md)<br/>
[Russian Version](https://hr-testcases.s3.amazonaws.com/1058/1058_rus.md)<br/>
You are given a 3-D Matrix in which each block contains 0 initially. The first block is defined by the coordinate (1,1,1) and the last block is defined by th... | code | Update and query a 3-d matrix | ai | 2013-10-10T09:07:12 | 2022-08-31T08:33:13 | #
# Complete the 'cubeSum' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts following parameters:
# 1. INTEGER n
# 2. STRING_ARRAY operations
#
def cubeSum(n, operations):
# 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()
matSize = int(first_multiple_input[0])
m = int(first_multiple_input[1])
ops = []
for _ in range... | [Chinese Version](https://hr-testcases.s3.amazonaws.com/1058/1058-chinese.md)<br/>
[Russian Version](https://hr-testcases.s3.amazonaws.com/1058/1058_rus.md)<br/>
Define a 3-D Matrix in which each block contains 0 initially. The first block is defined by the coordinates (1,1,1) and the last block is defined by the coor... | 0.56 | ["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"... | Hard | Cube Summation : 101 Hack January Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | 101-hack-jan-cube-summation | 2014-02-05T18:23:32 | {"contest_participation":1791,"challenge_submissions":401,"successful_submissions":276} | 2014-02-05T18:23:32 | 2016-05-13T00:03:42 | tester |
#include <bits/stdc++.h>
using namespace std;
const int sz = 111;
long long tree[sz][sz][sz];
void update(int x, int y, int z, long long val) {
int xx = x;
while(xx < sz) {
int yy = y;
while(yy < sz) {
int zz = z;
while(zz < sz) {
tree[xx][yy][zz] += val;
zz += zz & (-zz);
}... | not-set | 2016-04-24T02:02:15 | 2016-04-24T02:02:15 | C++ | ||||
27 | 1,543 | bike-racers | Bike Racers | [Chinese Version](https://hr-filepicker.s3.amazonaws.com/feb14/chinese/1543-chinese.md)<br/>
[Russian Version](https://hr-filepicker.s3.amazonaws.com/feb-14/russian/1543-russian.md)<br/>
There are _N_ bikers present in a city (shaped as a grid) having _M_ bikes. All the bikers want to participate in the HackerRace com... | code | Calculate the square of the minimum time required to start the bike race. | ai | 2013-12-13T23:10:30 | 2022-08-31T08:14:22 | #
# Complete the 'bikeRacers' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. 2D_INTEGER_ARRAY bikers
# 2. 2D_INTEGER_ARRAY bikes
#
def bikeRacers(bikers, bikes):
# 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')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
k = int(first_multiple_input[2])
bikers = []
for _ in range(n):
bikers.append(list(map(int, i... |
There are $N$ bikers present in a city (shaped as a grid) having $M$ bikes. All the bikers want to participate in the HackerRace competition, but unfortunately only $K$ bikers can be accommodated in the race. Jack is organizing the HackerRace and wants to start the race as soon as possible. He can instruct any biker t... | 0.406504 | ["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 three integers, $N$, $M$, and $K$, separated by a single space.
The following $N$ lines will contain $N$ pairs of integers denoting the co-ordinates of $N$ bikers. Each pair of integers is separated by a single space. The next $M$ lines will similarly denote the co-ordinates of the $M$ bikes.
| A single line containing the square of required time.
| 3 3 2
0 1
0 2
0 3
100 1
200 2
300 3
| 40000
| Hard | Bike Racers - 2020 Hack February Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | feb14-bike-racers | 2014-02-27T05:02:05 | {"contest_participation":2769,"challenge_submissions":556,"successful_submissions":192} | 2014-02-27T05:02:05 | 2016-12-02T20:11:31 | setter | ###C++
```cpp
//Hopcraft carp maxium matching algorithm time complexity = E*sqrt(V)
#include<iostream>
#include<cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
#define SET(x) memset(x, -1, sizeof(x))
#define CLR(x) memset(x, 0, sizeof(x))
#define MAX ... | not-set | 2016-04-24T02:02:16 | 2016-12-02T20:11:31 | C++ |
28 | 1,543 | bike-racers | Bike Racers | [Chinese Version](https://hr-filepicker.s3.amazonaws.com/feb14/chinese/1543-chinese.md)<br/>
[Russian Version](https://hr-filepicker.s3.amazonaws.com/feb-14/russian/1543-russian.md)<br/>
There are _N_ bikers present in a city (shaped as a grid) having _M_ bikes. All the bikers want to participate in the HackerRace com... | code | Calculate the square of the minimum time required to start the bike race. | ai | 2013-12-13T23:10:30 | 2022-08-31T08:14:22 | #
# Complete the 'bikeRacers' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. 2D_INTEGER_ARRAY bikers
# 2. 2D_INTEGER_ARRAY bikes
#
def bikeRacers(bikers, bikes):
# 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')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
k = int(first_multiple_input[2])
bikers = []
for _ in range(n):
bikers.append(list(map(int, i... |
There are $N$ bikers present in a city (shaped as a grid) having $M$ bikes. All the bikers want to participate in the HackerRace competition, but unfortunately only $K$ bikers can be accommodated in the race. Jack is organizing the HackerRace and wants to start the race as soon as possible. He can instruct any biker t... | 0.406504 | ["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 three integers, $N$, $M$, and $K$, separated by a single space.
The following $N$ lines will contain $N$ pairs of integers denoting the co-ordinates of $N$ bikers. Each pair of integers is separated by a single space. The next $M$ lines will similarly denote the co-ordinates of the $M$ bikes.
| A single line containing the square of required time.
| 3 3 2
0 1
0 2
0 3
100 1
200 2
300 3
| 40000
| Hard | Bike Racers - 2020 Hack February Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | feb14-bike-racers | 2014-02-27T05:02:05 | {"contest_participation":2769,"challenge_submissions":556,"successful_submissions":192} | 2014-02-27T05:02:05 | 2016-12-02T20:11:31 | tester | ###C++
```cpp
#include <bits/stdc++.h>
using namespace std;
const int sz = 2000;
long long userX[sz], userY[sz];
long long bikeX[sz], bikeY[sz];
int lt[sz];
int N, M, K;
bool vis[sz];
bool validPath(int userId, int bikerId, long long distanceAllowed) {
long long distX = userX[userId] - bikeX[bik... | not-set | 2016-04-24T02:02:16 | 2016-07-23T13:49:52 | C++ |
29 | 1,319 | board-cutting | Cutting Boards | [Chinese Version](https://hr-filepicker.s3.amazonaws.com/feb14/chinese/1319-chinese.md)<br/>
[Russian Version](https://hr-filepicker.s3.amazonaws.com/feb-14/russian/1319-russian.md)<br/>
Alice gives a wooden board composed of M X N wooden square pieces to Bob and asks him to find the minimal cost of breaking the board... | code | Find the minimum cost of breaking down an m x n board into 1 x 1 pieces. | ai | 2013-11-15T11:51:49 | 2022-08-31T08:14:37 | #
# Complete the 'boardCutting' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER_ARRAY cost_y
# 2. INTEGER_ARRAY cost_x
#
def boardCutting(cost_y, cost_x):
# 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')
q = int(input().strip())
for q_itr in range(q):
first_multiple_input = input().rstrip().split()
m = int(first_multiple_input[0])
n = int(first_multiple_input[1])
cost_y = list(map(int, input().rstrip(... | Alice gives Bob a board composed of $1 \times 1$ wooden squares and asks him to find the minimum cost of breaking the board back down into its individual squares. To break the board down, Bob must make cuts along its horizontal and vertical lines.
To reduce the board to squares, Bob makes horizontal and vertical cuts... | 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 an integer $q$, the number of queries.
The following $q$ sets of lines are as follows:
- The first line has two positive space-separated integers $m$ and $n$, the number of rows and columns in the board.
- The second line contains $m-1$ space-separated integers cost_y[i], the cost of a hori... | For each of the $q$ queries, find the minimum cost ($minCost$) of cutting the board into $1 \times 1$ squares and print the value of $minCost \text{ % } (10^9+7)$.
**Sample Input 0**
1
2 2
2
1
**Sample Output 0**
4
**Explanation 0**
We have a $2 \times 2$ board, with cut costs $cost\_y[1] = 2$ ... | Hard | Cutting Boards - 2020 Hack February Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | feb14-board-cutting | 2014-02-27T05:13:32 | {"contest_participation":2769,"challenge_submissions":927,"successful_submissions":696} | 2014-02-27T05:13:32 | 2018-04-17T17:56:40 | setter | ###C++
```cpp
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct arr{
long long int val;
int horv;
};
typedef struct arr arr;
int compare(arr c , arr d){
if(c.val > d.val){
return 1;
}
return 0;
}
arr a[2000020];
int main(){
int tc;
scanf("%d",&t... | not-set | 2016-04-24T02:02:16 | 2016-07-23T14:25:46 | C++ | ||
30 | 1,319 | board-cutting | Cutting Boards | [Chinese Version](https://hr-filepicker.s3.amazonaws.com/feb14/chinese/1319-chinese.md)<br/>
[Russian Version](https://hr-filepicker.s3.amazonaws.com/feb-14/russian/1319-russian.md)<br/>
Alice gives a wooden board composed of M X N wooden square pieces to Bob and asks him to find the minimal cost of breaking the board... | code | Find the minimum cost of breaking down an m x n board into 1 x 1 pieces. | ai | 2013-11-15T11:51:49 | 2022-08-31T08:14:37 | #
# Complete the 'boardCutting' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER_ARRAY cost_y
# 2. INTEGER_ARRAY cost_x
#
def boardCutting(cost_y, cost_x):
# 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')
q = int(input().strip())
for q_itr in range(q):
first_multiple_input = input().rstrip().split()
m = int(first_multiple_input[0])
n = int(first_multiple_input[1])
cost_y = list(map(int, input().rstrip(... | Alice gives Bob a board composed of $1 \times 1$ wooden squares and asks him to find the minimum cost of breaking the board back down into its individual squares. To break the board down, Bob must make cuts along its horizontal and vertical lines.
To reduce the board to squares, Bob makes horizontal and vertical cuts... | 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 an integer $q$, the number of queries.
The following $q$ sets of lines are as follows:
- The first line has two positive space-separated integers $m$ and $n$, the number of rows and columns in the board.
- The second line contains $m-1$ space-separated integers cost_y[i], the cost of a hori... | For each of the $q$ queries, find the minimum cost ($minCost$) of cutting the board into $1 \times 1$ squares and print the value of $minCost \text{ % } (10^9+7)$.
**Sample Input 0**
1
2 2
2
1
**Sample Output 0**
4
**Explanation 0**
We have a $2 \times 2$ board, with cut costs $cost\_y[1] = 2$ ... | Hard | Cutting Boards - 2020 Hack February Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | feb14-board-cutting | 2014-02-27T05:13:32 | {"contest_participation":2769,"challenge_submissions":927,"successful_submissions":696} | 2014-02-27T05:13:32 | 2018-04-17T17:56:40 | tester | ###Haskell
```haskell
-- {{{
module Main where
---------------------Import-------------------------
import Data.List
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Char
import Data.Int -- Int32, Int64
import System.IO
import Data.Ratio ... | not-set | 2016-04-24T02:02:16 | 2016-07-23T14:26:06 | Python | ||
31 | 1,857 | mathematical-expectation | Mathematical Expectation | [Chinese Version](https://hr-filepicker.s3.amazonaws.com/feb14/chinese/1857-chinese.md)<br/>
[Russian Version](https://hr-filepicker.s3.amazonaws.com/feb-14/russian/1857-russian.md)<br/>
Let's consider a random permutation p<sub>1</sub>, p<sub>2</sub>, ..., p<sub>N</sub> of numbers 1, 2, ..., N and calculate the value... | code | Expected value of Seyaua's function | ai | 2014-02-06T20:29:14 | 2022-09-02T09:55:42 | null | null | null | Let's consider a random permutation p<sub>1</sub>, p<sub>2</sub>, ..., p<sub>N</sub> of numbers 1, 2, ..., N and calculate the value F=(X<sub>2</sub>+...+X<sub>N-1</sub>)<sup>K</sup>, where X<sub>i</sub> equals 1 if one of the following two conditions holds: p<sub>i-1</sub> < p<sub>i</sub> > p<sub>i+1</sub> or p<sub>i-... | 0.586207 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | Hard | Mathematical Expectation - 2020 Hack February Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | feb14-mathematical-expectation | 2014-03-03T12:02:38 | {"contest_participation":2769,"challenge_submissions":187,"successful_submissions":38} | 2014-03-03T12:02:38 | 2016-07-23T19:18:53 | setter | ###Java
```java
import java.io.*;
import java.util.*;
import java.math.*;
public class Solution {
public static void main(String[] args) {
new Solution().run();
}
// 1 : +2/3*n^1-4/3*n^0
// 2 : 40*n^2-144*n+131 / 90
// 3 : 280*n^3-1344*n^2+2063*n-1038 / 945
// 4 : 2800*n^4... | not-set | 2016-04-24T02:02:16 | 2016-07-23T19:18:54 | Java | ||||
32 | 1,828 | isosceles-triangles | Isosceles Triangles | [Sevenkplus](http://sevenkplus.com/) has a regular polygon. Each vertex of the polygon has a color, either white or black. Sevenkplus wants to count the number of isosceles triangles whose vertices are vertices of the regular polygon and have the same color.
**Input Format**
The first line contains an integer T. ... | code | How many monochromatic isosceles triangles are there? | ai | 2014-02-02T04:29:46 | 2022-09-02T09:55:24 | null | null | null | [Sevenkplus](http://sevenkplus.com/) has a regular polygon. Each vertex of the polygon has a color, either white or black. Sevenkplus wants to count the number of isosceles triangles whose vertices are vertices of the regular polygon and have the same color.
**Input Format**
The first line contains an integer T. ... | 0.488636 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | null | null | null | null | Hard | Isosceles Triangles - 101 Hack February Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | 101feb14-isosceles-triangles | 2014-03-03T12:39:18 | {"contest_participation":1550,"challenge_submissions":54,"successful_submissions":9} | 2014-03-03T12:39:18 | 2016-07-23T19:10:55 | setter | ###C++
```cpp
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <ctime>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<... | not-set | 2016-04-24T02:02:16 | 2016-07-23T19:10:40 | C++ |
33 | 1,828 | isosceles-triangles | Isosceles Triangles | [Sevenkplus](http://sevenkplus.com/) has a regular polygon. Each vertex of the polygon has a color, either white or black. Sevenkplus wants to count the number of isosceles triangles whose vertices are vertices of the regular polygon and have the same color.
**Input Format**
The first line contains an integer T. ... | code | How many monochromatic isosceles triangles are there? | ai | 2014-02-02T04:29:46 | 2022-09-02T09:55:24 | null | null | null | [Sevenkplus](http://sevenkplus.com/) has a regular polygon. Each vertex of the polygon has a color, either white or black. Sevenkplus wants to count the number of isosceles triangles whose vertices are vertices of the regular polygon and have the same color.
**Input Format**
The first line contains an integer T. ... | 0.488636 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | null | null | null | null | Hard | Isosceles Triangles - 101 Hack February Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | 101feb14-isosceles-triangles | 2014-03-03T12:39:18 | {"contest_participation":1550,"challenge_submissions":54,"successful_submissions":9} | 2014-03-03T12:39:18 | 2016-07-23T19:10:55 | tester | ###C++
```cpp
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <complex>
#pragma comment (linker, "/STACK:256000000")
using namespace std;
struct base {
double x, y;
base() { x = y = 0;}
... | not-set | 2016-04-24T02:02:16 | 2016-07-23T19:10:55 | C++ |
34 | 1,071 | coloring-tree | Coloring Tree |
You are given a tree with **N** nodes with every node being colored. A color is represented by an integer ranging from 1 to 10<sup>9</sup>. Can you find the number of distinct colors available in a subtree rooted at the node **s**?
**Input Format**
The first line contains three space separated integers representi... | code | Given a tree with all nodes colored, find the number of distinct colors rooted at a given node. | ai | 2013-10-12T06:23:17 | 2022-09-02T10:00:36 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts following parameters:
# 1. 2D_INTEGER_ARRAY tree
# 2. INTEGER_ARRAY color
# 3. INTEGER_ARRAY s
#
def solve(tree, color, 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')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
r = int(first_multiple_input[2])
tree = []
for _ in range(n - 1):
tree.append(list(map(int, i... |
You are given a tree with **N** nodes with every node being colored. A color is represented by an integer ranging from 1 to 10<sup>9</sup>. Can you find the number of distinct colors available in a subtree rooted at the node **s**?
**Input Format**
The first line contains three space separated integers representi... | 0.413793 | ["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 | Coloring Tree - 101 Hack February Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | 101feb14-coloring-tree | 2014-03-03T16:23:22 | {"contest_participation":1550,"challenge_submissions":146,"successful_submissions":86} | 2014-03-03T16:23:22 | 2016-05-13T00:03:32 | setter |
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
using namespace std;
#define Max_N 1000001
#define INF 1000000000
int N,color[Max_N],root,from,to,counter,parent[Max_N],s,q,search_here[Max_N],highest,last_occurence[M... | not-set | 2016-04-24T02:02:16 | 2016-04-24T02:02:16 | C++ | ||||
35 | 1,071 | coloring-tree | Coloring Tree |
You are given a tree with **N** nodes with every node being colored. A color is represented by an integer ranging from 1 to 10<sup>9</sup>. Can you find the number of distinct colors available in a subtree rooted at the node **s**?
**Input Format**
The first line contains three space separated integers representi... | code | Given a tree with all nodes colored, find the number of distinct colors rooted at a given node. | ai | 2013-10-12T06:23:17 | 2022-09-02T10:00:36 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts following parameters:
# 1. 2D_INTEGER_ARRAY tree
# 2. INTEGER_ARRAY color
# 3. INTEGER_ARRAY s
#
def solve(tree, color, 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')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
r = int(first_multiple_input[2])
tree = []
for _ in range(n - 1):
tree.append(list(map(int, i... |
You are given a tree with **N** nodes with every node being colored. A color is represented by an integer ranging from 1 to 10<sup>9</sup>. Can you find the number of distinct colors available in a subtree rooted at the node **s**?
**Input Format**
The first line contains three space separated integers representi... | 0.413793 | ["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 | Coloring Tree - 101 Hack February Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | 101feb14-coloring-tree | 2014-03-03T16:23:22 | {"contest_participation":1550,"challenge_submissions":146,"successful_submissions":86} | 2014-03-03T16:23:22 | 2016-05-13T00:03:32 | tester |
/*
Author:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% LALIT KUNDU %%%%%%%%
%%%%%%%% IIIT HYDERABAD %%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<... | not-set | 2016-04-24T02:02:16 | 2016-04-24T02:02:16 | C++ | ||||
36 | 1,148 | xoring-ninja | Xoring Ninja |
Given a list containing N integers, calculate the XOR\_SUM of all the non-empty subsets of the list and print the value of sum % (10<sup>9</sup> + 7).
XOR operation on a list (or a subset of the list) is defined as the XOR of all the elements present in it. <br>
E.g. XOR of list containing elements {A,B,C} = ((A^... | code | Given a list of integers, sum the XORs of all the list's non-empty subsets and mod your answer by 10^9 + 7. | ai | 2013-10-22T17:20:15 | 2022-08-31T08:14:58 | #
# Complete the 'xoringNinja' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY arr as parameter.
#
def xoringNinja(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')
t = int(input().strip())
for t_itr in range(t):
arr_count = int(input().strip())
arr = list(map(int, input().rstrip().split()))
result = xoringNinja(arr)
fptr.write(str(result) + '\n')
fptr.close... | An [XOR](https://en.wikipedia.org/wiki/Exclusive_or) operation on a list is defined here as the *xor* ($\oplus$) of all its elements (e.g.: $XOR(\{A, B, C\}) = A \oplus B \oplus C$).
The $XorSum$ of set $arr$ is defined here as the sum of the $XOR$s of all non-empty subsets of $arr$ known as $arr'$. The set $arr'$ ca... | 0.492408 | ["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 an integer $T$, the number of test cases.
Each test case consists of two lines:
- The first line contains an integer $n$, the size of the set $arr$.
- The second line contains $n$ space-separated integers $arr[i]$.
| For each test case, print its $XorSum\ \%\ (10^9+7)$ on a new line. The $i^{th}$ line should contain the output for the $i^{th}$ test case. | 1
3
1 2 3 | 12 | Hard | Xoring Ninja 2020 Hack March Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | mar14-xoring-ninja | 2014-03-23T17:52:57 | {"contest_participation":2080,"challenge_submissions":577,"successful_submissions":438} | 2014-03-23T17:52:57 | 2018-05-08T18:32:33 | setter | ###C++
```cpp
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define MOD 1000000007
long long int power(long long int n, long long int k)
{
long long int result, pow;
if(k==0)
return 1;
if(n==0)
return 0;
if(n==1)
r... | not-set | 2016-04-24T02:02:35 | 2016-07-23T16:10:37 | C++ |
37 | 1,148 | xoring-ninja | Xoring Ninja |
Given a list containing N integers, calculate the XOR\_SUM of all the non-empty subsets of the list and print the value of sum % (10<sup>9</sup> + 7).
XOR operation on a list (or a subset of the list) is defined as the XOR of all the elements present in it. <br>
E.g. XOR of list containing elements {A,B,C} = ((A^... | code | Given a list of integers, sum the XORs of all the list's non-empty subsets and mod your answer by 10^9 + 7. | ai | 2013-10-22T17:20:15 | 2022-08-31T08:14:58 | #
# Complete the 'xoringNinja' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY arr as parameter.
#
def xoringNinja(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')
t = int(input().strip())
for t_itr in range(t):
arr_count = int(input().strip())
arr = list(map(int, input().rstrip().split()))
result = xoringNinja(arr)
fptr.write(str(result) + '\n')
fptr.close... | An [XOR](https://en.wikipedia.org/wiki/Exclusive_or) operation on a list is defined here as the *xor* ($\oplus$) of all its elements (e.g.: $XOR(\{A, B, C\}) = A \oplus B \oplus C$).
The $XorSum$ of set $arr$ is defined here as the sum of the $XOR$s of all non-empty subsets of $arr$ known as $arr'$. The set $arr'$ ca... | 0.492408 | ["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 an integer $T$, the number of test cases.
Each test case consists of two lines:
- The first line contains an integer $n$, the size of the set $arr$.
- The second line contains $n$ space-separated integers $arr[i]$.
| For each test case, print its $XorSum\ \%\ (10^9+7)$ on a new line. The $i^{th}$ line should contain the output for the $i^{th}$ test case. | 1
3
1 2 3 | 12 | Hard | Xoring Ninja 2020 Hack March Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | mar14-xoring-ninja | 2014-03-23T17:52:57 | {"contest_participation":2080,"challenge_submissions":577,"successful_submissions":438} | 2014-03-23T17:52:57 | 2018-05-08T18:32:33 | tester | ###Python 2
```python
#!/usr/bin
from math import *
t=int(raw_input())
assert(t<=5)
assert(t>=1)
for i in range(0,t):
n=int(raw_input())
assert(n<=10**5)
assert(n>=1)
a=[]
b=[]
for j in range(0,int(log(10**9,2)+1)):
b=[0]*n
a.append(b)
number=map(int, raw_input().split()... | not-set | 2016-04-24T02:02:35 | 2016-07-23T16:10:46 | Python |
38 | 1,767 | ones-and-twos | Ones and Twos |
You are using at most **A** number of 1s and at most **B** number of 2s. How many different evaluation results are possible when they are formed in an expression containing only addition `+` sign and multiplication `*` sign are allowed?
Note that, multiplication takes precedence over addition.
For example, if **A=2... | code | Using A 1's and B 2's how many different evaluations are possible only by performing addition and multiplication | ai | 2014-01-29T15:42:24 | 2022-08-31T08:14:53 | #
# Complete the 'onesAndTwos' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER a
# 2. INTEGER b
#
def onesAndTwos(a, b):
# 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()
a = int(first_multiple_input[0])
b = int(first_multiple_input[1])
result = onesAndTwos(a, b)
fp... |
You are using at most **A** number of 1s and at most **B** number of 2s. How many different evaluation results are possible when they are formed in an expression containing only addition `+` sign and multiplication `*` sign are allowed?
Note that, multiplication takes precedence over addition.
For example, if **A=2... | 0.545455 | ["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 the number of test cases T, T testcases follow each in a newline.
Each testcase contains 2 integers A and B separated by a single space.
| Print the number of different evaluations modulo (%) (10<sup>9</sup>+7.)
| 4
0 0
2 2
0 2
2 0
| 0
6
2
2
| Hard | Ones and Twos - 2020 Hack March Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | mar14-ones-and-twos | 2014-03-27T19:47:34 | {"contest_participation":2080,"challenge_submissions":137,"successful_submissions":15} | 2014-03-27T19:47:34 | 2016-07-23T15:23:45 | setter | ###C++
```cpp
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define SZ(c) ((int)(c).size())
typedef long long LL;
int MOD = 1e9+7;
int p[33][1005]... | not-set | 2016-04-24T02:02:35 | 2016-07-23T15:23:27 | C++ |
39 | 1,767 | ones-and-twos | Ones and Twos |
You are using at most **A** number of 1s and at most **B** number of 2s. How many different evaluation results are possible when they are formed in an expression containing only addition `+` sign and multiplication `*` sign are allowed?
Note that, multiplication takes precedence over addition.
For example, if **A=2... | code | Using A 1's and B 2's how many different evaluations are possible only by performing addition and multiplication | ai | 2014-01-29T15:42:24 | 2022-08-31T08:14:53 | #
# Complete the 'onesAndTwos' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER a
# 2. INTEGER b
#
def onesAndTwos(a, b):
# 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()
a = int(first_multiple_input[0])
b = int(first_multiple_input[1])
result = onesAndTwos(a, b)
fp... |
You are using at most **A** number of 1s and at most **B** number of 2s. How many different evaluation results are possible when they are formed in an expression containing only addition `+` sign and multiplication `*` sign are allowed?
Note that, multiplication takes precedence over addition.
For example, if **A=2... | 0.545455 | ["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 the number of test cases T, T testcases follow each in a newline.
Each testcase contains 2 integers A and B separated by a single space.
| Print the number of different evaluations modulo (%) (10<sup>9</sup>+7.)
| 4
0 0
2 2
0 2
2 0
| 0
6
2
2
| Hard | Ones and Twos - 2020 Hack March Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | mar14-ones-and-twos | 2014-03-27T19:47:34 | {"contest_participation":2080,"challenge_submissions":137,"successful_submissions":15} | 2014-03-27T19:47:34 | 2016-07-23T15:23:45 | tester | ###C++
```cpp
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <ctime>
#include <set>
#include <cassert>
using namespace std;
const int P = 1000000007;
const int maxN = 1100;
int d[maxN][maxN], s[maxN][maxN];
void precalc() {
d[maxN - 1][0] = 1;
for (int i... | not-set | 2016-04-24T02:02:35 | 2016-07-23T15:23:45 | C++ |
40 | 1,050 | devu-police | Devu Vs Police | [Mandarin-Chinese](https://hr-filepicker.s3.amazonaws.com/infinitum-mar14/mandarin/1050-devupolice.md)
[Russian](https://hr-filepicker.s3.amazonaws.com/infinitum-mar14/russian/1050-devupolice.md)
It is holi festival, festival of colors. Devu is having fun playing holi and is throwing balloons with his girlfriend G... | code | Help Devu escape from police | ai | 2013-10-09T04:59:51 | 2022-09-02T09:54:38 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n1
# 2. INTEGER k1
# 3. INTEGER n2
# 4. INTEGER k2
# 5. INTEGER n
#
def solve(n1, k1, n2, k2, 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):
first_multiple_input = input().rstrip().split()
n1 = int(first_multiple_input[0])
k1 = int(first_multiple_input[1])
n2 = int(first_multiple_input[2])
... |
It is holi festival, festival of colors. Devu is having fun playing holi and is throwing balloons with his girlfriend Glynis. Police saw this mischief and tried arresting his girlfriend, Devu being a mathematician asked police not to arrest his girlfriend and instead torture him with brain teaser. Devu was a young e... | 0.431818 | ["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"] | You are given $T$ which is the number of queries to solve.
Each Query consist of 5 space separated integers $n_1,k_1,n_2,k_2,n$ | Output contains exactly $T$ lines. $i^{\text{th}}$ line containing the answer for the $i^{\text{th}}$ query. | 1
2 1 2 2 15 | 1 | Hard | Devu Vs Police Infinitum Mar14 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | infinitum-mar14-devu-police | 2014-04-01T21:20:47 | {"contest_participation":1667,"challenge_submissions":241,"successful_submissions":76} | 2014-04-01T21:20:47 | 2016-12-09T10:05:33 | setter | ###C++
```cpp
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<vector>
#include<assert.h>
using namespace std;
typedef long long int ll;
int sieve_par=3162;
int prime[3162] , array[3162],counter=0;
ll inverse(ll a,ll b) //b>a
{
ll Remainder,p0=0,p1=1,pcurr=1,q,m=b;
while... | not-set | 2016-04-24T02:02:35 | 2016-07-23T18:01:09 | C++ |
41 | 1,050 | devu-police | Devu Vs Police | [Mandarin-Chinese](https://hr-filepicker.s3.amazonaws.com/infinitum-mar14/mandarin/1050-devupolice.md)
[Russian](https://hr-filepicker.s3.amazonaws.com/infinitum-mar14/russian/1050-devupolice.md)
It is holi festival, festival of colors. Devu is having fun playing holi and is throwing balloons with his girlfriend G... | code | Help Devu escape from police | ai | 2013-10-09T04:59:51 | 2022-09-02T09:54:38 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n1
# 2. INTEGER k1
# 3. INTEGER n2
# 4. INTEGER k2
# 5. INTEGER n
#
def solve(n1, k1, n2, k2, 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):
first_multiple_input = input().rstrip().split()
n1 = int(first_multiple_input[0])
k1 = int(first_multiple_input[1])
n2 = int(first_multiple_input[2])
... |
It is holi festival, festival of colors. Devu is having fun playing holi and is throwing balloons with his girlfriend Glynis. Police saw this mischief and tried arresting his girlfriend, Devu being a mathematician asked police not to arrest his girlfriend and instead torture him with brain teaser. Devu was a young e... | 0.431818 | ["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"] | You are given $T$ which is the number of queries to solve.
Each Query consist of 5 space separated integers $n_1,k_1,n_2,k_2,n$ | Output contains exactly $T$ lines. $i^{\text{th}}$ line containing the answer for the $i^{\text{th}}$ query. | 1
2 1 2 2 15 | 1 | Hard | Devu Vs Police Infinitum Mar14 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | infinitum-mar14-devu-police | 2014-04-01T21:20:47 | {"contest_participation":1667,"challenge_submissions":241,"successful_submissions":76} | 2014-04-01T21:20:47 | 2016-12-09T10:05:33 | tester | ###Java
```java
import java.math.*;
import java.util.*;
public class Solution {
public static long powermod(long x,long y,long M) {
x %= M;
if (y == 0) {
return 1;
}
if (x == 0) {
return 0;
}
long r = 1L;
for (;y > 0; y >>= 1) {... | not-set | 2016-04-24T02:02:35 | 2016-07-23T18:01:49 | Java |
42 | 1,329 | a-very-special-multiple | A Very Special Multiple | [Mandarin](http://hr-filepicker.s3.amazonaws.com/infinitum-mar14/mandarin/1329-veryspecialmultiple.md) \| [Russian](http://hr-filepicker.s3.amazonaws.com/infinitum-mar14/russian/1329-veryspecialmultiple.md) \| [Japanese](http://hr-filepicker.s3.amazonaws.com/infinitum-mar14/japanese/1329-veryspecialmultiple.md)
Char... | code | Find the number of 4's and 0's in the multiple | ai | 2013-11-18T07:44:55 | 2022-09-02T09:54:43 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts LONG_INTEGER x as parameter.
#
def solve(x):
# 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):
x = int(input().strip())
result = solve(x)
fptr.write(str(result) + '\n')
fptr.close()
| Charlie and Johnny play a game. For every integer $X$ Charlie gives, Johnny has to find the smallest positive integer $Y$ such that $X \times Y$ ($X$ multiplied by $Y$) contains only 4s and 0s and starts with one or more 4s followed by zero or more 0s. For example, 404 is an invalid number but 4400, 440, and 444 are va... | 0.564103 | ["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 | A Very Special Multiple Infinitum Mar14 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | infinitum-mar14-a-very-special-multiple | 2014-04-01T21:24:58 | {"contest_participation":1667,"challenge_submissions":122,"successful_submissions":48} | 2014-04-01T21:24:58 | 2016-12-02T17:29:23 | tester | ###C++
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll sieve(ll a[],ll b[],ll n)
{
ll i,k,j;
for(i=0;i<n;i++)
{
a[i]=i,b[i]=0;
}
for (j=2;j*j<n;j++)
{
k=j;
if(a[j]!=0)
{
while(k*j<n)
{ ... | not-set | 2016-04-24T02:02:35 | 2016-07-23T18:13:45 | C++ | ||||
43 | 2,152 | reverse-factorization | Reverse Factorization | At the time when Pythagoreanism was prevalent, people were also focused on different ways to factorize a number. In one class, Pythagoreas asked his disciples to solve one such problem, _Reverse Factorization_. They were given a set of integer, `A` = _{a<sub>1</sub>, a<sub>2</sub>,..., a<sub>K</sub>}_, and an integer ... | code | Find multiples to reach `N`. | ai | 2014-03-17T22:45:59 | 2017-03-10T08:53:18 | null | null | null | At the time when Pythagoreanism was prevalent, people were also focused on different ways to factorize a number. In one class, Pythagoras asked his disciples to solve one such problem, _Reverse Factorization_. They were given a set of integer, $A = \{a_1, a_2, \cdots, a_K\}$, and an integer $N$. They need to find the ... | 0.5 | ["haskell","clojure","scala","erlang","sbcl","ocaml","fsharp","racket","elixir"] | Input contains two lines where first line contains two space separated integer, $N$ and $K$, representing the final value to reach and the size of set $A$, respectively. Next line contains `K` space integers representing the set $A = \{a_1, a_2, \cdots, a_K\}$.
| Print the steps to reach $N$ if it exists. Otherwise print `-1`.
| Hard | Reverse Factorization, Functional Programming Contest - March'14 | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | lambda-calculi-mar14-reverse-factorization | 2014-04-02T19:30:44 | {"contest_participation":797,"challenge_submissions":56,"successful_submissions":46} | 2014-04-02T19:30:44 | 2016-05-13T00:03:08 | setter | import Data.List
import qualified Data.Map as Map
data Queue a = Queue {
active :: [a]
, inactive :: [a]
} deriving (Show)
emptyQ :: Queue a
emptyQ = Queue [] []
swapQ :: Queue a -> Queue a
swapQ q = Queue {active = inactive q, inactive = active q}
... | not-set | 2016-04-24T02:02:36 | 2016-04-24T02:02:36 | Python | ||
44 | 2,176 | hexagonal-grid | Hexagonal Grid |
You are given a hexagonal grid of size _2xN_. Your task is to construct the grid with _2x1_ dominoes. The dominoes can be arranged in any of the three orientations shown below. To add to the woes, certain cells of the hexogonal grid are blackened i.e., no domino can occupy that cell. Can you construct such a hexagona... | code | You are given a hexagonal grid of size 2xN. Your task is to
construct the grid with dominoes of given size. | ai | 2014-03-20T21:45:12 | 2022-08-31T08:14:47 | #
# Complete the 'hexagonalGrid' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
# 1. STRING a
# 2. STRING b
#
def hexagonalGrid(a, b):
# 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())
a = input()
b = input()
result = hexagonalGrid(a, b)
fptr.write(result + '\n')
fptr.close()
| You are given a hexagonal grid consisting of two rows, each row consisting of $n$ cells. The cells of the first row are labelled $a_1, a_2, \ldots a_n$ and the cells of the second row are labelled $b_1, b_2, \ldots, b_n$.
For example, for $n = 6$:

using namespace std;
const int max... | not-set | 2016-04-24T02:02:36 | 2016-07-23T14:48:30 | C++ |
45 | 2,176 | hexagonal-grid | Hexagonal Grid |
You are given a hexagonal grid of size _2xN_. Your task is to construct the grid with _2x1_ dominoes. The dominoes can be arranged in any of the three orientations shown below. To add to the woes, certain cells of the hexogonal grid are blackened i.e., no domino can occupy that cell. Can you construct such a hexagona... | code | You are given a hexagonal grid of size 2xN. Your task is to
construct the grid with dominoes of given size. | ai | 2014-03-20T21:45:12 | 2022-08-31T08:14:47 | #
# Complete the 'hexagonalGrid' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
# 1. STRING a
# 2. STRING b
#
def hexagonalGrid(a, b):
# 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())
a = input()
b = input()
result = hexagonalGrid(a, b)
fptr.write(result + '\n')
fptr.close()
| You are given a hexagonal grid consisting of two rows, each row consisting of $n$ cells. The cells of the first row are labelled $a_1, a_2, \ldots a_n$ and the cells of the second row are labelled $b_1, b_2, \ldots, b_n$.
For example, for $n = 6$:
 {
if(l == -1 && r == -1)
return 1;
if(l < -1 ||r < -1)
return 0;
if(l < 0 && r >= 0 && a[1][r] == 1)
return solve(l, r-1);
if(r < 0 && l >=... | not-set | 2016-04-24T02:02:36 | 2016-07-23T14:48:42 | C++ |
46 | 2,135 | count-palindromes | Count Palindromes |
A string is made of only lowercase latin letters (a,b,c,d,.....,z). Can you find the length of the lexicographically smallest string such that it has exactly **K** sub-strings, each of which are palindromes?
**Input Format**
The first line of input contains single integer **T** - the number of testcases.
T lin... | code | What is the smallest string that contains exactly K palindromes? | ai | 2014-03-15T11:46:14 | 2022-09-02T10:08:05 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts LONG_INTEGER k as parameter.
#
def solve(k):
# 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):
k = int(input().strip())
result = solve(k)
fptr.write(str(result) + '\n')
fptr.close()
| A string is made of only lowercase latin letters (a,b,c,d,.....,z). Can you find the length of the lexicographically smallest string such that it has exactly $K$ sub-strings, each of which are palindromes? | 0.426829 | ["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"] | The first line of input contains single integer $T$ - the number of testcases.
T lines follow, each containing the integer $K$.
| Output exactly $T$ lines. Each line should contain single integer - the length of the lexicographically smallest string.
| 2
10
17
| 4
7
| Hard | Count Palindromes - 101 Hack March Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | 101mar14-count-palindromes | 2014-04-08T07:38:59 | {"contest_participation":1218,"challenge_submissions":58,"successful_submissions":14} | 2014-04-08T07:38:58 | 2016-07-23T18:40:52 | setter | ###C++
```cpp
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <bitset>
#include <ctime>
#include <string>
#include <cstring>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int max... | not-set | 2016-04-24T02:02:36 | 2016-07-23T18:40:45 | C++ |
47 | 2,135 | count-palindromes | Count Palindromes |
A string is made of only lowercase latin letters (a,b,c,d,.....,z). Can you find the length of the lexicographically smallest string such that it has exactly **K** sub-strings, each of which are palindromes?
**Input Format**
The first line of input contains single integer **T** - the number of testcases.
T lin... | code | What is the smallest string that contains exactly K palindromes? | ai | 2014-03-15T11:46:14 | 2022-09-02T10:08:05 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts LONG_INTEGER k as parameter.
#
def solve(k):
# 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):
k = int(input().strip())
result = solve(k)
fptr.write(str(result) + '\n')
fptr.close()
| A string is made of only lowercase latin letters (a,b,c,d,.....,z). Can you find the length of the lexicographically smallest string such that it has exactly $K$ sub-strings, each of which are palindromes? | 0.426829 | ["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"] | The first line of input contains single integer $T$ - the number of testcases.
T lines follow, each containing the integer $K$.
| Output exactly $T$ lines. Each line should contain single integer - the length of the lexicographically smallest string.
| 2
10
17
| 4
7
| Hard | Count Palindromes - 101 Hack March Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | 101mar14-count-palindromes | 2014-04-08T07:38:59 | {"contest_participation":1218,"challenge_submissions":58,"successful_submissions":14} | 2014-04-08T07:38:58 | 2016-07-23T18:40:52 | tester | ###C++
```cpp
//by tmt514
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
using namespace std;
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define SZ(c) ((int)(c).size())
typedef l... | not-set | 2016-04-24T02:02:36 | 2016-07-23T18:40:52 | C++ |
48 | 1,768 | the-bouncing-flying-ball | The Bouncing Flying Ball |
Sergey and Chen are locked in a rectangular box of Dimension L\*W\*H. Evil Larry has put a machine which is located at a point inside the box (p,q,r) which starts shooting balls in every direction (dx,dy,dz) where
-N ≤ dx, dy, dz ≤ N except (0, 0, 0)
such that the ball goes through (p, q, r) -> (p + dx, q +... | code | Some bouncing balls are flying from a single source in a rectangular box. You are going to count how many balls passes through point A and point B | ai | 2014-01-29T16:38:17 | 2022-09-02T09:54:45 | null | null | null |
Sergey and Chen are locked in a rectangular box of Dimension L\*W\*H. Evil Larry has put a machine which is located at a point inside the box (p,q,r) which starts shooting balls in every direction (dx,dy,dz) where
-N ≤ dx, dy, dz ≤ N except (0, 0, 0)
such that the ball goes through (p, q, r) -> (p + dx, q +... | 0.538462 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | null | null | null | null | Hard | The bouncing flying ball - March'14 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | mar14-the-bouncing-flying-ball | 2014-04-15T09:40:26 | {"contest_participation":2080,"challenge_submissions":74,"successful_submissions":19} | 2014-04-15T09:40:26 | 2016-07-23T18:17:52 | setter | ###C++
```cpp
/ by tmt514
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define SZ(x) ((int)(x).size())
int L, W, H, a, b, c, d, e, f,... | not-set | 2016-04-24T02:02:36 | 2016-07-23T18:17:39 | C++ |
49 | 1,768 | the-bouncing-flying-ball | The Bouncing Flying Ball |
Sergey and Chen are locked in a rectangular box of Dimension L\*W\*H. Evil Larry has put a machine which is located at a point inside the box (p,q,r) which starts shooting balls in every direction (dx,dy,dz) where
-N ≤ dx, dy, dz ≤ N except (0, 0, 0)
such that the ball goes through (p, q, r) -> (p + dx, q +... | code | Some bouncing balls are flying from a single source in a rectangular box. You are going to count how many balls passes through point A and point B | ai | 2014-01-29T16:38:17 | 2022-09-02T09:54:45 | null | null | null |
Sergey and Chen are locked in a rectangular box of Dimension L\*W\*H. Evil Larry has put a machine which is located at a point inside the box (p,q,r) which starts shooting balls in every direction (dx,dy,dz) where
-N ≤ dx, dy, dz ≤ N except (0, 0, 0)
such that the ball goes through (p, q, r) -> (p + dx, q +... | 0.538462 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | null | null | null | null | Hard | The bouncing flying ball - March'14 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | mar14-the-bouncing-flying-ball | 2014-04-15T09:40:26 | {"contest_participation":2080,"challenge_submissions":74,"successful_submissions":19} | 2014-04-15T09:40:26 | 2016-07-23T18:17:52 | tester | ###C++
```cpp
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define SZ(c) ((long long)(c).size())
typedef long long LL;
long long L... | not-set | 2016-04-24T02:02:36 | 2016-07-23T18:17:52 | C++ |
50 | 486 | k-balance | k-balance number | Your task is to calculate the sum (indicated by S) of all the k-balanced integers between [L, R]. An integer is called k-balanced when either of #1 or #2 below holds true.
1. The length of the integer <= k
2. Sum of the first k digits (with no leading zeros) is equal to the sum of the last k digits.
**Input ... | code | Your task is to calculate the sum(indicated by S) of all the k-balanced integers between [L,R]. | ai | 2013-03-14T16:03:43 | 2022-09-02T09:55:00 | null | null | null | Your task is to calculate the sum (indicated by S) of all the k-balanced integers between [L, R]. An integer is called k-balanced when either of #1 or #2 below holds true.
1. The length of the integer <= k
2. Sum of the first k digits (with no leading zeros) is equal to the sum of the last k digits.
**Input ... | 0.526316 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | null | null | null | null | Hard | May 20-20 Hack Editorial: K-Balance | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | may-2020-editorial-k-balance | 2013-06-11T15:00:56 | {"contest_participation":3663,"challenge_submissions":242,"successful_submissions":69} | 2013-06-11T15:00:56 | 2016-07-23T18:44:37 | setter | ###C++
```cpp
#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<queue>
#include<stack>
#include<bitset>
#include<vector>
#include<cstdio>
#include<string>
#include<cassert>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iterator>
#include<iostream>
#include<algorithm>
using namesp... | not-set | 2016-04-24T02:02:36 | 2016-07-23T18:44:37 | C++ |
51 | 2,293 | p-sequences | P-sequences |
We call a sequence of `N` natural numbers (*a*<sub>1</sub>, *a*<sub>2</sub>, ..., *a*<sub>N</sub>) a *P-sequence*, if the product of any two adjacent numbers in it is not greater than *P*. In other words, if a sequence (*a*<sub>1</sub>, *a*<sub>2</sub>, ..., *a*<sub>N</sub>) is a *P-sequence*, then *a*<sub>i</sub> *... | code | How many sequences of N elements are there if product of two adjacent elements is not greater than P | ai | 2014-03-31T21:26:34 | 2022-08-31T08:14:51 | #
# Complete the 'pSequences' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER p
#
def pSequences(n, p):
# 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())
p = int(input().strip())
result = pSequences(n, p)
fptr.write(str(result) + '\n')
fptr.close()
| We call a sequence of `N` natural numbers (*a*<sub>1</sub>, *a*<sub>2</sub>, ..., *a*<sub>N</sub>) a *P-sequence*, if the product of any two adjacent numbers in it is not greater than *P*. In other words, if a sequence (*a*<sub>1</sub>, *a*<sub>2</sub>, ..., *a*<sub>N</sub>) is a *P-sequence*, then *a*<sub>i</sub> * *a... | 0.550562 | ["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 of input consists of `N`
The second line of the input consists of `P`.
| Output the number of *P-sequences* of `N` integers modulo 10<sup>9</sup>+7.
| 2
2
| 3
| Hard | P-Sequences - Week 1 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | w1-p-sequences | 2014-04-24T18:24:07 | {"contest_participation":2214,"challenge_submissions":260,"successful_submissions":117} | 2014-04-24T18:24:07 | 2016-07-23T15:27:56 | setter | ###C++
```cpp
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define maxn 1000 + 5
#define max_sqrt_k 32000
#define mod 1000000007
int dp[2][max_sqrt_k][2], n, k, sqrt_k, i, j, t, ret, pref, sum0, sum1, count_lr[max_sqrt_k], le, ri, l, p;
void upd (int &a, int b) {
... | not-set | 2016-04-24T02:02:36 | 2016-07-23T15:24:00 | C++ |
52 | 2,293 | p-sequences | P-sequences |
We call a sequence of `N` natural numbers (*a*<sub>1</sub>, *a*<sub>2</sub>, ..., *a*<sub>N</sub>) a *P-sequence*, if the product of any two adjacent numbers in it is not greater than *P*. In other words, if a sequence (*a*<sub>1</sub>, *a*<sub>2</sub>, ..., *a*<sub>N</sub>) is a *P-sequence*, then *a*<sub>i</sub> *... | code | How many sequences of N elements are there if product of two adjacent elements is not greater than P | ai | 2014-03-31T21:26:34 | 2022-08-31T08:14:51 | #
# Complete the 'pSequences' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER p
#
def pSequences(n, p):
# 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())
p = int(input().strip())
result = pSequences(n, p)
fptr.write(str(result) + '\n')
fptr.close()
| We call a sequence of `N` natural numbers (*a*<sub>1</sub>, *a*<sub>2</sub>, ..., *a*<sub>N</sub>) a *P-sequence*, if the product of any two adjacent numbers in it is not greater than *P*. In other words, if a sequence (*a*<sub>1</sub>, *a*<sub>2</sub>, ..., *a*<sub>N</sub>) is a *P-sequence*, then *a*<sub>i</sub> * *a... | 0.550562 | ["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 of input consists of `N`
The second line of the input consists of `P`.
| Output the number of *P-sequences* of `N` integers modulo 10<sup>9</sup>+7.
| 2
2
| 3
| Hard | P-Sequences - Week 1 Editorial | <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-fam... | 0 | w1-p-sequences | 2014-04-24T18:24:07 | {"contest_participation":2214,"challenge_submissions":260,"successful_submissions":117} | 2014-04-24T18:24:07 | 2016-07-23T15:27:56 | tester | ###C++
```cpp
/*
Solution by sdya (Dmytro Soboliev)
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cassert>
using namespace std;
const int P = 1000000007;
const int maxN = 64000;
vector < int > bounds, ways;
int d[2][maxN], add[maxN];... | not-set | 2016-04-24T02:02:36 | 2016-07-23T15:27:56 | C++ |
53 | 2,301 | manasa-and-factorials | Manasa and Factorials |
Manasa was sulking her way through a boring class when suddenly her teacher singled her out and asked her a question. He gave her a number **n** and Manasa has to come up with the smallest number **m** which contains atleast **n** number of zeros at the end of **m!**. Help Manasa come out of the sticky situation.
... | code | Think about number of zeros in k! | ai | 2014-04-04T20:18:51 | 2022-09-02T09:54:31 | #
# Complete the 'solve' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts LONG_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()
|
Manasa was sulking her way through a boring class when suddenly her teacher singled her out and asked her a question. He gave her a number **n** and Manasa has to come up with the smallest number **m** which contains atleast **n** number of zeros at the end of **m!**. Help Manasa come out of the sticky situation.
... | 0.487273 | ["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 | {"contest_participation":1581,"challenge_submissions":287,"successful_submissions":188} | 2014-04-29T17:15:38 | 2016-12-02T22:59:21 | setter | ###C++
```cpp
// Author Amit Pandey
#include<bits/stdc++.h>
using namespace std;
bool check(long long int p, long long int n)
{
long long int temp = p , outp =0, five = 5;
while(five < temp)
{
outp += temp/five;
five = five*5;
// cout<<temp<<" "<<five<<endl;
}
if(outp>= ... | not-set | 2016-04-24T02:02:37 | 2016-07-23T17:34:17 | C++ |
54 | 2,301 | manasa-and-factorials | Manasa and Factorials |
Manasa was sulking her way through a boring class when suddenly her teacher singled her out and asked her a question. He gave her a number **n** and Manasa has to come up with the smallest number **m** which contains atleast **n** number of zeros at the end of **m!**. Help Manasa come out of the sticky situation.
... | code | Think about number of zeros in k! | ai | 2014-04-04T20:18:51 | 2022-09-02T09:54:31 | #
# Complete the 'solve' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts LONG_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()
|
Manasa was sulking her way through a boring class when suddenly her teacher singled her out and asked her a question. He gave her a number **n** and Manasa has to come up with the smallest number **m** which contains atleast **n** number of zeros at the end of **m!**. Help Manasa come out of the sticky situation.
... | 0.487273 | ["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 | {"contest_participation":1581,"challenge_submissions":287,"successful_submissions":188} | 2014-04-29T17:15:38 | 2016-12-02T22:59:21 | tester | ###Python 2
```python
def pcount(p, n):
''' the number of factors p of n! (where p is prime) '''
if n < p:
return 0
return n / p + pcount(p, n / p)
def f(n):
''' Least m such that m! has n trailing zeroes '''
L, R = 0, 5*n
while R - L > 1:
M = L + R >> 1
if pcoun... | not-set | 2016-04-24T02:02:37 | 2016-07-23T17:34:26 | Python |
55 | 2,298 | courier-rank | Courier Rank | CourierRank is a very famous and well established company in the market and well known for transporting products with minimum cost for their customers. Your friend chandu works at CourierRank and is facing a problem these days. You being an excellent programmer and his friend. He asks you to help him with the problem. ... | code | null | ai | 2014-04-03T22:55:02 | 2016-09-09T09:42:08 | null | null | null | CourierRank is a very famous and well established company in the market and well known for transporting products with minimum cost for their customers. Your friend chandu works at CourierRank and is facing a problem these days. You being an excellent programmer and his friend. He asks you to help him with the problem. ... | 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-05-01T07:27:59 | 2016-05-13T00:02:45 | setter | #include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <ctime>
// STL
#define pb push_back
#define LL long long
#define ULL unsig... | not-set | 2016-04-24T02:02:37 | 2016-04-24T02:02:37 | C++ |
56 | 2,475 | sherlock-and-permutations | Sherlock and Permutations |
Watson asks Sherlock:
Given a string _S_ of _N_ `0's` and _M_ `1's`, how many unique permutations of this string start with `1`?
Help Sherlock by printing the answer modulo (_10<sup>9</sup>+7_).
**Input Format**
First line contains _T_, the number of test cases.
Each test case consists of _N_ and _M_ s... | code | Help Sherlock in counting permutations. | ai | 2014-05-01T14:02:20 | 2022-09-02T09:54:12 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER m
#
def solve(n, m):
# 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])
result = solve(n, m)
fptr.wri... | Watson asks Sherlock:
Given a string _S_ of _N_ `0's` and _M_ `1's`, how many unique permutations of this string start with `1`?
Help Sherlock by printing the answer modulo (_10<sup>9</sup>+7_).
**Input Format**
First line contains _T_, the number of test cases.
Each test case consists of _N_ and _M_ sep... | 0.598086 | ["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 | {"contest_participation":922,"challenge_submissions":417,"successful_submissions":322} | 2014-05-21T08:40:53 | 2016-12-02T15:01:16 | setter | ###C++
```cpp
//Language: C++
//Author: darkshadows(Lalit Kundu)
#include<bits/stdc++.h>
#define assn(n,a,b) assert(n<=b && n>=a)
using namespace std;
typedef long long LL;
#define MOD 1000000007
#define MAX 1000033
LL mpow(LL a, LL n)
{
LL ret=1;
LL b=a;
while(n)
{
if(n&1)ret=(ret*b)%... | not-set | 2016-04-24T02:02:39 | 2016-07-23T16:31:46 | C++ | ||||
57 | 2,475 | sherlock-and-permutations | Sherlock and Permutations |
Watson asks Sherlock:
Given a string _S_ of _N_ `0's` and _M_ `1's`, how many unique permutations of this string start with `1`?
Help Sherlock by printing the answer modulo (_10<sup>9</sup>+7_).
**Input Format**
First line contains _T_, the number of test cases.
Each test case consists of _N_ and _M_ s... | code | Help Sherlock in counting permutations. | ai | 2014-05-01T14:02:20 | 2022-09-02T09:54:12 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER m
#
def solve(n, m):
# 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])
result = solve(n, m)
fptr.wri... | Watson asks Sherlock:
Given a string _S_ of _N_ `0's` and _M_ `1's`, how many unique permutations of this string start with `1`?
Help Sherlock by printing the answer modulo (_10<sup>9</sup>+7_).
**Input Format**
First line contains _T_, the number of test cases.
Each test case consists of _N_ and _M_ sep... | 0.598086 | ["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 | {"contest_participation":922,"challenge_submissions":417,"successful_submissions":322} | 2014-05-21T08:40:53 | 2016-12-02T15:01:16 | tester | ###C++
```cpp
//Language: C++
//Author: xorfire(R Goutham)
#include <cstdio>
#include <cassert>
int mod = 1000000007, comb[2001][2001];
int main()
{
// Computing Binomial coefficients
for (int i = 0; i <= 2000; i++)
{
comb[i][0] = comb[i][i] = 1;
for (int j = 1; j < i;... | not-set | 2016-04-24T02:02:39 | 2016-07-23T16:32:55 | C++ | ||||
58 | 2,462 | gcd-product | GCD Product | [Russian](https://hr-filepicker.s3.amazonaws.com/w3/russian/2462-gcd-product.pdf)<br/>
This time your assignment is really simple.
Calculate GCD(1, 1) * GCD(1, 2) * ... * GCD(1, M) * GCD(2, 1) * GCD(2, 2) * ... * GCD(2, M) * ... * GCD(N, 1) * GCD(N, 2) * ... * GCD(N, M).
where GCD is defined as the [Greatest Common... | code | Find the product of the Greatest Common Divisors for all the pairs inside a rectangle. | ai | 2014-04-29T10:32:28 | 2022-09-02T09:54:44 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER m
#
def solve(n, m):
# 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')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
result = solve(n, m)
fptr.write(str(result) + '\n')
fptr.close()
| This time your assignment is really simple.
Calculate GCD(1, 1) * GCD(1, 2) * ... * GCD(1, M) * GCD(2, 1) * GCD(2, 2) * ... * GCD(2, M) * ... * GCD(N, 1) * GCD(N, 2) * ... * GCD(N, M).
where GCD is defined as the [Greatest Common Divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
**Input Format**
The... | 0.426136 | ["c","clojure","cobol","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 | {"contest_participation":1475,"challenge_submissions":236,"successful_submissions":103} | 2014-05-26T14:49:21 | 2016-12-08T09:25:32 | setter | ###C++
```cpp
#include <cstdio>
#include <algorithm>
using namespace std;
#define maxn 15000000 + 5
#define mod 1000000007
#define tm Tm
int n, m, i, j, p[maxn], dp[maxn], sf[maxn], sfn, g, tn, tm, ret, pref[maxn], l, c, p1, p2, r, carry;
long long sfm[maxn], t;
int pw (int x, long long p) {
if (!p) return 1... | not-set | 2016-04-24T02:02:39 | 2016-07-23T18:25:31 | C++ | ||||
59 | 2,462 | gcd-product | GCD Product | [Russian](https://hr-filepicker.s3.amazonaws.com/w3/russian/2462-gcd-product.pdf)<br/>
This time your assignment is really simple.
Calculate GCD(1, 1) * GCD(1, 2) * ... * GCD(1, M) * GCD(2, 1) * GCD(2, 2) * ... * GCD(2, M) * ... * GCD(N, 1) * GCD(N, 2) * ... * GCD(N, M).
where GCD is defined as the [Greatest Common... | code | Find the product of the Greatest Common Divisors for all the pairs inside a rectangle. | ai | 2014-04-29T10:32:28 | 2022-09-02T09:54:44 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER m
#
def solve(n, m):
# 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')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
result = solve(n, m)
fptr.write(str(result) + '\n')
fptr.close()
| This time your assignment is really simple.
Calculate GCD(1, 1) * GCD(1, 2) * ... * GCD(1, M) * GCD(2, 1) * GCD(2, 2) * ... * GCD(2, M) * ... * GCD(N, 1) * GCD(N, 2) * ... * GCD(N, M).
where GCD is defined as the [Greatest Common Divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
**Input Format**
The... | 0.426136 | ["c","clojure","cobol","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 | {"contest_participation":1475,"challenge_submissions":236,"successful_submissions":103} | 2014-05-26T14:49:21 | 2016-12-08T09:25:32 | tester | ###C++
```cpp
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <vector>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <numeric>
#include <iomanip>
#include <sstream>
#inc... | not-set | 2016-04-24T02:02:39 | 2016-07-23T18:25:38 | C++ | ||||
60 | 2,560 | palindrome-test | Palindrome Test | Palindrome blablabla
Ecrire programme blabla langage blabla
Verifier chaine blabla.
Entrée :
la chaine (String)
Sortie :
booléen | code | Vérifier que le mot est un palindrome | ai | 2014-05-28T11:15:53 | 2016-09-09T09:43:55 | null | null | null | Palindrome blablabla
Ecrire programme blabla langage blabla
Verifier chaine blabla.
Entrée :
la chaine (String)
Sortie :
booléen | 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-05-28T11:40:26 | 2016-05-13T00:02:19 | setter | hello | not-set | 2016-04-24T02:02:40 | 2016-04-24T02:02:40 | Unknown |
61 | 2,560 | palindrome-test | Palindrome Test | Palindrome blablabla
Ecrire programme blabla langage blabla
Verifier chaine blabla.
Entrée :
la chaine (String)
Sortie :
booléen | code | Vérifier que le mot est un palindrome | ai | 2014-05-28T11:15:53 | 2016-09-09T09:43:55 | null | null | null | Palindrome blablabla
Ecrire programme blabla langage blabla
Verifier chaine blabla.
Entrée :
la chaine (String)
Sortie :
booléen | 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-05-28T11:40:26 | 2016-05-13T00:02:19 | tester | Hello tester | not-set | 2016-04-24T02:02:40 | 2016-04-24T02:02:40 | Unknown |
62 | 2,491 | sherlock-and-minimax | Sherlock and MiniMax | [Русский](https://hr-filepicker.s3.amazonaws.com/101may14/russian/2491-sherlock-and-minimax.pdf) \|
[中文](https://hr-filepicker.s3.amazonaws.com/101may14/chinese/2491-sherlock-and-minimax.pdf)<br/>
Watson gives Sherlock an array _A<sub>1</sub>,A<sub>2</sub>...A<sub>N</sub>_.
He asks him to find an integer _M_ betwe... | code | Watson gives Sherlock an array A1,A2...AN. Find an integer M
between P and Q(both inclusive), satistying a condition. | ai | 2014-05-06T18:57:55 | 2022-08-31T08:14:38 | #
# Complete the 'sherlockAndMinimax' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER_ARRAY arr
# 2. INTEGER p
# 3. INTEGER q
#
def sherlockAndMinimax(arr, p, q):
# 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()))
first_multiple_input = input().rstrip().split()
p = int(first_multiple_input[0])
q = int(first_multiple_input[1])
result = sherlockAndMinimax(a... | Watson gives Sherlock an array of integers. Given the endpoints of an integer range, for all $M$ in that inclusive range, determine the minimum( abs(arr[i]-M) for all $1 \le i \le |arr|$) ). Once that has been determined for all integers in the range, return the $M$ which generated the maximum of those values. If th... | 0.541436 | ["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 elements in $arr$.
The next line contains $n$ space-separated integers $arr[i]$.
The third line contains two space-separated integers $p$ and $q$, the inclusive endpoints for the range of $M$.
| Print the value of $M$ on a line. | 3
5 8 14
4 9
| 4
| Hard | null | null | null | null | null | {"contest_participation":1164,"challenge_submissions":299,"successful_submissions":128} | 2014-05-30T22:31:21 | 2018-04-17T13:18:01 | setter | ###C++
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[109];
int A, B;
int answer;
//returns the value to be maximised if M=x
int check( int x )
{
int ret = INT_MAX;
for( int i = 0; i < n; ++i )
ret =min(ret, abs( x- arr[i] ));
return ret;
}
// check is x is within limits and i... | not-set | 2016-04-24T02:02:40 | 2016-07-23T14:21:41 | C++ |
63 | 2,491 | sherlock-and-minimax | Sherlock and MiniMax | [Русский](https://hr-filepicker.s3.amazonaws.com/101may14/russian/2491-sherlock-and-minimax.pdf) \|
[中文](https://hr-filepicker.s3.amazonaws.com/101may14/chinese/2491-sherlock-and-minimax.pdf)<br/>
Watson gives Sherlock an array _A<sub>1</sub>,A<sub>2</sub>...A<sub>N</sub>_.
He asks him to find an integer _M_ betwe... | code | Watson gives Sherlock an array A1,A2...AN. Find an integer M
between P and Q(both inclusive), satistying a condition. | ai | 2014-05-06T18:57:55 | 2022-08-31T08:14:38 | #
# Complete the 'sherlockAndMinimax' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER_ARRAY arr
# 2. INTEGER p
# 3. INTEGER q
#
def sherlockAndMinimax(arr, p, q):
# 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()))
first_multiple_input = input().rstrip().split()
p = int(first_multiple_input[0])
q = int(first_multiple_input[1])
result = sherlockAndMinimax(a... | Watson gives Sherlock an array of integers. Given the endpoints of an integer range, for all $M$ in that inclusive range, determine the minimum( abs(arr[i]-M) for all $1 \le i \le |arr|$) ). Once that has been determined for all integers in the range, return the $M$ which generated the maximum of those values. If th... | 0.541436 | ["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 elements in $arr$.
The next line contains $n$ space-separated integers $arr[i]$.
The third line contains two space-separated integers $p$ and $q$, the inclusive endpoints for the range of $M$.
| Print the value of $M$ on a line. | 3
5 8 14
4 9
| 4
| Hard | null | null | null | null | null | {"contest_participation":1164,"challenge_submissions":299,"successful_submissions":128} | 2014-05-30T22:31:21 | 2018-04-17T13:18:01 | tester | ###C++
```cpp
//C++ Code
Author Gerald
#ifdef ssu1
#define _GLIBCXX_DEBUG
#endif
#undef NDEBUG
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <vector>
#include <lis... | not-set | 2016-04-24T02:02:40 | 2016-07-23T14:24:58 | C++ |
64 | 2,413 | roy-and-alpha-beta-trees | Roy and alpha-beta trees | [Russian](https://hr-filepicker.s3.amazonaws.com/w4/russian/2413-roy-and-alpha-beta-trees.pdf)<br/>
Roy has taken a liking to the [Binary Search Trees](https://en.wikipedia.org/wiki/Binary_search_tree)(*BST*). He is interested in knowing the number of ways an array *A* of *N* integers can be arranged to form a *BST*.... | code | Can you calculate the sum of Liking of all possible BST's that can be formed from an array of N integers. | ai | 2014-04-21T11:02:40 | 2022-09-02T10:00:36 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER alpha
# 2. INTEGER beta
# 3. INTEGER_ARRAY a
#
def solve(alpha, beta, 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):
n = int(input().strip())
first_multiple_input = input().rstrip().split()
alpha = int(first_multiple_input[0])
beta = int(first_multiple_input[1])
... | Roy has taken a liking to the [Binary Search Trees](https://en.wikipedia.org/wiki/Binary_search_tree)(*BST*). He is interested in knowing the number of ways an array $A$ of $N$ integers can be arranged to form a *BST*. Thus, he tries a few combinations, and notes down the numbers at the odd levels and the numbers at th... | 0.578431 | ["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 | {"contest_participation":1868,"challenge_submissions":144,"successful_submissions":109} | 2014-06-01T21:08:38 | 2016-12-02T07:25:09 | setter |
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
class ANKBST02_solver {
long go(int lo, int hi, int odd) {
if (lo > hi) {
return 0;
}
if (dp[lo][hi][odd] == -1) {
long ans = 0;
for ... | not-set | 2016-04-24T02:02:40 | 2016-04-24T02:02:40 | Python | ||||
65 | 2,212 | rooted-tree | Rooted Tree | [Русский](https://hr-filepicker.s3.amazonaws.com/101may14/russian/2212-rooted_tree.pdf) \|
[中文](https://hr-filepicker.s3.amazonaws.com/101may14/chinese/2212-rooted_tree.pdf)<br/>
You are given a rooted [tree](http://en.wikipedia.org/wiki/Tree_(graph_theory)) with _N_ nodes and the root of the tree, _R_, is also given.... | code | Maintain the given tree under Update and Query operations. | ai | 2014-03-23T14:11:05 | 2022-08-31T08:33:19 | null | null | null | You are given a rooted [tree](http://en.wikipedia.org/wiki/Tree_(graph_theory)) with _N_ nodes and the root of the tree, _R_, is also given. Each node of the tree contains a value, that is initially empty. You have to mantain the tree under two operations:
1. Update Operation
2. Report Operation
**Update Operation** ... | 0.423729 | ["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"... | Hard | null | null | null | null | null | {"contest_participation":1164,"challenge_submissions":30,"successful_submissions":9} | 2014-06-02T06:04:31 | 2016-12-01T20:38:59 | setter | #include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<bitset>
#include<queue>
#include<stack>
#include<assert.h>
using namespace std;
#define mod... | not-set | 2016-04-24T02:02:40 | 2016-04-24T02:02:40 | C++ | ||||
66 | 2,212 | rooted-tree | Rooted Tree | [Русский](https://hr-filepicker.s3.amazonaws.com/101may14/russian/2212-rooted_tree.pdf) \|
[中文](https://hr-filepicker.s3.amazonaws.com/101may14/chinese/2212-rooted_tree.pdf)<br/>
You are given a rooted [tree](http://en.wikipedia.org/wiki/Tree_(graph_theory)) with _N_ nodes and the root of the tree, _R_, is also given.... | code | Maintain the given tree under Update and Query operations. | ai | 2014-03-23T14:11:05 | 2022-08-31T08:33:19 | null | null | null | You are given a rooted [tree](http://en.wikipedia.org/wiki/Tree_(graph_theory)) with _N_ nodes and the root of the tree, _R_, is also given. Each node of the tree contains a value, that is initially empty. You have to mantain the tree under two operations:
1. Update Operation
2. Report Operation
**Update Operation** ... | 0.423729 | ["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"... | Hard | null | null | null | null | null | {"contest_participation":1164,"challenge_submissions":30,"successful_submissions":9} | 2014-06-02T06:04:31 | 2016-12-01T20:38:59 | tester | #ifdef ssu1
#define _GLIBCXX_DEBUG
#endif
#undef NDEBUG
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <ve... | not-set | 2016-04-24T02:02:40 | 2016-04-24T02:02:40 | C++ | ||||
67 | 2,523 | easy-sum | Easy sum | Little Kevin had never heard the word 'Infinitum'. So he asked his mentor to explain the word to him. His mentor knew that 'Infinitum' is a very large number. To show him how big [Infinitum](http://en.wikipedia.org/wiki/Ad_infinitum) can be, his mentor gave him a challenge: to sum the numbers from _1_ up to _N_. The su... | code | Find the mod sum | ai | 2014-05-14T04:26:01 | 2022-09-02T09:55:04 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER m
#
def solve(n, m):
# 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])
result = solve(n, m)
fptr.wri... | Little Kevin had never heard the word 'Infinitum'. So he asked his mentor to explain the word to him. His mentor knew that 'Infinitum' is a very large number. To show him how big [Infinitum](http://en.wikipedia.org/wiki/Ad_infinitum) can be, his mentor gave him a challenge: to sum the numbers from _1_ up to _N_. The su... | 0.597523 | ["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 | {"contest_participation":2021,"challenge_submissions":1071,"successful_submissions":793} | 2014-06-02T11:02:56 | 2016-12-07T10:25:14 | setter | ###Python 2
```python
for _ in range(input()):
N,M = [int(x) for x in raw_input().split()]
k = N%M
print (M-1)*(M)/2*(N/M) + k*(k+1)/2
```
| not-set | 2016-04-24T02:02:40 | 2016-07-23T18:55:35 | Python |
68 | 2,523 | easy-sum | Easy sum | Little Kevin had never heard the word 'Infinitum'. So he asked his mentor to explain the word to him. His mentor knew that 'Infinitum' is a very large number. To show him how big [Infinitum](http://en.wikipedia.org/wiki/Ad_infinitum) can be, his mentor gave him a challenge: to sum the numbers from _1_ up to _N_. The su... | code | Find the mod sum | ai | 2014-05-14T04:26:01 | 2022-09-02T09:55:04 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER m
#
def solve(n, m):
# 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])
result = solve(n, m)
fptr.wri... | Little Kevin had never heard the word 'Infinitum'. So he asked his mentor to explain the word to him. His mentor knew that 'Infinitum' is a very large number. To show him how big [Infinitum](http://en.wikipedia.org/wiki/Ad_infinitum) can be, his mentor gave him a challenge: to sum the numbers from _1_ up to _N_. The su... | 0.597523 | ["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 | {"contest_participation":2021,"challenge_submissions":1071,"successful_submissions":793} | 2014-06-02T11:02:56 | 2016-12-07T10:25:14 | tester | ###Python 2
```python
for c in xrange(input()):print(lambda N,m:N/m*m*(m-1)/2+(N%m*2+1)**2/8)(*map(int,raw_input().split()))
```
| not-set | 2016-04-24T02:02:40 | 2016-07-23T18:56:00 | Python |
69 | 1,636 | crush | Array Manipulation | [Russian](https://hr-filepicker.s3.amazonaws.com/w4/russian/1636-crush.pdf)<br/>
Devendra is on cloud nine after seeing his crush smiling at him in class. At that very moment his professor singles him out and asks him a question. Devendra's mind is all too fuzzy with his crush and her smile to concentrate on anything... | code | Perform m operations on an array and print the maximum of the values. | ai | 2014-01-09T11:29:47 | 2022-09-02T09:59:47 | #
# Complete the 'arrayManipulation' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. 2D_INTEGER_ARRAY queries
#
def arrayManipulation(n, queries):
# 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')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
queries = []
for _ in range(m):
queries.append(list(map(int, input().rstrip().split())))
resu... | Starting with a 1-indexed array of zeros and a list of operations, for each operation add a value to each the array element between two given indices, inclusive. Once all operations have been performed, return the maximum value in the array.
**Example**
$n = 10$
$queries = [[1, 5, 3], [4, 8, 7], [6, 9, 1]$
Q... | 0.504803 | ["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"] | The first line contains two space-separated integers $n$ and $m$, the size of the array and the number of operations.
Each of the next $m$ lines contains three space-separated integers $a$, $b$ and $k$, the left index, right index and summand. | 5 3
1 2 100
2 5 100
3 4 100
| 200
| Hard | null | null | null | null | null | {"contest_participation":1783,"challenge_submissions":658,"successful_submissions":361} | 2014-06-03T07:16:46 | 2020-09-08T16:59:12 | setter | ```cpp
#include <bits/stdc++.h>
using namespace std;
long a[400009];
int main() {
int n;
int m;
cin >> n >> m;
vector < pair < int, int > > v;
for(int a0 = 0; a0 < m; a0++) {
int a;
int b;
int k;
cin >> a >> b >> k;
//storing the quer... | not-set | 2016-04-24T02:02:40 | 2018-07-18T10:50:18 | C++ | |
70 | 1,636 | crush | Array Manipulation | [Russian](https://hr-filepicker.s3.amazonaws.com/w4/russian/1636-crush.pdf)<br/>
Devendra is on cloud nine after seeing his crush smiling at him in class. At that very moment his professor singles him out and asks him a question. Devendra's mind is all too fuzzy with his crush and her smile to concentrate on anything... | code | Perform m operations on an array and print the maximum of the values. | ai | 2014-01-09T11:29:47 | 2022-09-02T09:59:47 | #
# Complete the 'arrayManipulation' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. 2D_INTEGER_ARRAY queries
#
def arrayManipulation(n, queries):
# 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')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
queries = []
for _ in range(m):
queries.append(list(map(int, input().rstrip().split())))
resu... | Starting with a 1-indexed array of zeros and a list of operations, for each operation add a value to each the array element between two given indices, inclusive. Once all operations have been performed, return the maximum value in the array.
**Example**
$n = 10$
$queries = [[1, 5, 3], [4, 8, 7], [6, 9, 1]$
Q... | 0.504803 | ["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"] | The first line contains two space-separated integers $n$ and $m$, the size of the array and the number of operations.
Each of the next $m$ lines contains three space-separated integers $a$, $b$ and $k$, the left index, right index and summand. | 5 3
1 2 100
2 5 100
3 4 100
| 200
| Hard | null | null | null | null | null | {"contest_participation":1783,"challenge_submissions":658,"successful_submissions":361} | 2014-06-03T07:16:46 | 2020-09-08T16:59:12 | tester | ```python
def arrayManipulation(n, queries):
arr = [0] * (n+1)
# add the value at first index
# subtract the value at last index + 1
for q in queries:
start, end, amt = q
arr[start-1] += amt
arr[end] -= amt
# max value and running sum
mv = -1
running = 0
for a in... | not-set | 2016-04-24T02:02:40 | 2020-09-08T16:59:12 | Python | |
71 | 472 | print | Difficult Printer | There are N printers and you have M papers to print. But every paper has a diffculty value (indicated by d[i]), and every printer has an ability value (indicated by a[j]). The printer j can print the paper i, iff a[j] >= d[i].
It takes one second for a printer to print a paper (if it's possible to print that is). Yo... | code | null | ai | 2013-03-11T17:19:00 | 2016-09-09T09:29:21 | null | null | null | There are N printers and you have M papers to print. But every paper has a diffculty value (indicated by d[i]), and every printer has an ability value (indicated by a[j]). The printer j can print the paper i, iff a[j] >= d[i].
It takes one second for a printer to print a paper (if it's possible to print that is). Yo... | 0.592 | ["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-06-03T14:05:30 | 2017-04-13T02:32:24 | tester | #include <bits/stdc++.h>
using namespace std;
int nPrinters, nPapers;
vector <int> a, d;
bool canSolveWithin(int maxTime) {
int printerIdx = 0, paperIdx = 0;
while(printerIdx < nPrinters && paperIdx < nPapers) {
int curTime = 0;
while(paperIdx < nPapers && cur... | not-set | 2016-04-24T02:02:40 | 2016-04-24T02:02:40 | C++ |
72 | 2,572 | gifts | Gifts | In order to transform her student into the perfect knight, Shaina has given to Koga the best possible gifts for a saint: a bunch of scrolls that contains all ancient techniques discovered by older saints.
Shaina said:
> Listen carefully Koga, here you have all the attack techniques from all the Athena's Saints - Bro... | code | From these gifts, what's the best you can do? | ai | 2014-06-03T18:11:32 | 2019-07-02T13:58:34 | null | null | null | Shaina has given to her student, Koga, a bunch of scrolls, some instructions to remember while learning the techniques described in the scrolls, and some stones that will multiply the power of the techniques. The instructions are as follows:
1. He has to master all the Bronze, Silver, and Gold Saints techniques... | 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"] | Input begins with a line containing three integers, $B$, $S$, and $G$, separated by a single white space, denoting we have $B$, $S$, and $G$ bronze, silver, and gold scrolls, respectively. $B + S + G$ lines follow, each one with some integer saying the power of some technique: first $B$ belong to bronze's, next $S$ bel... | Output just one line with a single integer: the largest possible sum you can get from learning the techniques with the restrictions mentioned above. **Remember that you must pick the outer techniques from each type first and, yes, don't forget to properly use the stones :)**
The output will always fit in a **32-bit si... | 2 2 2
4
1
2
3
5
6
1
2
3
4
5
6 | 91 | Hard | null | null | null | null | null | null | 2014-06-03T20:56:00 | 2017-02-12T04:14:52 | setter | //============================================================================
// Name : GIFTS.cpp
// Author : Shaka
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
... | not-set | 2016-04-24T02:02:40 | 2016-04-24T02:02:40 | C++ |
73 | 2,561 | dance-class | Dancing in Pairs | Bob is a dance teacher and he started dance classes recently. He observes a strange attendance pattern among his students. Initially, there are no students. On day *i*, a new student starts attending the class. The student stops attending the class, if and only if he has attended the class for _i_ consecutive days.
Al... | code | Find out if they can dance in pairs? | ai | 2014-05-29T07:35:20 | 2022-09-02T09:54:27 | #
# Complete the 'solve' function below.
#
# The function is expected to return a STRING.
# The function accepts LONG_INTEGER i as parameter.
#
def solve(i):
# 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):
i = int(input().strip())
result = solve(i)
fptr.write(result + '\n')
fptr.close()
| Bob is a dance teacher and he started dance classes recently. He observes a strange attendance pattern among his students. Initially, there are no students. On day *i*, a new student starts attending the class. The student stops attending the class, if and only if he has attended the class for _i_ consecutive days.
Al... | 0.580645 | ["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 | {"contest_participation":2021,"challenge_submissions":338,"successful_submissions":195} | 2014-06-09T09:29:38 | 2016-12-03T09:20:56 | setter | ###Python 2
```python
import fileinput
n=0
for line in fileinput.input():
t=int(line)
if n>0:
p=1
q=10**9+1
while q-p>=2:
mi=(p+q)/2
if mi**2>t:
q=mi
else:
p=mi
ans=p
if ans%2==1:
print 'o... | not-set | 2016-04-24T02:02:41 | 2016-07-23T17:55:14 | Python |
74 | 2,561 | dance-class | Dancing in Pairs | Bob is a dance teacher and he started dance classes recently. He observes a strange attendance pattern among his students. Initially, there are no students. On day *i*, a new student starts attending the class. The student stops attending the class, if and only if he has attended the class for _i_ consecutive days.
Al... | code | Find out if they can dance in pairs? | ai | 2014-05-29T07:35:20 | 2022-09-02T09:54:27 | #
# Complete the 'solve' function below.
#
# The function is expected to return a STRING.
# The function accepts LONG_INTEGER i as parameter.
#
def solve(i):
# 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):
i = int(input().strip())
result = solve(i)
fptr.write(result + '\n')
fptr.close()
| Bob is a dance teacher and he started dance classes recently. He observes a strange attendance pattern among his students. Initially, there are no students. On day *i*, a new student starts attending the class. The student stops attending the class, if and only if he has attended the class for _i_ consecutive days.
Al... | 0.580645 | ["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 | {"contest_participation":2021,"challenge_submissions":338,"successful_submissions":195} | 2014-06-09T09:29:38 | 2016-12-03T09:20:56 | tester | ###Python 2
```python
from decimal import Decimal as D
for cas in range(input()):print["even","odd"][int(D(input()).sqrt())&1]
```
| not-set | 2016-04-24T02:02:41 | 2016-07-23T17:55:35 | Python |
75 | 2,339 | permutation-problem | Permutation Problem | How many n-digit numbers (without leading zeros) are there such that no digit occurs more than k times?
As the count of such n-digit numbers can be very large, print the answer mod (10<sup>9</sup>+7)
**Input Format**
The first line contains an integer, _T_ , the number of test cases. This is followed by _T_ li... | code | Find the number of n digit numbers | ai | 2014-04-10T09:15:12 | 2022-09-02T09:54:56 | #
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER k
#
def solve(n, k):
# 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])
k = int(first_multiple_input[1])
result = solve(n, k)
fptr.wri... | How many n-digit numbers (without leading zeros) are there such that no digit occurs more than k times?
As the count of such n-digit numbers can be very large, print the answer mod (10<sup>9</sup>+7)
**Input Format**
The first line contains an integer, _T_ , the number of test cases. This is followed by _T_ li... | 0.469388 | ["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 | {"contest_participation":2021,"challenge_submissions":165,"successful_submissions":54} | 2014-06-09T09:30:00 | 2016-12-06T19:43:26 | tester | ###C++
```cpp
#include <stdio.h>
#include <stdlib.h>
#define mod 1000000007
#define min(a,b) ((a)<(b)?(a):(b))
#define LIM 1000
#define ull unsigned long long
#define _9_10 300000003 // (9/10'ths mod 10^9+7)
ull fac[LIM+1];
ull ifc[LIM+1];
ull **F[11];
int main() {
// precalculate factorials and inverse facto... | not-set | 2016-04-24T02:02:41 | 2016-07-23T18:38:08 | C++ | ||||
76 | 2,557 | kundu-and-tree | Kundu and Tree | Kundu is true tree lover. Tree is a connected graph having _N_ vertices and _N-1_ edges. Today when he got a tree, he colored each edge with one of either red(`r`) or black(`b`) color. He is interested in knowing how many triplets(a,b,c) of vertices are there , such that, there is atleast one edge having red color on ... | code | Find the number of triplets (a,b,c) such that atleast one edge is colored red on all the three paths. | ai | 2014-05-28T05:49:51 | 2022-08-31T08:33:12 | null | null | null | Kundu is true tree lover. Tree is a connected graph having _N_ vertices and _N-1_ edges. Today when he got a tree, he colored each edge with one of either red(`r`) or black(`b`) color. He is interested in knowing how many triplets(a,b,c) of vertices are there , such that, there is atleast one edge having red color on ... | 0.465839 | ["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"... | Hard | null | null | null | null | null | {"contest_participation":3,"challenge_submissions":0,"successful_submissions":0} | 2014-06-12T12:50:12 | 2016-12-02T11:13:36 | setter | #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define s(a) scanf("%d",&a);
vector<int> edges[100009];
long long int visited[100009];
long long int count1[100009];
long long int B[100009],C[100009],D[100009];
void dfs(int x, int temp)
{
if(visite... | not-set | 2016-04-24T02:02:41 | 2016-04-24T02:02:41 | C++ | ||||
77 | 2,557 | kundu-and-tree | Kundu and Tree | Kundu is true tree lover. Tree is a connected graph having _N_ vertices and _N-1_ edges. Today when he got a tree, he colored each edge with one of either red(`r`) or black(`b`) color. He is interested in knowing how many triplets(a,b,c) of vertices are there , such that, there is atleast one edge having red color on ... | code | Find the number of triplets (a,b,c) such that atleast one edge is colored red on all the three paths. | ai | 2014-05-28T05:49:51 | 2022-08-31T08:33:12 | null | null | null | Kundu is true tree lover. Tree is a connected graph having _N_ vertices and _N-1_ edges. Today when he got a tree, he colored each edge with one of either red(`r`) or black(`b`) color. He is interested in knowing how many triplets(a,b,c) of vertices are there , such that, there is atleast one edge having red color on ... | 0.465839 | ["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"... | Hard | null | null | null | null | null | {"contest_participation":3,"challenge_submissions":0,"successful_submissions":0} | 2014-06-12T12:50:12 | 2016-12-02T11:13:36 | tester | // When I wrote this, only God and I understood what I was doing
// Now, God only knows
#include<bits/stdc++.h>
using namespace std;
#define assn(n,a,b) assert(n<=b && n>=a)
#define pb push_back
typedef vector<int> VI;
typedef long long LL;
#define MOD 1000000007
LL mpow(LL a, L... | not-set | 2016-04-24T02:02:41 | 2016-04-24T02:02:41 | Go | ||||
78 | 104 | median | Median Updates | The median of *M* numbers is defined as the middle number after sorting them in order, if *M* is odd. Or it is the average of the middle 2 numbers (again after sorting), if *M* is even. You have an empty number list at first. Then you can add in or remove some number from the list. For each add or remove operation, out... | code | Return the median after each number is added to a list. | algorithm | 2013-01-04T20:28:56 | 2022-08-31T08:33:08 | #!/bin/python
def median(a,x):
N = int(input())
s = []
x = []
for i in range(0, N):
tmp = input().strip().split(' ')
a, b = [xx for xx in tmp]
s.append(a)
x.append(int(b))
median(s,x)
| null | null | The median of $M$ numbers is defined as the middle number after sorting them in order if $M$ is odd. Or it is the average of the middle two numbers if $M$ is even. You start with an empty number list. Then, you can add numbers to the list, or remove existing numbers from it. After each add or remove operation, output t... | 0.418014 | ["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"... | Hard | null | null | null | null | null | null | 2014-06-16T10:15:13 | 2016-12-01T23:14:40 | setter | #include <cstdio>
#include <set>
#include <cstring>
#include <string>
using namespace std;
multiset<int> s1,s2; //0<=|s1|-|s2|<=1
char s[55];
void gao() {
int a,b;
bool f1,f2;
if (s1.empty()) {
puts("Wrong!");
return;
}
if (s1.... | not-set | 2016-04-24T02:02:41 | 2016-04-24T02:02:41 | C++ | ||||
79 | 104 | median | Median Updates | The median of *M* numbers is defined as the middle number after sorting them in order, if *M* is odd. Or it is the average of the middle 2 numbers (again after sorting), if *M* is even. You have an empty number list at first. Then you can add in or remove some number from the list. For each add or remove operation, out... | code | Return the median after each number is added to a list. | algorithm | 2013-01-04T20:28:56 | 2022-08-31T08:33:08 | #!/bin/python
def median(a,x):
N = int(input())
s = []
x = []
for i in range(0, N):
tmp = input().strip().split(' ')
a, b = [xx for xx in tmp]
s.append(a)
x.append(int(b))
median(s,x)
| null | null | The median of $M$ numbers is defined as the middle number after sorting them in order if $M$ is odd. Or it is the average of the middle two numbers if $M$ is even. You start with an empty number list. Then, you can add numbers to the list, or remove existing numbers from it. After each add or remove operation, output t... | 0.418014 | ["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"... | Hard | null | null | null | null | null | null | 2014-06-16T10:15:13 | 2016-12-01T23:14:40 | tester |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef pair< int , int > pii;
int main() {
int t;
cin>>t;
char c;
int n;
int insert_counter = 0;
... | not-set | 2016-04-24T02:02:41 | 2016-04-24T02:02:41 | C++ | ||||
80 | 2,581 | even-odd-query | Even Odd Query | You are given an array *A* of size *N*. You are also given an integer *Q*. Can you figure out the answer to each of the *Q* queries?
Each query contains 2 integers x and y, and you need to find whether the value find(x,y) is Odd or Even:
find(int x,int y)
{
if(x>y) return 1;
ans = pow(A[x],find(x... | code | Is the number odd or even? | ai | 2014-06-08T11:37:31 | 2022-09-02T09:54:12 | #
# Complete the 'solve' function below.
#
# The function is expected to return a STRING_ARRAY.
# The function accepts following parameters:
# 1. INTEGER_ARRAY arr
# 2. 2D_INTEGER_ARRAY queries
#
def solve(arr, queries):
# 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')
arr_count = int(input().strip())
arr = list(map(int, input().rstrip().split()))
q = int(input().strip())
queries = []
for _ in range(q):
queries.append(list(map(int, input().rstrip().split())))
result = solv... | You are given an array *A* of size *N*. You are also given an integer *Q*. Can you figure out the answer to each of the *Q* queries?
Each query contains 2 integers x and y, and you need to find whether the value find(x,y) is Odd or Even:
find(int x,int y)
{
if(x>y) return 1;
ans = pow(A[x],find(x... | 0.551471 | ["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 | {"contest_participation":2182,"challenge_submissions":916,"successful_submissions":579} | 2014-06-18T06:05:31 | 2016-12-05T12:34:41 | setter | ###C++
```cpp
#include<stdio.h>
#include<assert.h>
#define MaxN 100000
int A[MaxN+1];
int main()
{
int N,Q,x,y,last=1,flip;
scanf("%d",&N);
for(int i=1;i<=N;i++){
scanf("%d",&A[i]);
assert(0 <= A[i] && A[i]<=9);
assert(!(last==0 && last==A[i]));
last=A[i];
}
scanf... | not-set | 2016-04-24T02:02:42 | 2016-07-23T16:31:21 | C++ |
81 | 2,581 | even-odd-query | Even Odd Query | You are given an array *A* of size *N*. You are also given an integer *Q*. Can you figure out the answer to each of the *Q* queries?
Each query contains 2 integers x and y, and you need to find whether the value find(x,y) is Odd or Even:
find(int x,int y)
{
if(x>y) return 1;
ans = pow(A[x],find(x... | code | Is the number odd or even? | ai | 2014-06-08T11:37:31 | 2022-09-02T09:54:12 | #
# Complete the 'solve' function below.
#
# The function is expected to return a STRING_ARRAY.
# The function accepts following parameters:
# 1. INTEGER_ARRAY arr
# 2. 2D_INTEGER_ARRAY queries
#
def solve(arr, queries):
# 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')
arr_count = int(input().strip())
arr = list(map(int, input().rstrip().split()))
q = int(input().strip())
queries = []
for _ in range(q):
queries.append(list(map(int, input().rstrip().split())))
result = solv... | You are given an array *A* of size *N*. You are also given an integer *Q*. Can you figure out the answer to each of the *Q* queries?
Each query contains 2 integers x and y, and you need to find whether the value find(x,y) is Odd or Even:
find(int x,int y)
{
if(x>y) return 1;
ans = pow(A[x],find(x... | 0.551471 | ["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 | {"contest_participation":2182,"challenge_submissions":916,"successful_submissions":579} | 2014-06-18T06:05:31 | 2016-12-05T12:34:41 | tester | ###C++
```cpp
#include <bits/stdc++.h>
using namespace std;
int A[100008], N;
int find(int x, int y){
if(A[x]%2) return 1;
if(x == y) return 0;
if(A[x+1] == 0) return 1;
return 0;
}
int main(){
int x,y,Q;
cin >> N;
for(int i = 1; i <= N; i++) cin >> A[i];
cin >> Q;
while(Q--){
... | not-set | 2016-04-24T02:02:42 | 2016-07-23T16:31:28 | C++ |
82 | 3,092 | reverse-trip-to-jerusalem | Reverse Trip to Jerusalem | You and your $N-1$ friends recently got tired of playing Trip to Jerusalem (i.e. Musical Chairs). In order to make things interesting again, you decide to invent a new game. And you call it *Reverse Trip to Jerusalem*.
Here's how it works. Instead of arranging the chairs in a circle, the $N$ friends (including you) ar... | code | Winning in Trip to Jerusalem is so two thousand and late. Winning Reverse Trip to Jerusalem is what matters. | ai | 2014-06-19T02:26:40 | 2018-03-13T12:03:35 | null | null | null | You and your $N-1$ friends recently got tired of playing Trip to Jerusalem (i.e. Musical Chairs). In order to make things interesting again, you decide to invent a new game. And you call it *Reverse Trip to Jerusalem*.
Here's how it works. Instead of arranging the chairs in a circle, the $N$ friends (including you) ar... | 0.5 | ["c","cpp","java","python3","python","cpp14"] | Hard | null | null | null | null | null | {"contest_participation":83,"challenge_submissions":12,"successful_submissions":4} | 2014-06-21T10:01:03 | 2018-02-06T18:33:47 | setter | ```cpp
#include <stdio.h>
#include <stdlib.h>
struct tree {
int count; // how many are alive at this tree
int l; // leftmost index
tree *parent;
tree *left;
tree *right;
};
int n;
tree *root;
tree *curr;
tree *leftmost() {
// find the leftmost alive leaf
tree *t = root;
while (t->left... | not-set | 2016-04-24T02:02:42 | 2018-02-06T17:55:02 | C++ | ||||
83 | 3,092 | reverse-trip-to-jerusalem | Reverse Trip to Jerusalem | You and your $N-1$ friends recently got tired of playing Trip to Jerusalem (i.e. Musical Chairs). In order to make things interesting again, you decide to invent a new game. And you call it *Reverse Trip to Jerusalem*.
Here's how it works. Instead of arranging the chairs in a circle, the $N$ friends (including you) ar... | code | Winning in Trip to Jerusalem is so two thousand and late. Winning Reverse Trip to Jerusalem is what matters. | ai | 2014-06-19T02:26:40 | 2018-03-13T12:03:35 | null | null | null | You and your $N-1$ friends recently got tired of playing Trip to Jerusalem (i.e. Musical Chairs). In order to make things interesting again, you decide to invent a new game. And you call it *Reverse Trip to Jerusalem*.
Here's how it works. Instead of arranging the chairs in a circle, the $N$ friends (including you) ar... | 0.5 | ["c","cpp","java","python3","python","cpp14"] | Hard | null | null | null | null | null | {"contest_participation":83,"challenge_submissions":12,"successful_submissions":4} | 2014-06-21T10:01:03 | 2018-02-06T18:33:47 | tester | ```cpp
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
int f[200010];
int main() {
int n;
scanf("%d",&n);
for (int i = 0; i + 1 < n; ++i) {
scanf("%d",f + i);
}
int x = 0;
for (int i = 2; i <= n; ++i) {
x = (x + f[n... | not-set | 2016-04-24T02:02:42 | 2018-02-06T17:55:02 | C++ | ||||
84 | 2,579 | messy-medians | Messy Medians | Robin is stuck doing a terminally boring data entry job. She has to enter a lot of numeric observations manually and report running medians after each step to her project lead. The task is sufficiently mind-numbing for her to make a lot of entry errors. Fortunately, she has a keen eye and often notices her mistakes. On... | code | (Add|Remove|getMedian) | ai | 2014-06-05T17:02:31 | 2016-09-01T16:22:55 | null | null | null | Robin is stuck doing a terminally boring data entry job. She has to enter a lot of numeric observations manually and report running medians after each step to her project lead. The task is sufficiently mind-numbing for her to make a lot of entry errors. Fortunately, she has a keen eye and often notices her mistakes. On... | 0.574468 | ["haskell","clojure","scala","erlang","sbcl","ocaml","fsharp","racket","elixir"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-06-23T20:20:45 | 2016-12-07T10:52:12 | setter | object Solution {
class BinomHeap[T](lt: (T, T) => Boolean) {
def min(a: Option[T], b: Option[T]): Option[T] =
(a, b) match {
case (None, None) => None
case (None, _) => b
case (_, None) => a
case (So... | not-set | 2016-04-24T02:02:43 | 2016-04-24T02:02:43 | Python |
85 | 2,579 | messy-medians | Messy Medians | Robin is stuck doing a terminally boring data entry job. She has to enter a lot of numeric observations manually and report running medians after each step to her project lead. The task is sufficiently mind-numbing for her to make a lot of entry errors. Fortunately, she has a keen eye and often notices her mistakes. On... | code | (Add|Remove|getMedian) | ai | 2014-06-05T17:02:31 | 2016-09-01T16:22:55 | null | null | null | Robin is stuck doing a terminally boring data entry job. She has to enter a lot of numeric observations manually and report running medians after each step to her project lead. The task is sufficiently mind-numbing for her to make a lot of entry errors. Fortunately, she has a keen eye and often notices her mistakes. On... | 0.574468 | ["haskell","clojure","scala","erlang","sbcl","ocaml","fsharp","racket","elixir"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-06-23T20:20:45 | 2016-12-07T10:52:12 | tester | **Approach #1**
module Main where
import Data.List
import Data.Char
import qualified Data.Vector as V
import qualified Data.Map as Map
import Text.Printf
data SegmentTree = Leaf {
count :: Int
, index :: Int
... | not-set | 2016-04-24T02:02:43 | 2016-04-24T02:02:43 | Python |
86 | 3,129 | world-peace | World Peace | The Artifact of World Peace was obtained by the evil Pharaoh. He smashed it into pieces and hid them inside a temple. The temple has a very elaborate and confusing floor plan. It contained different rooms. Each room has a trap. Moreover, to go from one room to another, you must pass by a corridor and each of these also... | code | How skillful must you be to retrieve The Artifact of World Peace? | ai | 2014-06-22T19:04:22 | 2018-02-06T18:26:45 | null | null | null | The Artifact of World Peace was obtained by the evil Pharaoh. He smashed it into pieces and hid them inside a temple. The temple has a very elaborate and confusing floor plan. It contained different rooms. Each room has a trap. Moreover, to go from one room to another, you must pass by a corridor and each of these also... | 0.5 | ["c","cpp","java","python3","python","cpp14"] | Hard | null | null | null | null | null | null | 2014-06-24T05:03:25 | 2018-02-06T18:32:10 | setter | ```cpp
#include <stdio.h>
struct edge {
int a, b, s;
};
int ea[111111];
int eb[111111];
int es[111111];
int pa[111111];
int pb[111111];
int ps[111111];
int r, c, p;
int find(int n) {
return ps[n] < 0 ? n : ps[n] = find(ps[n]);
}
int kaya(int cost) {
for (int i = 0; i < r; i++) ps[i] = -1;
for (int ... | not-set | 2016-04-24T02:02:43 | 2018-02-06T18:26:46 | C++ | ||||
87 | 3,129 | world-peace | World Peace | The Artifact of World Peace was obtained by the evil Pharaoh. He smashed it into pieces and hid them inside a temple. The temple has a very elaborate and confusing floor plan. It contained different rooms. Each room has a trap. Moreover, to go from one room to another, you must pass by a corridor and each of these also... | code | How skillful must you be to retrieve The Artifact of World Peace? | ai | 2014-06-22T19:04:22 | 2018-02-06T18:26:45 | null | null | null | The Artifact of World Peace was obtained by the evil Pharaoh. He smashed it into pieces and hid them inside a temple. The temple has a very elaborate and confusing floor plan. It contained different rooms. Each room has a trap. Moreover, to go from one room to another, you must pass by a corridor and each of these also... | 0.5 | ["c","cpp","java","python3","python","cpp14"] | Hard | null | null | null | null | null | null | 2014-06-24T05:03:25 | 2018-02-06T18:32:10 | tester | ```cpp
#include <cstdio>
#include <cstring>
#include <string>
#include <cassert>
using namespace std;
const int N = 100005;
int f[N],num[N];
struct node {
int x,y,s;
};
node a[N];
pair<int,int> b[N];
int getf(int x) {
return (f[x] == x)?x:(f[x] = getf(f[x]));
}
void make(int x,int y) {
x = getf(x);
... | not-set | 2016-04-24T02:02:43 | 2018-02-06T18:26:46 | C++ | ||||
88 | 3,152 | uppals-ego | Uppal's Ego | Ramu is very good at maths. He always tries to play with different kinds of numbers. This time he has discovered a new type of numbers and has named them **KMH** numbers. According to him, a number **N** is a **KMH** number, if **the sum of its prime divisors is a power of 2** i.e **_(2, 4, 8, ...and so on)._** ... | code | Help Uppal so that his ego doesn't get hurt. | ai | 2014-06-24T08:08:53 | 2016-09-09T09:47:13 | null | null | null | Ramu is very good at maths. He always tries to play with different kinds of numbers. This time he has discovered a new type of numbers and has named them **KMH** numbers. According to him, a number **N** is a **KMH** number, if **the sum of its prime divisors is a power of 2** i.e **_(2, 4, 8, ...and so on)._** ... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","erlang","brainfuck","javascript","go","d","ocaml","pascal","sbcl","python3","groovy","objectivec","fsharp","cobol","visualbasic","lolcode","smalltalk","tcl","whitespace","tsql","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-06-24T08:24:54 | 2017-11-21T15:46:55 | setter | #include<iostream>
#include<string>
#define LL long long int
#define rep(i,x,n) for(i=x;i<n;i++)
using namespace std;
LL kmh[25],p=0,dp[16][136];
//returns string value of an integer
string convert(LL n)
{
LL i,j,k;
if(n==0)return "0";
string str;
... | not-set | 2016-04-24T02:02:43 | 2016-04-24T02:02:43 | C++ |
89 | 3,098 | big-balls | Big Balls | In the jackpot round of a game show, Big Balls, you are given $N$ jackpot balls, each having an integer weight (in grams). Within the time alloted, you may put two balls on opposite sides of a scale in order to determine which ball is heavier. To help you with your task, the host added some extra balls (different from ... | code | Guess the weights of the balls from comparisons. | ai | 2014-06-19T03:48:36 | 2016-09-09T09:46:50 | null | null | null | In the jackpot round of a game show, Big Balls, you are given $N$ jackpot balls, each having an integer weight (in grams). Within the time alloted, you may put two balls on opposite sides of a scale in order to determine which ball is heavier. To help you with your task, the host added some extra balls (different from ... | 0.5 | ["c","cpp","java","python3","python","cpp14"] | Hard | null | null | null | null | null | null | 2014-06-24T19:18:31 | 2017-03-17T05:18:04 | setter | #include <stdio.h>
#include <stdlib.h>
#define ll long long
int lower[211111];
int upper[211111];
char cmd[111];
int xs[211111];
int ys[211111];
int *adj[211111];
int adc[211111];
int deg[211111];
int que[211111];
int main() {
int n, m;
scanf("%d%d", ... | not-set | 2016-04-24T02:02:44 | 2016-04-24T02:02:44 | C++ | ||||
90 | 3,098 | big-balls | Big Balls | In the jackpot round of a game show, Big Balls, you are given $N$ jackpot balls, each having an integer weight (in grams). Within the time alloted, you may put two balls on opposite sides of a scale in order to determine which ball is heavier. To help you with your task, the host added some extra balls (different from ... | code | Guess the weights of the balls from comparisons. | ai | 2014-06-19T03:48:36 | 2016-09-09T09:46:50 | null | null | null | In the jackpot round of a game show, Big Balls, you are given $N$ jackpot balls, each having an integer weight (in grams). Within the time alloted, you may put two balls on opposite sides of a scale in order to determine which ball is heavier. To help you with your task, the host added some extra balls (different from ... | 0.5 | ["c","cpp","java","python3","python","cpp14"] | Hard | null | null | null | null | null | null | 2014-06-24T19:18:31 | 2017-03-17T05:18:04 | tester | #include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
const int N = 200002;
set<int> con[N];
int ind[N],L[N],G[N],a[N];
char s[5];
queue<int> q;
bool run(int n) {
int m = 0;
for (... | not-set | 2016-04-24T02:02:44 | 2016-04-24T02:02:44 | C++ | ||||
91 | 3,153 | testing-iii | Testing III | There are $w$ watermelons. Print YES if it can be divided into two parts, each weighing an even number. Print NO otherwise.
This is identical to the Watermelon challenge on Codeforces. | code | This problem is easy. | ai | 2014-06-24T19:35:49 | 2016-09-09T09:47:13 | null | null | null | There are $w$ watermelons. Print YES if it can be divided into two parts, each weighing an even number. Print NO otherwise.
This is identical to the Watermelon challenge on Codeforces. | 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-06-24T19:39:59 | 2016-05-13T00:01:39 | tester | #include <cstdio>
int main(void) {
int n;
scanf("%d", &n);
puts((n >= 4 && n % 2 == 0) ? "YES" : "NO");
return 0;
} | not-set | 2016-04-24T02:02:44 | 2016-04-24T02:02:44 | C++ |
92 | 3,051 | connecting-points | Connecting points | John has his own 3-dimensional space. He currently has $N$ distinct points that belong to this space.
Today John is connecting the points with each other. In each step, he chooses two points and connects them together by drawing a curved line between them. After that he always puts single point somewhere on the cur... | code | How many curve lines will be drawn? | ai | 2014-06-16T18:38:48 | 2019-07-02T13:58:38 | null | null | null | John has his own 3-dimensional space. He currently has $N$ distinct points that belong to this space.
Today John is connecting the points with each other. In each step, he chooses two points and connects them together by drawing a curved line between them. After that he always puts single point somewhere on the cur... | 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-06-24T21:08:10 | 2016-05-13T00:01:37 | setter |
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <... | not-set | 2016-04-24T02:02:44 | 2016-04-24T02:02:44 | C++ |
93 | 3,051 | connecting-points | Connecting points | John has his own 3-dimensional space. He currently has $N$ distinct points that belong to this space.
Today John is connecting the points with each other. In each step, he chooses two points and connects them together by drawing a curved line between them. After that he always puts single point somewhere on the cur... | code | How many curve lines will be drawn? | ai | 2014-06-16T18:38:48 | 2019-07-02T13:58:38 | null | null | null | John has his own 3-dimensional space. He currently has $N$ distinct points that belong to this space.
Today John is connecting the points with each other. In each step, he chooses two points and connects them together by drawing a curved line between them. After that he always puts single point somewhere on the cur... | 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-06-24T21:08:10 | 2016-05-13T00:01:37 | tester | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#define SZ(x) ((int)(x).size())
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
using namespace std;
typedef long long LL;
vo... | not-set | 2016-04-24T02:02:44 | 2016-04-24T02:02:44 | C++ |
94 | 3,097 | skwishinese | Skwishinese | The language Skwishinese has its own elegant, albeit complicated, measure for the beauty of a word.
Before we can start describing how to measure it, we must first define a subsequence. Discovered by and named after the famous Skwishinese doctor, Aaron J. Subsequence, a _subsequence_ of a word is another word that can... | code | Determine how beautiful a Skwishinese word is. | ai | 2014-06-19T03:42:29 | 2018-02-06T18:45:19 | null | null | null | The language Skwishinese has its own elegant, albeit complicated, measure for the beauty of a word.
Before we can start describing how to measure it, we must first define a subsequence. Discovered by and named after the famous Skwishinese doctor, Aaron J. Subsequence, a _subsequence_ of a word is another word that can... | 0.5 | ["c","cpp","java","python3","python","cpp14"] | Hard | null | null | null | null | null | null | 2014-06-25T11:28:33 | 2018-02-06T18:45:22 | setter | ```cpp
#include <stdio.h>
#define infinity 111111111
int min(int a, int b) {
return a < b ? a : b;
}
char V[411];
int F[411][411][411];
int main() {
int N;
scanf("%d%s", &N, V);
for (int i = N; i >= 0; i--) {
// try on ones and zeroes
for (int j = 0; j < N; j++) {
for (int k... | not-set | 2016-04-24T02:02:44 | 2018-02-06T18:45:22 | C++ | ||||
95 | 3,097 | skwishinese | Skwishinese | The language Skwishinese has its own elegant, albeit complicated, measure for the beauty of a word.
Before we can start describing how to measure it, we must first define a subsequence. Discovered by and named after the famous Skwishinese doctor, Aaron J. Subsequence, a _subsequence_ of a word is another word that can... | code | Determine how beautiful a Skwishinese word is. | ai | 2014-06-19T03:42:29 | 2018-02-06T18:45:19 | null | null | null | The language Skwishinese has its own elegant, albeit complicated, measure for the beauty of a word.
Before we can start describing how to measure it, we must first define a subsequence. Discovered by and named after the famous Skwishinese doctor, Aaron J. Subsequence, a _subsequence_ of a word is another word that can... | 0.5 | ["c","cpp","java","python3","python","cpp14"] | Hard | null | null | null | null | null | null | 2014-06-25T11:28:33 | 2018-02-06T18:45:22 | tester | ```cpp
#include <cstring>
#include <string>
#include <cstdio>
#include <cctype>
#include <cassert>
using namespace std;
char s[402];
int dp[2][402][402];
void better(int &x,int y) {
if ((x < 0) || (x > y)) {
x = y;
}
}
int main() {
memset(dp,0xff,sizeof(dp));
dp[0][0][0] = 0;
int n;
... | not-set | 2016-04-24T02:02:44 | 2018-02-06T18:45:22 | C++ | ||||
96 | 3,164 | net-admin | Network administration | Like every IT company, the Uplink Corporation has its own network. But, unlike the rest of the companies around the world, Uplink's network is subject to very specific restrictions:
* Any pair of servers within the network should be directly connected by at most 1 link.
* Each link is controlled by some specific netwo... | code | Given a network administrator, find out how many devices are in the path created by links controlled by that administrator (if any) between 2 servers. | ai | 2014-06-25T22:32:13 | 2022-09-02T10:00:41 | #
# Complete the 'solve' function below.
#
# The function is expected to return a STRING_ARRAY.
# The function accepts following parameters:
# 1. INTEGER s
# 2. INTEGER a
# 3. 2D_INTEGER_ARRAY links
# 4. 2D_INTEGER_ARRAY queries
#
def solve(s, a, links, queries):
# 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')
first_multiple_input = input().rstrip().split()
s = int(first_multiple_input[0])
l = int(first_multiple_input[1])
a = int(first_multiple_input[2])
t = int(first_multiple_input[3])
links = []
for _ in range(l):
... | <sub><strong>Time Limits</strong> C:5, Cpp:5, C#:6, Java:8, Php:18, Ruby:20, Python:20, Perl:18, Haskell:10, Scala:14, Javascript:20, Pascal:5</sub>
Like every IT company, the Uplink Corporation has its own network. But, unlike the rest of the companies around the world, Uplink's network is subject to very specific re... | 0.416667 | ["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-06-25T22:32:35 | 2016-12-03T07:57:19 | setter | //============================================================================
// Name : NETADMIN.cpp
// Author : Shaka
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//======================================================... | not-set | 2016-04-24T02:02:44 | 2016-04-24T02:02:44 | C++ |
97 | 2,565 | xor-love | XOR love | Devendra loves the XOR operation very much which is denoted by $\wedge$ sign in most of the programming languages. He has a list $A$ of $N$ numbers and he wants to know the answers of $M$ queries. Each query will be denoted by three numbers i.e. $K,P,R$ .
For query $K,P \text{ and } R$, he has to print the value of th... | code | Reply to query related to XOR. | ai | 2014-05-30T20:35:04 | 2022-09-02T09:55:10 | null | null | null | Devendra loves the XOR operation very much which is denoted by $\wedge$ sign in most of the programming languages. He has a list $A$ of $N$ numbers and he wants to know the answers of $M$ queries. Each query will be denoted by three numbers i.e. $K,P,R$ .
For query $K,P \text{ and } R$, he has to print the value of th... | 0.476923 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | null | null | null | null | Hard | null | null | null | null | null | null | 2014-06-26T10:13:36 | 2016-12-06T09:46:26 | setter | ###C++
```cpp
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<set>
#include<stdlib.h>
#include<string.h>
#include<utility>
#include<assert.h>
using namespace std;
typedef long long int ll;
int A[100001][31];
int main()
{
ll answer=0,ones,zeros,o,z;
int N,x,pow[31],y,k,M;
pow[0]=1;
fo... | not-set | 2016-04-24T02:02:45 | 2016-07-23T18:58:34 | C++ |
98 | 2,565 | xor-love | XOR love | Devendra loves the XOR operation very much which is denoted by $\wedge$ sign in most of the programming languages. He has a list $A$ of $N$ numbers and he wants to know the answers of $M$ queries. Each query will be denoted by three numbers i.e. $K,P,R$ .
For query $K,P \text{ and } R$, he has to print the value of th... | code | Reply to query related to XOR. | ai | 2014-05-30T20:35:04 | 2022-09-02T09:55:10 | null | null | null | Devendra loves the XOR operation very much which is denoted by $\wedge$ sign in most of the programming languages. He has a list $A$ of $N$ numbers and he wants to know the answers of $M$ queries. Each query will be denoted by three numbers i.e. $K,P,R$ .
For query $K,P \text{ and } R$, he has to print the value of th... | 0.476923 | ["bash","c","clojure","cpp","cpp14","cpp20","csharp","d","elixir","erlang","fsharp","go","groovy","haskell","java","java8","java15","javascript","julia","kotlin","lolcode","lua","objectivec","ocaml","pascal","perl","php","python3","r","racket","ruby","rust","sbcl","scala","smalltalk","swift","tcl","typescript","visualb... | null | null | null | null | Hard | null | null | null | null | null | null | 2014-06-26T10:13:36 | 2016-12-06T09:46:26 | tester | ###C++
```cpp
#ifdef ssu1
#define _GLIBCXX_DEBUG
#endif
#undef NDEBUG
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#incl... | not-set | 2016-04-24T02:02:45 | 2016-07-23T18:58:47 | C++ |
99 | 3,166 | dcbus | Dassu And Business | Dassu is very disturbed since the brutal murdur of her pet mosquito. As such, she is unable to concentrate on her studies.
So, she decided to step into business.<br>
She had learnt that she had to deal with **2 type of people - Dealers and Customers**.
There are **N dealers** and **M customers**. Also, there are... | code | Help Dassu make the maximum out of the day. | ai | 2014-06-26T10:16:14 | 2016-09-09T09:47:21 | null | null | null | Dassu is very disturbed since the brutal murdur of her pet mosquito. As such, she is unable to concentrate on her studies.
So, she decided to step into business.<br>
She had learnt that she had to deal with **2 type of people - Dealers and Customers**.
There are **N dealers** and **M customers**. Also, there are... | 0.5 | ["bash","c","cpp","java","csharp","php","ruby","python","perl","haskell","clojure","scala","lua","erlang","brainfuck","javascript","go","d","ocaml","pascal","sbcl","python3","groovy","objectivec","fsharp","cobol","visualbasic","lolcode","smalltalk","tcl","whitespace","tsql","cpp14"] | null | null | null | null | Hard | null | null | null | null | null | null | 2014-06-27T05:17:03 | 2018-08-14T21:11:55 | setter | <br><br>[CODE](http://ideone.com/z3TwMM) | not-set | 2016-04-24T02:02:45 | 2016-04-24T02:02:45 | Unknown |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.