question_id
int64
39
56.8k
question_title
stringlengths
3
54
question_content
stringlengths
88
4.02k
dataset
stringclasses
1 value
difficulty
stringclasses
3 values
java
dict
java15
dict
java8
dict
python
dict
test_cases
stringlengths
28
4.02M
max_retries
float64
1
3
⌀
16,725
Beautiful Strings
You are given a string, $S$, consisting of lowercase English letters. A string is *beautiful* with respect to $S$ if it can be derived from $S$ by removing *exactly* $2$ characters. Find and print the number of different strings that are *beautiful* with respect to $S$.
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static long beautifulStrings(String s)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\n\npublic class B\n{\n String line;\n StringTokenizer inputParser;\n BufferedReader is;\n ...
{ "solution": "import java.io.*;\n\npublic class Solution {\n \n static long beautifulStrings(char[] s) {\n long result = 0;\n int res[] = new int[s.length];\n for (int j = s.length-1; j > 0; j--) {\n res[j-1] = res[j];\n if ((j > 1) && (s[j] == s[j-1])) {\n continue;...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n in = new InputReader(System.in);\n out = new PrintWriter(System.out, true);\n\n char[] c = i...
{ "class_name": null, "func_sign": [ "beautifulStrings(s)" ], "solution": "import operator as op\nimport functools\n\n \ndef ncr(n, r):\n if n < r: return 0\n r = min(r, n-r)\n if r == 0: return 1\n numer = functools.reduce(op.mul, range(n, n-r, -1))\n denom = functools.reduce(op.mul, ...
eJzt2duO5za23/FcBMgj5LZR10Zgz3gOnicJkAkGJEWKlCjxJFISBwbyEHmvvFLW3xgEgTecqyB7Z/D99A8Nt6u6Sgdyca3q//bv//N//B//4d/9l79/hTP36+sv376UVdWsizusev56fn337cs+2ZrLLn9L/frHJ/3xD18/f/ftf/tbd9dWn/G2aRpz19/8iz/98Ku/OHqO/Tc//Yfvf/Xp7/rM9zG3a0ONeZv9VTnm5+y1XT6XqM/W1urSVl2v6UzzbWPfvS2bXmp7bx+CurK1KchNhl1d1TQzt+jMLVeyP662p9jF2Bq2au2497oc...
null
2,186
Travel around the world
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city *i* to city *(i + 1) % N*, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0). Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int travelAroundTheWorld(List<Integer> a, List<Integer> b, long c)" ], "script_name": "Solution", "solution": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\nimport java.io.*;\n\npublic class Solution {\n\n\tint N; long C; long...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n InputReader in = new InputReader(System.in);\n int N...
{ "class_name": null, "func_sign": [ "travelAroundTheWorld(a, b, c)" ], "solution": "#!/usr/bin/env python3\n\ndef travel(cap, fuel, costs):\n fuel = list(fuel)\n costs = list(costs)\n\n n = len(fuel)\n req = [0] * n\n \n # first iter\n for _ in range(2):\n for i in reversed(rang...
eJysvUmOLOuSnFkD1j4Mb8zB3zdcCQFeoAbFHHByKweZAAGCQO2lVlG7K/lEzT28MY+I84oZfOC550R4mP2NNqKiov/3f/jP/+//87//b//lf/zjv/39r//+b//4T8c/eh31aPmvv9ORjtz3SP6bdOw+xuxt7iO9fOWWe1+jr6PvmmfVf719z9dX7XmUlsvUn3tLJc2Z3z/T31na2GWMpj+vNludu+X7v+69eq0t8zmzr1RmmuWb35uOUkvtbazn79Kjl1X3yzOslVvaW+9U51xLL8bvyTW1svZu9ydcfSz9lb6r55r1vfGZqc8x5x7x...
null
19,667
Longest Palindromic Subsequence
Steve loves playing with palindromes. He has a string, $s$, consisting of $n$ lowercase English alphabetic characters (i.e., `a` through `z`). He wants to calculate the number of ways to insert exactly $1$ lowercase character into string $s$ such that the length of the [longest palindromic subsequence](http://www.geeks...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int longestPalindromicSubsequence(String s, int k)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static int lo...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static int longestPalindromicSubsequence(String s, int k)\n {\n int n = s.length();\n \n if (k == 0)\n {\n return (n + ...
{ "solution": "\nimport java.util.Scanner;\n\n/**\n *\n * @author abhishek\n */\npublic class LongestPalSeq {\n \n \n //lsc[i][j] = length of longest common subsequence between S[0,i] and rev(S)[0,j] i.e. S[n-1-j]\n private static int[][] lcs(char[] arr,char[] b){\n int[][] lcs = new int[arr.length...
{ "class_name": null, "func_sign": [ "longestPalindromicSubsequence(s, k)" ], "solution": "#!/bin/python3\n\nimport math\nimport os\nimport random\nimport re\nimport sys\nsys.setrecursionlimit(100000)\ndata ={}\ndef longestPalindrome(s, x, y):\n if x==y:\n return 1\n if y<x:\n return 0\n...
eJzsvdnOJUmWndcX0nsE6poXGUNWRulJBCgAweZ5no0goJfQPfmigpb9RYrNaqq6kywS3WQcz0REnNHdbO+1v+VuZv5//S//9//67/7u4/G//z//9u/+7v/4138wMY/+h//t0x9++xG///rpyy8/Yuv/DbYf8fOnr99+RPoj/unbb58+/4rfuT+3n9vP7V/QhuT9+pHG1880Z9510VDqVHMUVVrtRlEbc1Ij3aYkS4X63FbpNIrAdT3JkU2zJHpz4dhsLJCg+NXKJNr9ii2GmX7EP376+vlHJJRxIZ9gfPr8HdLBx9J0U5tld8OOpKxg...
null
2,529
Swap Permutation
You are given an array _A = [1, 2, 3, ..., n]_: 1. How many sequences _(S<sub>1</sub>)_ can you get after exact _k_ adjacent swaps on _A_? 2. How many sequences _(S<sub>2</sub>)_ can you get after at most _k_ swaps on _A_? An adjacent swap can be made between two elements of the Array A, A[i] and A[i+1] or A...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static List<Integer> swapPermutation(int n, int k)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.Arrays;\n\npublic class Solution {\n\n final static long mod = 1000000007;\n\n public static void solve(Input in, PrintW...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nim...
{ "solution": "import java.io.*;\nimport java.util.Arrays;\n\npublic class Solution {\n\n final static long mod = 1000000007;\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n int k = in.nextInt();\n long[] d = new long[k + 1];\n d...
{ "class_name": null, "func_sign": [ "swapPermutation(n, k)" ], "solution": "from itertools import accumulate, chain, islice\nfrom sys import stderr\n\nMOD = 1000000007\n\ndef adjswap(n, k):\n if n == 1:\n return int(k==0)\n permcount = [1]*(k+1)\n for nperm in range(3, n+1):\n oldper...
eJyVkT0KAjEQRgU9yJB6kczkx40nEVQsdAubdYtdEETwEHooO49kWCyEzFdsqkDefPMy81i8PvPZeDbvfNnezLntht6syTCxqcg016459s3pcBn634sl3rXmXtEfLZBmEoWWCbSD2UJeoVG2o6jQbgLtoYmjlUIjk0hcKzhSSSTlPz15NEPW+ADd86/KhQYY7/L+xSoFAeWzWhChUFYtZx9hPttAK7VBRBXBqxVsoVMiXzplPqEWyUUmF6Wurd7IovlK8DWsFKzIiTiNm9w/l18QVyDR
2
2,113
Extremum Permutations
Let's consider a permutation _P = {p<sub>1</sub>, p<sub>2</sub>, ..., p<sub>N</sub>}_ of the set of _N = {1, 2, 3, ..., N}_ elements . _P_ is called a magic set if it satisfies both of the following constraints: * Given a set of _K_ integers, the elements in positions _a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int extremumPermutations(int n, List<Integer> a, List<Integer> b)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.uti...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int k = in.nextInt();\n int...
{ "solution": "\n\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.Scanner;\n\npublic class Solution {\n\tprivate File inputFile;\n\t\n\tint numElementsN;\n\tint sizeA;\n\tint sizeB;\n\tint[] arrA;\n\tint[] arrB;\n\t\n\tboolean debug = false;\n\t\n\tpublic static final long MOD = 1000000...
{ "class_name": null, "func_sign": [ "extremumPermutations(n, a, b)" ], "solution": "# from sets import Set\n\ndef main():\n\tN, K, L = map(int, input().split())\n\tK_indices = set(map(int, input().split()))\n\tL_indices = set(map(int, input().split()))\n\tdone = False\n\tif len(K_indices & L_indices) > 0:\...
eJyNmc2qZVkRhB34INsCZ42s/8zlkwhecaA1cHLtQTU0iOBD6PsaX+QpcKByGoq+devstXNlRkZE5vnHL//1w69+4f9+92v98Pu/ffnL548/ffvy2+dLH09vT//43M/lp/HE0/uTz3zOsz4+75cfni9ff/7x65++ff3zH//607fXc+3j88vff3j+86SuE/bH56pjOC91mM7h8Klfree8fdrV5xWV4vj4nO/HoKvwvuSVw7e4T7z9eCjEwQ24vK4yn/3+qwe5+/hUGnTEeZxXAtAv1tunHH1eV9cJez+b7I3jE57Rn6lT9cN4ptKro+ez...
null
82
Square Subsequences
**Square Subsequences** A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of the string are square strings? A subsequence of a string can b...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int squareSubsequences(String s)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution implements Runnable {\n final static int MOD = 1000000007;\n\n int count(String a, String b) {\n ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution implements Runnable {\n final static int MOD = 1000000007;\n\n int count(String a, String b) {\n int n = a.length();\n int m = b.length();\n int dp[][] = new int[n + 1][m + 1];\n int sum[][] = new int[n + ...
{ "solution": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper pl...
{ "class_name": null, "func_sign": [ "squareSubsequences(s)" ], "solution": "\ndef count_square_subsequences(s, t):\n m = len(s)\n n = len(t)\n\n T = [[0 for _ in range(n)] for _ in range(m)]\n T[0][0] = 1 if s[0] == t[0] else 0\n\n for i in range(1, n):\n T[0][i] = ...
eJzdu0mOZcm6nacGB/Jw24TgZbi7RiJAQRBW13VthAANQhoMexya1o6rB5D33eyoIYH0iMw8fs7Zldn/r/Ut2zv/j3/3f/2Xr//pz8//+p/x4n/7T38zMY/+t//lX/72+v07liDITdTRfhklcUjR7im/o905SUVGstfrmafxw9eeau5rmpSFNjZVrQu3rcyUojUqx1Sl5D51RbLkona1een8yD5YVG6MmuW2Ldqg6NGxFGfGuVss04OIVNjxOy6SZz5dKlVK8iP9jmb7fXFqswW+ypzOUjb13MenrYztZCavjaqkmELr1ZUse43lPCsS...
null
1,197
Modify The Sequence
You are given a sequence of integers a<sub>1</sub>,a<sub>2</sub>,a<sub>3</sub>.....a<sub>n</sub>. You are free to replace any integer with any other positive integer. How many integers must be replaced to make the resulting sequence strictly increasing? **Input Format** The first line of the test case contains an i...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int modifySequence(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.P...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n static int ceilIndex(int tailTable[], int r, int key) {\n int l = 0;\n while (l <= r) {\n int mid = (l + r) >> 1;\n if (tailTable[mid] <= key) {\n l = mid + 1;\n } el...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n \tScanner in=new Scanner(System.in);\n \t int n = in.nextInt(); \t \n \t int[]nums=new int[n+1];\n \t for(int i=0;i<=n;i++)\n \t\t nums[i]=Integer.MAX_VALUE;\n \t in...
{ "class_name": null, "func_sign": [ "modifySequence(arr)" ], "solution": "import bisect\n\ndef parse(seq):\n for i in range(len(seq)):\n seq[i] -= i\n\ndef patience_sort(array):\n piles = [array[0]]\n for x in range(1, len(array)):\n i = bisect.bisect_right(piles, array[x])\n ...
eJzt2d2KI0eagOGBnQsJdNws8ZPxk76ShanFLHYd+ETug2owGMNcxNzk3sV8smWloLL6zOBdP56R9D4pKTIyMlvVpf7n3//rf/73P/72j58vP1w/f3m7fJMuPef8cm01p7K2PtfeZyIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiKiP7FerpdP6fL60+fX795ev//2xy9vn7+8Xb5Jl23fVzz5y6f08+WH631jzy/Xmvva8j7Smr3GWG1LvazaS281lZK30eae...
null
19,176
Longest Mod Path
In the middle of a nightmare, [Maxine](http://life-is-strange.wikia.com/wiki/Maxine_Caulfield) suddenly finds herself in a mysterious room with the following items: 1. A piece of paper with the word *score* and the integer $0$ written on it. 2. A map of the castle where the room is located. - There are $N$ rooms ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> longestModPath(List<List<Integer>> corridor, List<List<Integer>> queries)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic ...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n /*\n * Complete the longestModPath function below.\n */\n static long gcd(long a, long b){\n if(b == 0)\n return a;\n return...
{ "solution": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\...
{ "class_name": null, "func_sign": [ "longestModPath(corridor, queries)" ], "solution": "\nfrom math import gcd\n\nn=int(input())\nadjlst = [[] for i in range(n)]\nfor j in range(0,n):\n arr=list(map(int,input().split()))\n a=arr[0]-1\n b=arr[1]-1\n c=arr[2]\n adjlst[a].append((b,c))\n adj...
eJx0vcuuNkuWZUUD3mMr29Vwc7vzJEgciQZkg05QjSyppBISj84cY/k+cU6mMioD4v/2d3E3N1vXueb8//7n/+2/P//L//S//49/+b//8V//27/9y//68y+tP+8f/2g/788d+U/74x/vT/vp89w51tr8qf/c95nvw5/GT+9jrtHPH/8YP/PnvXMd//f6We95n8H/3j/5dHvyZfvn/Nz+vn3w6fvz7jt7frD/tOdn393uM9b0R/ND77zt+Mf3Z83n7euPf5yflgtoo7frX/JL8y7+X75y/rT509dp+d/5TFv59z2DP+X72v4Zd62351/7...
null
76
Lucky Numbers
A number is called *lucky* if the sum of its digits, as well as the sum of the squares of its digits is a prime number. How many numbers between $a$ and $b$ inclusive, are lucky? For example, $a = 20$ and $b = 25$. Each number is tested below: digit digit squares value sum squares sum 20 2 4,0 4 2...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static long luckyNumbers(long a, long b)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class Solution implements Runnable {\n\n // leave empt...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n /*\n * Complete the luckyNumbers function below.\n */\n static long luckyNumbers(long a, long b) {\n return Method1.luckyNumbers(a, b);\n }\...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class LuckyNumbers {\n private class Numbers {\n public int sum2;\n public int sum;\n public long count;\n }\n\n int max = 9 * 18;\n int max2 = 81 * 18;\n private boolean[] prime;\n private Vector<Hashtable<Integer,...
{ "class_name": null, "func_sign": [ "luckyNumbers(a, b)" ], "solution": "def lucky(N):\n p = [int(x) for x in str(N)]\n numDigits = len(p)\n total = 0\n curSum = 0\n curSumSq = 0\n while len(p):\n for a in range(p[0]):\n total += resolve(numDigits - 1, curSum + a, curSum...
eJyUvc2uLEmSpMfF8D0ctSRm4fbvzichwAK4mOkFN8UB2AMQIAjw0SnfZ5HNmjTPATq7K/PGPXEi3NzNVEVVRUX/3//wv/yf/9P/+D/8r//33/73f/yX//qvf/ufr7+VUv7+j/HOq/bR+FO55px//8fb7qs87f37P+rz3Pdoda37nU/+adfb+7PqGK09fa7n5RdWH6POUkt9nz7e/Pt629vWnL2WWdr93HXkbaOVu/c6yrqvvOizlvHeY/39H7OV2lbNL7354vbcD5fSRv5mPq328pSWt7191Xx5abPWXEkuro+62sw68vYrl1Tzp1xy...
null
779
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...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int oilWell(List<List<Integer>> blocks)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static int dist(i...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static int dist(int x1,int y1,int x2,int y2) {\n int x = x1 - x2, y = y1 - y2;\n if (x < 0) {\n x = -x;\n }\n if (y...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n static int[][][][] a= new int[50][50][50][50];\n public static void main(String[] args) {\n Scanner s= new Scanner(System.in);\n int w=s.nextInt();\n int h=s.nextInt();\n boolean[][] rigs= new boolean[...
{ "class_name": null, "func_sign": [ "oilWell(blocks)" ], "solution": "r, c = list(map(int, input().strip().split()))\nn = max(r, c)\ng = [[0]*n for i in range(n)]\nfor i in range(r):\n\tbs = list(map(int, input().strip().split()))\n\tfor j in range(c):\n\t\tg[i][j] = bs[j]\n\nx = [[0]*(n+1) for i in range(...
eJztnc9u20YQxnvIgyx0DopdirKlPkmB/smh9aGXNAcHCFAEyEOkh75tE5kiZ775Zkk1tRE4nwnLFrk7v/m3s8u1ZH148ffdP9+dv3789dMvP/21++P1m7f3ux/KbizDz69radNDK3V62L0su7t3b+5+u7/7/dWfb++n9je79y+L6T987t8eura01x567ct47lDaA/l8mDOJmHYAOW0ot3P/T4cVdxH6+Sw8bZdTD41bqaCKbzzJXp42f3XuO1+bvDhrVRfJKxaOFU0cSzteuluZrdRC1HVaTD/BAXi04gyzfmikkbHfAlA30wh6ut8a...
null
3,435
The Blacklist
A new gangster is trying to take control of the city. He makes a list of his $N$ adversaries (e.g. _gangster_ $1$, _gangster_ $2$, ... _gangster_ $N-1$, _gangster_ $N$) and plans to get rid of them. $K$ mercenaries are willing to do the job. The gangster can use any number of these mercenaries. But he has to honor one...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int blacklist(List<List<Integer>> amounts)" ], "script_name": "Solution", "solution": "import java.util.Scanner;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static final int INF = Integer.MAX_VALUE / 10;\n\n static boolean hitmanAvailable(int hitman, int mask) {\n return (((2 << hitman)) & mask) == 0;\n }\n\n static int useHitman(int hitman, int mask) {\n return mask | (2 << hi...
{ "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n\npublic class Solution {\t\n\tBufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter out;\n\n int INF = Integer.MAX_VALUE / 2;\n\tpubl...
{ "class_name": null, "func_sign": [ "blacklist(amounts)" ], "solution": "def bits_free(x, K):\n res = []\n for i in range(K):\n if x % 2 == 0:\n res.append(i)\n x //= 2\n return res\n\nN, K = tuple(int(s) for s in input().strip().split())\n\ncosts = []\nfor i in range(K):\...
eJztmt2KZUkRRr3wQZIWvJBB8ifyzycRLPFC+8Kbci56QBDBh9D3da3cdY5SM2fo0caSobo5u3efnRkZGfHFFxG5z99++o9f/Pwn58+vf8bNb/7y4Y/PX3/z6cOv0odI7em5jJFi7ZpGbiO1MuvTc0SdadfZ0iwxUx2xn55HKTXV3HqaebfEkPn0/OGr9OHjn7/++PtPH//wuz998+lFcik72oe/fpX+bbXuanX1kXYeLbU8cuqrRCqx+9PzmjmnMXtNu6+eVmVgnZWFq9q0NnMqdSJFPXrf43tWH3O/Wr2l8vQ8e5lMHTVF5MfTWy+v...
null
83
Count Scorecards
In a tournament, $n$ players play against each other exactly once. Each game results in exactly one player winning. There are no ties. You have been given a scorecard containing the scores of each player at the end of the tournament. The score of a player is the total number of games the player won in the tournament. H...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int countScorecards(List<Integer> s)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n // leave empty to read from stdin/stdout\n private static final String TASK_NAME_FOR_IO = \"\...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static final int MOD = 1_000_000_007;\n\n static class Solve {\n int[] exceed = new int[55];\n int numErased;\n int sCount;\n int scores;\n int dp[][][] = new int[42][42][42 * 41];\n int[][][] calced = new int[42]...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n // leave empty to read from stdin/stdout\n private static final String TASK_NAME_FOR_IO = \"\";\n\n // file names\n private static final String FILE_IN = TASK_NAME_FOR_IO + \".in\";\n private static final String FILE_O...
{ "class_name": null, "func_sign": [ "countScorecards(s)" ], "solution": "# Enter your code here. Read input from STDIN.\nimport sys\ninput = sys.stdin.read\n\nmod = 10**9 + 7\n\ndef c2(n):\n return n * (n - 1) // 2\n\ndata = input().split()\nindex = 0\n\ntests = int(data[index])\nindex += 1\n\nresults =...
eJy9VstuVDEMZcGOn4hm3UGx8+ZLkBjEArpgM3TRSpUQEh8BP8aOv+HYSW7us1U3MFPm3sRx4nOO7fx8/fvvm1f67/0fPHz4fvp6vXu4P70zJ3+50uV6xh/LozPOnMmwNZQM12dnKBr54IW8vODBGib5xbevEbvL1RVxp+P4Bp1JJhuyWIPlrN51BU0euPnBXGy+6kwQeywtxrnm8zz7MuaxHyfdc/LHS6sakBiUMUJZQhwGfrXkcj3dmNPt493t5/vbL5++Pdw3xDBjL9fgk2NKETvHkrJPJebTjxszgxaGZPVgus/4D9g9tQGTtVtX...
null
6,530
Vim War
A war has broken down between Vim and Emacs. Gedit, being Vim's ally, is captured by Emacs as a prisoner of war and it is up to Vim to rescue him by defeating Emacs. For this task, Vim has to assemble an army of appropriate skills. He can choose a **non-empty** subset of soldiers from a set of $N$ soldiers (numbered f...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int vimWar(List<String> skills, String requirement)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimp...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n private static final int MAX_N= 100000;\n private static final int MAX_M= 20;\n private static final int MODULO= 1000000007; \n \n public static void m...
{ "solution": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class VimWar {\n\n static int n, m;\n static int[] a;\n static int[] b;\n static int target;\n static final long MOD = 1000000007;\n static int[] pow2 = new int[111111];\n\n static {\n p...
{ "class_name": null, "func_sign": [ "vimWar(skills, requirement)" ], "solution": "#!/bin/python3\n\nimport math\nimport os\nimport random\nimport re\nimport sys\n\np = (10**9) + 7\n\ndef bool_vector(x):\n return int(x, base=2)\n\n\ndef powers_of_two(n):\n x = 1\n for i in range(n):\n yield ...
eJzsvbuuLcmSZUeBEr8iceUW3O+zyC8hwAQokCVQKbZQDRBoEKDOn2bdzBPuZmMOi5MEKBHR6F079ooId7Np8+ErhXv+r//2f/zr//3f/Tf/03/90//2b//5v/z7n/6HX/7017///Ze//vpva63967/tvdZ/XP/Hr/J/9z/v/vZ/f7ve69798fxvd/fvz69/frJ/W209q5Xr+vkqz//YhbuvH7vc9ffda/+o58fd/Tz5Y5216+6li4W7T7Vtzazq7vXcZW0/7t7P+5p3999xO5XXvdDR72v+qPzBdt0pFPzrCnXNHwjsg/+Pmn88Waew...
null
1,555
Divisible Numbers
Given an integer, $n$, find the smallest integer $m$ such that $m$ is divisible by $n$ (i.e., $n$ is a factor of $m$) and satisfies the following properties: + $m$ must not contain zeroes in its decimal representation. + The sum of $m$'s digits must be *greater than or equal to* the product of $m$'s digits. Given $...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int divisibleNumbers(int n)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\nimport java.math.BigInteger;\n\npublic class Solution {\n\n\n private static Map<Integer, String> ones = new HashMap<>();\n\n priv...
{ "solution": "import java.io.*;\nimport java.util.*;\n\nimport java.math.BigInteger;\n\npublic class SolutionDiv2 {\n\n\n private static Map<Integer, String> ones = new HashMap<>();\n\n private static void swap(StringBuilder s, int i, int j) {\n char t = s.charAt(i);\n s.setCharAt(i, s.charAt(j))...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\n\npublic class Solution {\n\n public PrintWriter getWriter() {\n return new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n }\n\n public Scanner getScanner() {\n retur...
{ "class_name": null, "func_sign": [ "divisibleNumbers(n)" ], "solution": "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import, division, print_function\n\nfrom sys import version_info\nif version_info.major == 3:\n pass\nelif version_info.major == 2:\n input = raw_inpu...
eJyNkjEKAjEQRQU9yJJ6kUwmmSSeRFCx0C1sVotdEESws7PS+7pYiEz4i1MF8vh5/Mxt9npMJ59Z3ofD6mIO7anvzKIyxBLcujV1ZZrzqdl1zX577LvvrbnW1Q/uvLUZ41bhzB7CoqMlRYG0I41H6wmblOlsE8aDwnNM2IWcDk/WjZSow8nZyBBPihb2WCXraGyhnf8msaomCT+vKyOcWrQbIKqbdR7HFr8gnPB2Rk0HGfHwUpjkYUa3efOcvwF5BRZY
null
17,916
Unique Divide And Conquer
Divide-and-Conquer on a tree is a powerful approach to solving tree problems. Imagine a tree, $t$, with $n$ vertices. Let's remove some vertex $v$ from tree $t$, splitting $t$ into zero or more connected components, $t_1, t_2, \ldots, t_k$, with vertices $n_1, n_2, \ldots, n_k$. We can prove that there is a vertex, $...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int uniqueDivideAndConquer(int n, int m)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Locale;\nimport java.ut...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n FastScanner in;\n PrintWriter out;\n\n void solve() {\n int n = in.nextInt();\n int p = in.nextInt();\n int[][] c = new int[n + 1][n + 1];\n c[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint p = in.nextInt();\n\t\tint[][] c = new int[n + 1][n + 1];\n\t\tc[0][0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tc[i][0] = 1;\n\t\t\tfor...
{ "class_name": null, "func_sign": [ "uniqueDivideAndConquer(n, m)" ], "solution": "def uniqueDivideAndConquer(n, p):\n if n == 1:\n return 1 % p # Directly return 1 for this special case\n \n f = [0] * (n + 1)\n g = [0] * (n + 1)\n c = [[0] * (n + 1) for _ in range(n + 1)]\n \n ...
eJyFkk1KBDEQhRscPEeR9SD1l1TKkwgqLrQXbsZZ9MCACB5Cz6tpQZBqErPIqr68l3rvffd5uZt+zs3XxTTdvqbnw/G0pGtIZCYgRTPdHdIe0nw+zo/L/PTwclp+Ryqxprc9/MHYKrjziEKUSJGggqjVPpYFS9SqDl6VvQuJCXKkMmZQxwElkVntFaSBO1OJOtTsGaF0IRWPe0BW4EIDJRK3zSJEdJWq/T95zrSJyg2ctfTFxLBi9AjcNxcloP/7+K5A7vsIszqYjd0SRIR2DVZqMQd293+YKtEU5SZEeZSdb4qvTWjIFLJNSVYdHBS4...
null
3,124
Dortmund Dilemma
Borussia Dortmund are a famous football ( soccer ) club from Germany. Apart from their fast-paced style of playing, the thing that makes them unique is the hard to pronounce names of their players ( błaszczykowski , papastathopoulos , großkreutz etc. ). The team's coach is your friend. He is in a dilemma as he can't d...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int dortmundDilemma(int n, int k)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.Arrays;\n\npublic class Solution {\n\n static final long MOD = 1000000009;\n static final int MAXK = 26;\n static final int MAX...
{ "solution": "import java.util.Scanner;\n\npublic class DortmundDilemma {\n public static final int MAX_N = 100000;\n public static final int MAX_K = 26;\n public static final long MOD = 1000000009;\n\n static long[][] C;\n\n static long[][] F;\n\n static long[][] G;\n static long[][] P;\n\n public static vo...
{ "solution": "import java.util.List;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimpo...
{ "class_name": null, "func_sign": [ "dortmundDilemma(n, k)" ], "solution": "MOD = 10 ** 9 + 9\nN = 10 ** 5\nK = 26\n\nclass Solver(object):\n def __init__(self):\n self.factorials = [1 for _ in range(26 + 1)]\n for i in range(1, 26 + 1):\n self.factorials[i] = self.factorials[i ...
eJy8vcmuZUuSHUYChL4jkGMOvDHv9CUCFIAGVA00SXFQBAgQBPS/+gmtxnyffW68V5wQqsrMiLj3nN24u/XLlv0//+F/+3//l3//7/73//aP/+uf//m//Os//tdf/xi//7li/Grt9z/nr/77n/1X/f3PWvjX1nb0X/H7n//4j7/+8S//9T//y3/613/5P/+P//u//Ov96ozeIw6+ELvPUvCVicu0slrwX6uPvjv+g0v89//463XXWmLh079w9/h1fv9ztDj8x9xxDp/gzMp/45/7/Nr4VB1l/Kr46F6NDzdi1PiFp25j8QPT/9p76+u/...
null
2,381
Maximizing XOR
Given two integers, $l$ and $r$, find the maximal value of $a$ [xor](http://en.wikipedia.org/wiki/Bitwise_operation#XOR) $b$, written $a \oplus b$, where $a$ and $b$ satisfy the following condition: $l \le a \le b \le r$ For example, if $l = 11$ and $r = 12$, then $11 \oplus 11 = 0$ $11 \oplus 12 = 7$ $12 \op...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int maximizingXor(int l, int r)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n/*\n * Complete the function below.\n ...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\nclass Solution\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in=new Scanner(System.in);\n\t\tint l,r,i,j,ans=0;\n\t\tl=in.nextInt();\n\t\tr=in.nextInt();\n\t\tfor(i=l;i<r;i++)\n\t\t{\n\t\t\tfor(j=i+1;j<=r;j++)\n\t\t\t{\n\t\t\t\tif((int)(i^j) > an...
{ "class_name": null, "func_sign": [ "maximizingXor(l, r)" ], "solution": "l = int( input() )\nr = int( input() )\nm = 0\nfor i in range(l, r+1):\n for j in range( i+1, r+1 ):\n m = max( m, i^j )\nprint(m)", "template": "#\n# Complete the 'maximizingXor' function below.\n#\n# The function is exp...
eJyVk00KwjAQhQU9SMlaJDPJ5MeTCFZcaBduqosWBBE8hN7TnVsn1YXExpouQinvo++9mVwmt8d41D2LO78sT2JXH9pGzAuh0Za1VnyIaSGq46HaNNV2vW+bt0CBOE+LD8JpWdYeTJJAohixrPaoMhBPxIhJ+wK0EYKW1Y7SxkCiihitmTGAOYxyHIRA5hTgQwEEScTEP0HjOIxOV9ZjzAS5VT/CfHXGjtKmZCyWkkO/zn+RAX1PCu/9EBTXS2GAPxGCeI0xLAp/zpgihLsC6DIQwxMxOmMgvPXpBY6rgnClFKYzdLFX19kT0F8z6A==
null
3,396
Counter game
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts. Given an initial value, de...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String counterGame(long n)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\npublic class Solution{\n\tstatic void solve(long n){\n\t\tif(n==1){\n\t\t\tSystem.out.println(\"Richard\");\n\t\t\treturn;\n\t\t}\n\t\tint cnt=0;\n\t while(n!=1){\n\t \tlong r = Long.highestOneBit(n-1);\n\t \tif(r==n)n=n/2;\n\t \telse n=n-r;\n\t \t...
{ "class_name": null, "func_sign": [ "counterGame(n)" ], "solution": "import math\nfrom math import log2\nfrom math import floor\ndef genlist(x):\n if x==1:\n return False\n elif (log2(x))%1==0:\n return not genlist(int(x/2))\n else:\n return not genlist(x-2**floor(log2(x)))\n\...
eJytVctuE0EQ5MCBz4h8jlC/H3wDJ05IGCGUWCIcnACOhISQ+Aj4X2rWKAmJN44De3F7dma6uqq698fTX5+ePZme1x8RvPm2OFtfXG4WL44WuVyzp5p0hCzXwqXF7FjNYGXO7hGnILScYjEmzY7lOowV/9qwXBraHox4cXy0WH29WJ1sVqfvzi83f1K9Ojv58P7z6XL98vzy7Mvq+vfqxWyw+H58dAM0UgsRdYu2LtfGXmVeqMWL1EJzIBJ2a5XCjtbIVi3UpZYi3F77cT4k2NawA19EBdPEXoG+dGrga+kU9ZHdg7DFmQdUSnLDOmLg...
null
25,113
Sum vs XOR
Given an integer $n$, find each $x$ such that: * $0 \le x \le n$ * $n+x = n \oplus x$ where $\oplus$ denotes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operator. Return the number of $x$'s satisfying the criteria. **Example** $n = 4$ There are four values that meet the criteria: ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static long sumXor(long n)" ], "script_name": "Solution", "solution": "\n\n\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) {\n ConsoleIO io = new ConsoleIO();\n new Main(io).solve();\n io.close();\n }\n ConsoleIO io;...
{ "class_name": null, "func_sign": [ "sumXor(n)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nn = int(input().strip())\nprint(1 if n == 0 else 1 << (bin(n)[2:].count('0')))", "template": "#\n# Complete the 'sumXor' function below.\n#\n# The function is expected to return a LONG_INTEGER.\n# The functi...
eJydVLtKA1EQtciHhK2DzPvhlwgqFrqFTUyxgYAINnaW+r9OxMLccMPGqbY4Z86ZM3P3bfH1sbj4qev3+rh5GZ7Wm+00XC2HVAAVJcgQc7pdD6vlMO4248M0Pt4/b6dfnLKFQyINr6vlHz6TIbuoI2IadPlo7k5oDT0BEVBEUskE+3TwUsEgaRsEJIuTg5aCdBsIpjC0bHWpAZgNjE3PNc+YoSXqSsp9aQQpWEv2MgRR4Turg/fZLISlHq311KjUwFGVuO/dHCHC2slRFCvzZEKo4ft7J6FotdMzKcQFdB/NmaGfOJLW5Gxk/3CPDna+...
null
27,667
The Great XOR
Given a long integer $x$, count the number of values of $a$ satisfying the following conditions: * $a \oplus x > x$ * $0 < a < x$ where $a$ and $x$ are long integers and $\oplus$ is the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operator. You are given $q$ queries, and each query is in th...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static long theGreatXor(long x)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) ...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class B {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t...
{ "class_name": null, "func_sign": [ "theGreatXor(x)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nq = int(input().strip())\nfor a0 in range(q):\n x = int(input().strip())\n size = 1\n result = 0\n while x > 0 :\n if x & 1 == 0:\n result += size\n size *=2\n ...
eJyNvUmuLs2SLQQSXeaQyvYT8rpgJEhsRAOyQefyGvmkJyEkBsEUmQe2lpm7W3jE3jdvnvy1zz7fF+GF1cWy/+e/+5/+v//+v/1v/uf/61//j3/85//y7//6P/7Lv9aff8Sff0z9X6j95x8lz59/jFxzKyGX9POPltsYPcvP//qf/uVf/+2//ud/+9/+/d/+9//1//wv/27PCD//6LHP0UNMTX6W76Tc0iypyKNSSjG0yJ//9f/+T//iXi5vblVe9Mtz8W/160sx7P/98lWup8048uv7HauTtcQcQ6+Ph+2DyHPwXFJLsdT969jmL++L...
null
5,529
Flipping bits
You will be given a list of 32 bit unsigned integers. Flip all the bits ($1 \rightarrow 0$ and $0 \rightarrow 1$) and return the result as an unsigned integer. **Example** $n = 9_{10}$ $ 9_{10} = 1001_2$. We're working with 32 bits, so: $00000000000000000000000000001001_2 = 9_{10}$ $11111111111111111111...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static long flippingBits(long n)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatc...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class FlippingBits {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tvoid solve() throws IOException {\n\t\tint t = nextInt();\n\t\tlong all = (1L << 32) - 1;\n\t\twhile (t-- > 0) {\n\t\t\tlong x = nextLong();\n\t\...
{ "class_name": null, "func_sign": [ "flippingBits(n)" ], "solution": "T = int(input())\nfor _ in range(T) :\n N = int(input())\n print(0xffffffff & ~N)\n", "template": "#\n# Complete the 'flippingBits' function below.\n#\n# The function is expected to return a LONG_INTEGER.\n# The function accepts ...
eJztm82ubcdVhWnwINZtR6iqVv3mSZC4iAakQeeShiNFQpF4CHg4ejwK3zdqxz46zglGCCWgY1v2OvuuvVbVnGOOMeas43/5y3/7j1/+Rf7663/n4m/++cs/fvv1b77/8svvvuzn67c29li1nTq4LqX3cso5XLez+pmzlK/fnt5mH2P1xudnPE/da86v33rrex9+4J51nl7a3t4+z3POPr1zS5n18WNur62VdvpqlXueZ60yx+7eP/csTyubx++n9j0fVlafWs9erC6PWYN7Do9Zz8P9u3lHWdw6nrxo8eeluJY2F8/Zg4c8a1d215aP...
null
2,624
Sansa and XOR
Sansa has an array. She wants to find the value obtained by [XOR](http://en.wikipedia.org/wiki/XOR#Bitwise_operation)-ing the contiguous subarrays, followed by [XOR](http://en.wikipedia.org/wiki/XOR#Bitwise_operation)-ing the values thus obtained. Determine this value. **Example** $arr=[3,4,5]$ ``` Subarray Op...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int sansaXor(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class Solution {\n\...
{ "solution": "import java.util.*;\npublic class SansaAndXOR {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int t = sc.nextInt(),tst=0;\n while(t>0) {\n tst++;\n int n = sc.nextInt();\n int[] arr = new int[n];\n ...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Solution {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n\t\n\tstatic void solve() throws Exception {\n\t\tint t = nextInt();\n\t\tfor (int tt = 0; tt < t; ++tt) {\n\t\t\tint n = ...
{ "class_name": null, "func_sign": [ "sansaXor(arr)" ], "solution": "for _ in range(int(input())):\n N = int(input())\n A = tuple(map(int,input().split()))\n X = 0\n for i, x in enumerate(A):\n if ((i+1) * (N-i)) % 2 == 1:\n X ^= x\n print(X)", "template": "#\n# Complete t...
eJzs3buuLktyHGAZsvUMjWOP0ZfqG009hQBtgAY5Bp3NMWYAAgQBvZFeUfFFLUogIBnye8gz02fvtf6/u7oqL5GRkf/jP/+3//lf/8t/+u//+sc//f7L3/76x98tf2y/fp+/fm/Ltv78Z/kP179+//Gn5Y8//8tf/vwPf/3zP/79P//tr//n9/74tz8t//GTNh/l11YfsuefI/+M/HPmnyv/3PnnyT/vsm35uS0/t+XntvzcNv6fX7b+377s8V37WPZ1PMtY32t5tjefdR3PWI79vp7lOs8j33rke/f/jw/Pz16/fh/3uT7XcS/7e2z3...
null
45
String Transmission
Bob has received a binary string of length N transmitted by Alice. He knows that due to errors in transmission, up to K bits might have been corrupted (and hence flipped). However, he also knows that the string Alice had intended to transmit was not periodic. A string is not periodic if it cannot be represented as a sm...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int stringTransmission(int k, String s)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class Solution implements Runnable {\n\n // leave ...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class Solution {\n private final static short MAX_N = 1000;\n private final static int MOD = 1000000007;\n public static void main(String[] args) throws IOException{\n StringBuffer sb = new StringBuffer();\n Buff...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class Solution {\n private final static short MAX_N = 1000;\n private final static int MOD = 1000000007;\n public static void main(String[] args) throws IOException{\n StringBuffer sb = new StringBuffer();\n Buff...
{ "class_name": null, "func_sign": [ "stringTransmission(k, s)" ], "solution": "T = int(input())\nM = 1000000007\n\nfrom math import factorial, sqrt\n\n\ndef nck(n, k):\n res = 0\n \n for i in range(k+1):\n res += factorial(n)//(factorial(i)*factorial(n-i))\n return res\n\n\ndef divisors(...
eJztHUmOLDuRBRI7zmC99ReK8GxOgkQjFvAWbJq/eF9CQkgcAu7BEXHYjiG7qlp/6Bq623aly+n0EBEOh8NDOv/96//+9n+/GuYPv+meP/7zy9+ev//h25ffuy/49BxcdwC68+U79+XrP77/+pdvX//657//8G3FCf3Jv75zJlV5em7RpdzTISIgwLimwfVbDnIM9eG6XWHIyYBTcPjTc3GjkGFHoaHf41VNz79516/uGVCyVQyRYWf0lwcNxsi4MbKKFjBFNNWi14qPK8uXGSvNOA4I9Q6BqxI6/WJzARNV8DbbfBIjQo1kRnMx3oT/...
null
328
Stone Game
Alice and Bob are playing the game of [Nim](http://en.wikipedia.org/wiki/Nim) with $n$ piles of stones with sizes $p_0, p_1, \ldots, p_{n-1}$. If Alice plays first, she loses if and only if the '[xor](http://en.wikipedia.org/wiki/Exclusive_or) sum' (or 'Nim sum') of the piles is zero, i.e., $p_{0} \oplus p_{1} \oplus \...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int stoneGame(List<Integer> p)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMi...
{ "solution": "import java.io.*;\n\nimport java.math.BigDecimal;\nimport java.util.*;\n\npublic class Solution {\n\n void solve()throws Exception\n {\n\n int testCases=1;\n for(int test=1;test<=testCases;test++)\n {\n solveTestCase(test);\n }\n\n }\n\n final static l...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n private static final int MODULUS = 1000000007;\n private static int n;\n private static int[] nums;\n \n private static String[][] testcases = {{\"3\", \"1 2 3\", \"4\"}, {\"10\", \"10 10 1 1 1 1 1 10 10 10\", \"321616...
{ "class_name": null, "func_sign": [ "stoneGame(p)" ], "solution": "import operator as op\nimport functools as ft\nfrom sys import stderr\nMOD = 1000000007\n\ndef readcase():\n npiles = int(input())\n piles = [int(fld) for fld in input().split()]\n assert npiles == len(piles)\n return piles\n\nd...
eJztmL+OJrcRxBX4JZQ1NhYMdjebTfpJBGhlB/YFStYKToABQ4AfQnpf/YrS2cZ3+pQ4snC7F8ztzJD9p7qqOP/6w4/vPv/s/nz5Zy6++ufLN2/ffvf+5U/2cl7feq/2udPNx/EzatveY1WdMbha/KEnVytG+T7bMsbiP6ft+PbTe7TlqeozclqMPjPizNe3ly/s5d0/vn331/fv/vaXv3/3/pc9V805T5/18v0X9l+x9OvbGt1zrRk2186z1knzzkVkfWyOUT2jyjxz5qgadnKv7JrcXXMv7z5PN548OLbnr+2bFe29bXUSwDphvtvP...
null
56
2's complement
Understanding [*$2$'s complement*](https://en.wikipedia.org/wiki/Two%27s_complement) representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static long twosCompliment(long a, long b)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class Solution ...
{ "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class Solution {\n \n private static Map<Long, Long> onesCache = new HashMap<Long, Long>();\n \n private static long computeOnes(long n,...
{ "solution": "import java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int testCases = in.nextInt();\n int baseCount = (int)sumBitCount(0, 65535);\n int boundary = Integer.MIN_VALUE;\n for (int i = 0; i ...
{ "class_name": null, "func_sign": [ "twosCompliment(a, b)" ], "solution": "t = int(input())\n\ndef gen(num):\n if num == '':\n return 0\n elif num == '1':\n return 1\n elif num == '0':\n return 0\n elif num[0] == '0':\n return(gen(num[1:]))\n else:\n return...
eJztXM3O5TgRZcGDWM0OTZB/yuUyT4JEj1jALNg0s+iRkBASDwHvyynnDn2/pCq3lLtDMww9t+PEsc+pHx8nlX/9+j+//f5X658//AY//viPT3/98uNPXz/9Pn0an79spYw26mylpkZz8mid9bDUWeag3BINmXXKpM9fCL9baXmkQrlI465HeVLPMudMpY5ZcSnPz1/mHHnMJDNzL7ngXiR5jMa5pNKlZM4yZI2AUpGBEz59lz798Pcff/jz1x/+8qe//fT1McxKs5H0mmf9/KUN/MDNMc7PXwpxp9kLjuCGuY/SZiachTFKztKnFPxl...
null
21,548
Maximizing the Function
Consider an array of $n$ binary integers (i.e., $0$'s and $1$'s) defined as $A = [a_0, a_1, \ldots, a_{n-1}]$. Let $f(i, j)$ be the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of all elements in the inclusive range between index $i$ and index $j$ in array $A$. In other words, $f(i, j) = a_i \opl...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> maximizingFunction(List<Integer> a, List<List<Integer>> queries)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n BufferedReader br;\n PrintWriter out;\n StringTokenizer...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n\n void solve() throws IOException {\n int n = nextInt();\n int q = nextInt();\n \n int[] b = new int[n + 1];\n fo...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint q = nextInt();\n\t\t\n\t\tint[] b = new int[n + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\...
{ "class_name": null, "func_sign": [ "maximizingFunction(a, queries)" ], "solution": "#!/usr/bin/python3\n\ndef init(A,n):\n retA = [0]*(n+1);\n B = [0]*(n+1)\n tmp = 0\n for i in range(n):\n tmp ^= A[i]\n B[i+1] = tmp\n retA[i+1] += retA[i] + tmp\n\n return retA,B\n\nif ...
eJzsnUuOJctyXdWQ5pG4bTbC3c1/HIJGIEAJqCG9BjuPbDwCBAgBGrp8r21xKn91xY4AiQhk4d5zqjJPekS4L/ub/a//+F/+8z/8p//wX//1j3/46z/989/++Pu3P/p1XW/6z/tfr7fn6/l6vp6v5+v5er6er+fr+Xq+nq/n6/l6vp6v5+v5er6er+fr+Xq+nq/n6/l6vp6v5+v5er6er+fr+Xq+nq/n6/n6//5LCXGx935ePa+eV8+r59Xz6nn1vHpePa+eV8+r59Xz6nn1vHpePa+eV8+r59Xz6nn1vHpePa+eV8+r59Xz6nn1vHpe...
null
3,263
XOR Subsequences
Consider an array, $A$, of $n$ integers ($A = a_0, a_1, \ldots, a_{n-1}$). We take all consecutive subsequences of integers from the array that satisfy the following: $$\{a_i, a_{i+1}, \ldots, a_{j-1}, a{j}\} \text{, where } 0 \le i \le j \lt n$$ For example, if $n = 3$ our subsequences will be: 1. $a_0$ 2. $a_1$ ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> xorSubsequence(List<Long> a)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void ma...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Solution sol1 = new Solution();\n sol1.process();\n }\n public void process() {\n Scanner sc = ...
{ "solution": "import java.io.*;\nimport java.util.Arrays;\n\npublic class HR_xor_subsequence {\n\n final static int bits = 16;\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n int prefixXor = 0;\n long[] counts = new long[1 << bits];\n ...
{ "class_name": null, "func_sign": [ "xorSubsequence(a)" ], "solution": "from sys import stderr\nfrom itertools import accumulate\nfrom operator import xor\n\nMAXNUM = 1 << 16\n\ndef main():\n n = int(input())\n a = [int(input()) for _ in range(n)]\n c = [0] * MAXNUM\n for elt in accumulate(a, x...
eJxM3c2qLEuyIGYNpPe43HEP0n/sJ/UkAhVoIN2BEJR60A0NQqAX0bsq/bNVoIKKwzl7+1qZaZYR7l94mP0///3/9P/+H//Df/c//1///r//8z//1//y7//jv/372esf/1zxOZ9//HN/9/r6x+f8458Zn0/8/u2uqH/881St3z9WZd9//DPu7fdn27gT+/Q//nm/5/P7s53799/yc2t+5Of3I+Nbnb+/8fspvx9yP9WGdf7+bUec36873/vGrf6+nxV1I72G/v1bfedH9vf9y33/6ca57wev9Xv90fvz+2979fm9gKx+f5Irfj/29v1+...
null
21,862
Iterate It
Consider the following pseudocode, run on an array $A = [a_0, a_1, \ldots, a_{n - 1}]$ of length $n$: ```pascal rep := 0 while A not empty: B := [] for x in A, y in A: if x != y: append absolute_value(x - y) to B A := B rep := rep + 1 ``` Given the values of $n$ and array $A$, compute and prin...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int iterateIt(List<Integer> a)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n private static final int l = 60000;...
{ "solution": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class G {\n InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n \n void solv...
{ "solution": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class G {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n...
{ "class_name": null, "func_sign": [ "iterateIt(a)" ], "solution": "input()\nA = set([int(m) for m in input().strip().split()])\n\ndef DeltaBasis2(AList,P=False):\n if type(AList) == set:\n AList = sorted(list(AList))\n if len(AList) == 1:\n return 1\n Count = 0\n \n while len(A...
eJxc3cuuJU2WHGYNCOgNNF6oMQcZ4XHlkwhQAxqQPeCk2INugAAhQI+uiO3+uUUKhb/6r8xz9o7wy7rYMrP+f//T//m//x/1v/1f/+sf//2f//Yf//6P/1L/2O4/+/4v/2y11VrL899H7c8/x/O/3j9bnv+cv/+11v377/dntuff7+fv33/en7qen3j/dP99yvb82fr81vs373+/n3c/v/f+bnt+dn3+5P37/fd777+tv0+6nv8+nv/efr9z//7X/fvt7ffd7fn9/kn376n239O1378v4/nv30/2p97mN+/Pf9rv39vv04/ff/qzvZ9y...
null
36,028
The Power Sum
Find the number of ways that a given integer, $X$, can be expressed as the sum of the $N^{th}$ powers of unique, natural numbers. For example, if $X=13$ and $N=2$, we have to find all combinations of unique squares adding up to $13$. The only solution is $2^2+3^2$. **Function Description** Complete the *powerSu...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int powerSum(int X, int N)" ], "script_name": "Solution", "solution": "import java.util.Scanner;\n\n\npublic class PowerSum {\n\tint count=0;\n\tint sum;\n\tint pow;\n public static void main(String[] args) {\n\t\tScanner in=new Scanner(System.in)...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\nclass Result {\n \n static int count=0;\n public static int Solve(int X,int pow,int N)\n {\n double temp = X - Math.pow(N,pow);\n int t = (int)temp;\n if(t==0)\n return 1;\n if(t<0)\n re...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int x = s.nextInt();\n int n = s.nextInt();\n \n int r = 0;\n for (int i = 1; i < x; i++) {\n r ...
{ "class_name": null, "func_sign": [ "powerSum(X, N)" ], "solution": "num1,num2 = int(input()),int(input())\ndef power_sum(num,count,total,pair_count):\n powered_num = num**num2\n if powered_num==total:\n return pair_count+1\n if powered_num < total:\n return power_sum(num+1,count-1,t...
eJyV0ksKwjAQBmBBD1KyLpJM8xpPIhhxoV24GbtoQRDBQ+g53Hk+42MhrcZJVoF8mfxk5jS53Maj55pf42ZxEFtqulbMCqHBBYJAoixEvW/qdVtvVruufR9bFMey+PBey0D2p5d97qJ1bI7GBDJsDi6W9myubFYYBT6nOtholWR7q6tAms8fjcoor1JtVX0spUx6GAzC60pGIEg9MBiErPRVMnw/uVHRIru6A0xN/JevDFSxOSL+mfjleXoHtEkmUQ==
null
35,940
Bowling Pins
Bowling is a sport in which a player rolls a bowling ball towards a group of pins, the target being to knock down the pins at the end of a lane. _____________________________________________________________________________________ In this challenge, the rules of the game are slightly modified. Now, there are a given n...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String isWinning(int n, String config)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n\tstatic int[] nim = new int[...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.util.*;\n\n/**\n * Created by naum_ on 29-Jul-17.\n */\npublic class Solution6 {\n\n private static Map<Integer, Integer> results = new HashMap<>();\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int t = sc.nextInt();\n for (...
{ "class_name": null, "func_sign": [ "isWinning(n, config)" ], "solution": "def game_from(board: str) -> list:\n game = []\n count = 0\n for c in board:\n if c == 'I':\n count += 1\n elif count > 0:\n game.append(count)\n count = 0\n if count > 0:\n...
eJztWM2O00AM5sA7IC6oynmFmkmTJtw5WEJw4MBIBO0BeuCS3UNXQkIr8RDwvjhjezI/SZvZNtIW1lHSZjI/jv35sye/nv959fKZEf0C/3z+mX3vbu/22ZtVVrZd3rQdxNJ2jWo7rTXohQSXrs0KrkDfvqlGVTogbVfgEK2zq1W2+3G7+7rffbu+udvza36C9203dsnur1a+OZoi0imSk0yCr10aXYNGtT6+8FJKocm3CSbX5kSdN+t+FK79SM4T3Z+jHcg1hyYKBuEItZk2AyJzfcy0aMkRxPeY8IEyodW7Dx/fHns11LDKU6PK8bc2...
null
21,904
Game of Stones
Two players called $P1$ and $P2$ are playing a game with a starting number of stones. Player $1$ always plays first, and the two players move in alternating turns. The game's rules are as follows: - In a single move, a player can remove either $2$, $3$, or $5$ stones from the game board. - If a player is unable to ma...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String gameOfStones(int n)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "//package yr16.m6.hackerrank.practise.gameTheory;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * Created by cscvenkatmadurai on 6/1/2016.\n *\n * https://www.hackerrank.com/challenges/game-of-stones-1\n */\npublic class GameOfStones {\n p...
{ "class_name": null, "func_sign": [ "gameOfStones(n)" ], "solution": "First = [2,3,4,5,6,9,10]\nSecond = [1,7,8]\nfor i in range(11,101):\n if i-2 in Second or i-3 in Second or i-5 in Second:\n First.append(i)\n else:\n Second.append(i)\n#print(First,Second)\ntest = int(input())\nfor _ ...
eJy9WEtu1EAUzAJxBVhGs46Q2+4vB+ACbJAYxCKZBRsngomEhJA4BJwXXr16BuJMZty2k9FYttvdbXd3vap6/ePZr+cvz/T37veLs7P33zaf+pvb/eb1+Sb4bV/kaLd9V7a9z3IZ5FqO1G37EOXesdxF3ndSPUn9LOWt1EnSLuFayr08L4FdOqkTM+8D6sk5ytFKuZM2bZJnUu4avtOjvTyTUyh2Ky2kxyy3BW9Hr/rPgd9VCvvFd3TSn5Nzllqbi/PN7uvN7nK/u/p4fbu30b759PnLftsfO73dXV73V/duR8WHK1f0u/BU39vS948n...
null
21,908
Tower Breakers
Two players are playing a game of Tower Breakers! Player $1$ always moves first, and both players always play optimally.The rules of the game are as follows: - Initially there are $n$ towers. - Each tower is of height $m$. - The players move in alternating turns. - In each turn, a player can choose a tower of...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int towerBreakers(int n, int m)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[]...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n // Gets values from standard in\n Scanner scanner = new Scanner(System.in);\n StringBuilder output = new StringBuilder();\n \n int testCases = scanner.n...
{ "class_name": null, "func_sign": [ "towerBreakers(n, m)" ], "solution": "\ntest = int(input())\nfor _ in range(test):\n n,m = map(int,input().strip().split())\n if m==1:\n print(2)\n else:\n if n%2==1:\n print(1)\n else:\n print(2)", "template": "#\n# ...
eJylmM1uJUkRhVnwECxTXo9QZmREZgZPgoQRC+gFGzOLHgkJjcSaHRK8L9+J6+nuuT+2R1iWfetWVVZGxIlzTtQ/f/3ff//mV/Xz+3/x4Q//ePrry/c/fH76XXsKf37Z69jebfS1ODqr97HaWWFpHPo4ftocc/jmMNfaHJ41+3l+yb07Z63PvvL5xc6ce7bIGX0+v3hsH9nGynCWmjnGWW1MruZBOdaa2TxmLla2PbfuPTkP965gW7ONY2fo0IefzdneM55fRsY53ua2oZX39t6jcYfvzsqxLVsEC6ROjjFm82lDh2tM39bCiEwrbV8r...
null
21,916
A Chessboard Game
Two players are playing a game on a $15 \times 15$ chessboard. The rules of the game are as follows: * The game starts with a single coin located at some $x,y$ coordinates. The coordinates of the upper left cell are $(1,1)$, and of the lower right cell are $(15,15)$. * In each move, a player must move the coin from c...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String chessboardGame(int x, int y)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n \n private static void past...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\nstatic boolean g[][]=new boolean[16][16];\n static int move(int i,int j)\n {\n int f=0;\n int p1=-1,p2=-1,p3=-1,p4=-1;\n if(i-2>=1&&j+1<=15)\n {\n if(g[i-2][...
{ "class_name": null, "func_sign": [ "chessboardGame(x, y)" ], "solution": "import copy\n\nmove = [(-2,1),(-2,-1),(1,-2),(-1,-2)]\ngrid_copy = set()\nfor i in range(1,16):\n for j in range(1,16):\n grid_copy.add((i,j))\n\nFirst = set()\nSecond = set()\n\nt=0\nwhile len(First) + len(Second) != 225:...
eJztWsuOHEUQ5MCHtPaKhTrrXXwAP8AFiUEc7D34MliwlpCQJT4CfpMbd6YyIrObYXc90zO7YMs+TK+nq7IemZURGTW/ff7HX198pv++/fPwx3e/3rzev3l7d/PVdJN2ewmTHD7TJOM/ccr6n7Lb37yYbm5/eXP78u721Q8/vr1jl69f//Tz3W7/ze3LH/evjp83715MK/Nht8+TzLt9neKDBs2CGj4ycOgVdGJ1zKtPIqeZud+a1MPa5qnv9nEscKw8jAG6/r16eRg28V2y7Shjm5r2Y4fRoOrm6bwOzU5cpD+Ovr2/0QMbfkqf+zYh...
null
21,912
Introduction to Nim Game
[Nim](https://en.wikipedia.org/wiki/Nim) is the most famous two-player algorithm game. The basic rules for this game are as follows: * The game starts with a number of piles of stones. The number of stones in each pile may not be equal. * The players alternately pick up $1$ or more stones from $1$ pile * The player t...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String nimGame(List<Integer> pile)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(Strin...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n Scanner s=new Scanner(System.in);\n int t=s.nextInt(...
{ "class_name": null, "func_sign": [ "nimGame(pile)" ], "solution": "\ntest = int(input())\nfor _ in range(test):\n pile = int(input())\n ar = list(map(int,input().strip().split()))\n xor = 0\n for n in ar:\n xor = xor^n\n if xor == 0:\n print('Second')\n else:\n print...
eJztmU2KJ8cRxb3wQZIG74Sp/M7UAXwBbQxu44U0C21awhqBwBh8CPmk3nnl936R1TajGY1akmEQmo/uf1dXZUZGvHjxIuofv/3nv3/3G/788V/68Ke/PXz+9OXXrx8+Tg/r8Wlej0/7SnOmfqW60lqpb38eK7WWek59pLF9vYy0Rpoj1VRbmrqgD2nr4055+UO7fIeen521cso51eHrTT/2tLV00tWaVk29pJmTlvGaQ8vql5iRmxfT55Jq9UJVt+nalcpKk8210fTiMnFk/0a37Pb4tPrjU9G1lrK2HWmXlEtqxUfQj6On3n1Ybaej...
null
21,905
Misère Nim
Two people are playing game of [Misère](https://en.wikipedia.org/wiki/Misère) Nim. The basic rules for this game are as follows: - The game starts with $n$ piles of stones indexed from $0$ to $n-1$. Each pile $i$ (where $0 \le i \lt n$) has $s_i$ stones. - The players move in alternating turns. During each move, the c...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String misereNim(List<Integer> s)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n//Day 2: Misere Nim\n public stat...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n Scanner s=new Scanner(System.in);\n int t=s.nextInt(...
{ "class_name": null, "func_sign": [ "misereNim(s)" ], "solution": "\ntest = int(input())\nfor _ in range(test):\n pile = int(input())\n ar = list(map(int,input().strip().split()))\n xor = 0\n for n in ar:\n xor = xor^n\n if ar == [1]*len(ar):\n if len(ar)%2 == 0:\n p...
eJzVnMuOHclxhr3wgxS4Foy8R6YewFsvvDEgGgYszUKblmCNAAOGAD+E/b7+/sjMqjqnm0P2NEe2h5yu5jlVeYnrH5es//zb//7Xf/gb/++ffsMvv/mPT79/+eOff/z06+OTfX4phf9rO/oR+WO9xGgpHMUOq6NFGy0dI6fSWoz1iDm3HnLn7uRPNDNLsR2W8pFTPawNPubBo9feeh0Wj1rS0XvqOQ/joVB6tcZdNXNvyXw/jhyKps/h6EwYmT7OP+vu3EIqPdbqnxazI/G3pVj0XBrMEC3XFkM+WhifX6L+D3ydQ2QHo1oqPNIKY+Va...
null
16,638
Alice and Bob's Silly Game
Alice and Bob invented the following silly game: - The game starts with an integer, $n$, that's used to build a $set$ of $n$ distinct integers in the inclusive range from $1$ to $n$ (i.e., $set = \{1, 2, 3, \ldots, n-1, n\}$). - Alice always plays first, and the two players move in alternating turns. - During each mov...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String sillyGame(int n)" ], "script_name": "Solution", "solution": "/*\n * Code Author: Akshay Miterani\n * DA-IICT\n */\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.ut...
{ "solution": "DNE", "template": "class Result {\n\n /*\n * Complete the 'sillyGame' function below.\n *\n * The function is expected to return a STRING.\n * The function accepts INTEGER n as parameter.\n */\n\n public static String sillyGame(int n) {\n // Write your code here\n\n }\...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class B {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t...
{ "class_name": null, "func_sign": [ "sillyGame(n)" ], "solution": "#!/bin/python3\n\nimport sys\n\nprime_pre = [0 for i in range(100001)]\nsieve = [0 for i in range(100001)]\nfor i in range(2, 100000):\n if sieve[i] == 0:\n prime_pre[i] = prime_pre[i-1]+1\n #primes.append(i)\n for j...
eJzlm9uKpUkRRr3wQYa+HiTPB/FGn0KwRHDsiwGpmYsZEETwIfRVvROMtbLUobrrsLtrV/cwg53bvfuP/5ArIzLii7///vN//vtXP/O/3/4r/s/v/vrm69tvv//uzS+/eFPmze0eqfab21xrvbmtO7d2c9tWWfvmtvS64lvtrZSb29nyWje3feYZHyXnXTly7Tgyj+LfjdlGGMTxGNQx45BV4tgwKKvHjyvlFYfM0nN8K63xrY2eF7cye/aOOufM8f3mdvCVH+tOcYWWOHKOwZ29+fKLN2//8u3br757+6c/fPP9d3eP9es/f/3V25vb...
null
21,910
Tower Breakers, Revisited!
Two players (numbered $1$ and $2$) are playing a game of Tower Breakers! The rules of the game are as follows: - Player $1$ always moves first, and both players always move optimally. - Initially there are $N$ towers of various heights. - The players move in alternating turns. In each turn, a player can choose a tower...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int towerBreakers(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n//Day 2: Tower Breakers revisited...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\nimport java.lang.*;\n\n\npublic class TowerBreakersRevisted{\n\tstatic long mod=1000000007;\n\t\n public static void main(String[] args) throws Exception{ \t\n \t InputReader in ...
{ "class_name": null, "func_sign": [ "towerBreakers(arr)" ], "solution": "def nim_sum(a,n):\n \n ans = 0\n \n for i in range(n):\n ans = ans^a[i]\n \n return ans\n\nt = int(input())\n\nwhile(t != 0):\n t -= 1\n \n n = int(input())\n a= [int(i) for i in input().split(...
eJztnMuOJtlVhRnwIKEaW+jcLzyJJQoxAA+YFB7YEhKyxDsAE56W71uRmKKvbs/c6i6XszLzj4hz2Ze1114n/v2v/+u/f/1X+e/X/8E//u7fPv3zl9/+/nef/vb5ND5/ufytZa3xnFVKXXyZ7bbnjHrGeXrtdezn3LU2353Vy3nu3oXftdLLuk87ve/+zNtn6c+Ye9T71HXnaE+/tZ711M5Hx3PrWv3ykX7Xftru2+vO7ac/a+7Fl3raqXw36jib35Vy51PvPGc8fbfKPfcepcyHj49dnjt3u8+cXHz5Va1cPXqrfLdqH7s9szEXbrLH...
null
21,911
Tower Breakers, Again!
Two players (numbered $1$ and $2$) are playing a game of Tower Breakers! The rules of the game are as follows: - Player $1$ always moves first. - Initially there are $N$ towers of various heights. - The players move in alternating turns. In each turn, a player must choose a tower of height $X$ and break it down into $...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int towerBreakers(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n//Day 3: Tower Breakers again\n ...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.util.Scanner;\n\npublic class Solution {\n \n public static int[] primes = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 2...
{ "class_name": null, "func_sign": [ "towerBreakers(arr)" ], "solution": "from functools import reduce\ndef mex(s):\n f=0\n m=max(s)\n for i in range(m):\n if i not in s:\n return i\n return m+1\ndef factors(n): \n return set(reduce(list.__add__,([i, n//i] for i in range(...
eJztnEvOLUdWhWkwkNRtl1C8H4yBASBhRAOqQcfQqJKQUEkMAubL+tbKc7FctrGBDiXb957//OdkRkbs2I+1195x/+3P/+P+1Z/5v79uevM3//rlH7/959//7stfPl/q+Obbq7+tPHX1/bTznKfVc5/anjpPfcZ+xnl6f+rQJUWXLH3bGh/NO+Z5RtcVpT/7uVW/7bOeNp8+uKjeOZ7enuEBNbp+1kf/T75tGv5Zd/BdL6szZr88fOnuXa9GuefZu6z5TE2xaITlcTVE4Rm1zcoDTl88RH/mXRqXpzVeh0Yqtzy7tbUZVLPVF3rdvTCd...
null
21,914
Chessboard Game, Again!
Two players are playing a game on a $15 \times 15$ chessboard. The rules of the game are as follows: * The game starts with $k$ coins located at one or more $(x,y)$ coordinates on the board (a single cell may contain more than one coin). The coordinate of the upper left cell is $(1,1)$, and the coordinate of the lower...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String chessboardGame(List<List<Integer>> coins)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n//Day 3: Chessboard G...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n int tests = in.nextInt();\n for (int test = 0; test < tests; test++) {\n int n = in.nextInt();\n int ...
{ "class_name": null, "func_sign": [ "chessboardGame(coins)" ], "solution": "grundy = [[-1]*15 for _ in range(15)]\ngrundy[0][0] = grundy[0][1] = grundy[1][0] = grundy [1][1] = 0\ndef moveCoin(x, y):\n if x > 1:\n if y > 0 : yield (x-2, y-1)\n if y < 14 : yield (x-2, y+1)\n if y > 1:\n ...
eJztXUuuLElSZcBCUjVuofBvuCPGbIAJEokYdNegJ69bUC0hISQWAStgo7wMOx+LfFXdVS0xaWUNou67NyPC3dzs2LGPe/7XX//P3/3vX13//eP4+sM//cd3v/3y+z/88N3fPr7rzy9lP7/Mx9cf6qMcX/95PMr18/PLfpTBX5QW/+ivT379uccf2vPL+Sivv5fHvq7j+uy8fl7X9fXn9Sj1euDXa3mcX+/Sn74+8uud1+X1xH597OtAxvVzv14+X0/oema/XlzG9bn+aK/xruu+11SWHlQqn/oaZoy1XzfW68nxrtejXi/B4NY1P071...
null
21,917
Digits Square Board
Two HackerRank staffers found a secret room with a mysterious $N \times N$ square board and decided to play a game with it. The game has the following rules: - At the beginning of the game, the players write a single digit (given as input) ranging from $1$ to $9$ in each $1 \times 1$ cell composing the $N \times N$ sq...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String squareBoard(List<List<Integer>> board)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n static final int ma...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class DigitsSquareBoard {\n static final int max = 60;\n static final int maxn = 30;\n static int[][]a;\n static int n;\n static int[][][][]g;\n \n public static ...
{ "solution": "import java.util.Scanner;\n\npublic class DigitsSquareBoard1 {\n \n public static final int MAX_N = 30;\n \n public static int memo[][][][] = new int[MAX_N][MAX_N][MAX_N + 1][MAX_N + 1];\n public static int[][] grid;\n \n public static void setMemo() {\n for (int i = 0; i < ...
{ "class_name": null, "func_sign": [ "squareBoard(board)" ], "solution": "#!/bin/python3\n\nimport math\nimport os\nimport random\nimport re\nimport sys\n\n# document globals\nN = None # board size \nB = None # board in 0/1 (is prime?)\nG = None # grundy\nRINT = None # rows in B as Int\nCINT = None...
eJztncuubklWnWn4NZCmUjSRVSvu4QfwC7iDRFpuQDXoHJBdSJYsJPf8AuZ92SvG+GL+WWQmZLksGSs5nMqz/8tasSLmZcwxL/t//rt//LP/9Sfn//7iT7/+8Zf/47u/+fZ3f/+77/5DfDe//7a+/1ZiRIsSz/m7v//2fP1YY8aO/vXW1yfW1z+f88L+euvrE+38s3/98Hz973uZWF8/rPPF8n7l/cLXd/3F+v23+fX6+7X19fITz/uVGs+5cf16qXyt4/379eH3C+18un1dfJ0LzfNnnffGuUZ5V/F+YJ+Fvyt5zsffq/WzlH4Wc+7x...
null
21,909
Fun Game
Kyle and Mike are bored on a rainy day and decide to pass the time by creating a new game having the following rules: * The game starts with two $n$-sized integer arrays, $A$ and $B$, and is played by two players, $P_1$ and $P_2$. * The players move in alternating turns, with $P_1$ always moving first. During each mo...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String funGame(List<Integer> a, List<Integer> b)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n \n static fina...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int T = input.nextInt();\n for(int t=0; t<T; t++){\n int n = input.nextInt();\n int[] a = new int[n];\...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n Scanner s=new Scanner(System.in);\n int t=s.nextInt(...
{ "class_name": null, "func_sign": [ "funGame(a, b)" ], "solution": "for i in range(int(input())):\n n, a = int(input()), [list(map(int, input().split())) for j in [0, 1]]\n s = [a[0][j] + a[1][j] for j in range(n)]\n x = c = 0\n \n for j in range(n):\n k = s.index(max(s))\n if ...
eJx8vUvObVuzXUUC6rH1p52Y4z0GBaACZJA4EgnshDMHC64lJIRELagQBaO3FutYpJDlc/e/9/etNed4xKNHjx7/13/9P/w///d/81/9j//Hv/7j3//pP//bv/7bP/86f/3dZ//r73vv/nN2b+fPbPvdP/2d/Pn1/v05a7f9535t9T+rz/0n/zT/7H7zT9/X55/z+jf+nH7On9HPHH96f+v+OXOf+2ft0daf++btf+486/zJb+eT7m1r/hlj3PVnrpGPufnc9Wd/Xz7snvzDn7vPaH/2PPvLl76dR2xnzzwWD3defnX1m4/Zb02eYPf8...
null
26,005
Stone Division
Consider the following game: - There are two players, *First* and *Second*, sitting in front of a pile of $n$ stones. *First* always plays first. - There is a set, $S$, of $m$ distinct integers defined as $S = \{s_0, s_1, \ldots, s_{m-1}\}$. - The players move in alternating turns. During each turn, a player chooses s...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String stoneDivision(long n, List<Long> s)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void ma...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextLong();\n int m = in.nextInt();\n l...
{ "solution": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.Map;\n\npublic class D {\n\tInputStream is;\n\tPrintWriter out;\...
{ "class_name": null, "func_sign": [ "stoneDivision(n, s)" ], "solution": "hist = {}\n\ndef foo(n, a):\n if n in hist.keys():\n return hist[n]\n for x in a:\n if n % x == 0:\n if x % 2 == 0:\n hist[n] = True\n return True\n nn = n // x\...
eJyVVUtqVFEQdSC4jUuPg9T/4wLcgBPBFgdJDzJpg3ZAEMFF6JacuSdPtRFFksDr0e13X1WdOudUva9Pv/989uT8e/0Dhzefd9fHm9vT7sXaOYWoOPuS/TFKObVKF4tVijvZ/ri7WLvDp5vD5elw9e797eku8tXh8v3xavflYv2TLshaeDHtj+Vtxin4I9UkgRPjklJqsTebogqeWUpkqqNoZ3ha9uJAuEQAF2daBLEAVVuZd+gcUylZ0rcBbGqjPAN0i84MtZUmKMsVq0WAwBUIOClASONlUBIgitGYmUlXD/BBlWIkc2y8wg1cSeZs...
null
2,594
Chocolate in Box
Dexter and Debra are playing a game. They have *N* containers each having one or more chocolates. Containers are numbered from *1* to *N*, where *i<sup>th</sup>* container has *A[i]* number of chocolates. The game goes like this. First player will choose a container and take one or more chocolates from it. Then, secon...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int chocolateInBox(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java.io.BufferedReader;\ni...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Solution {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n\t\n\tstatic void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tint xor = 0;\n\t\tfor...
{ "class_name": null, "func_sign": [ "chocolateInBox(arr)" ], "solution": "from functools import reduce\nimport operator\n\nn = int(input())\na = list(map(int, input().split()))\n\ngr = reduce(operator.xor, a)\nans = sum(1 for _ in filter(lambda x: x ^ gr < x, a))\nprint(ans)\n", "template": "#\n# Complet...
eJzsncuqbsmOnQ32E/gJJtmuRlwVEfUkBie4YZ9GddLVOAUFRYEf3eMbsY2NV6ThtAqDzok9899rr/nPi0IKaWhI8T/+w3/6j3//7//df/6X3/7hj3/8p7/+9vffb+33P3ZrX+x69t69/v7Hb3/3/faXf/7Hv/zXv/7lv/2X//5Pf/31i/zLv/7d93+cutfvf0SpX59znP6dVXvtq5Sv7tH6+eapX6xx9G/Ri75bf68lvhr6lbK/1ebu5dvtfGu3VeqaupFxvqOTe+jne7ahrxn6Z/3+bF1fXb4V+q61enx7faHf0tfqO+qIb/Fv46u9...
null
21,915
Deforestation
Alice and Bob are playing a game with a rooted tree. The tree has $N$ vertices and the first node, $1$, is always the root. Here are the basic rules: 1. They move in alternating turns, and both players always move optimally. 2. During each move, a player removes an edge from the tree, disconnecting one of its leaves o...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String deforestation(int n, List<List<Integer>> tree)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n \n static...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int t = in.nextInt();\n for (int i = 0; i < t; ++i) {\n solve(in);\n }\n }\n \n private static void ...
{ "class_name": null, "func_sign": [ "deforestation(n, tree)" ], "solution": "def hackenbush(i, p):\n v = 0\n for x in g[i]:\n if x==p:\n continue\n v = v^(hackenbush(x, i)+1)\n\n return v\n \nt = int(input())\nfor _ in range(t):\n try:\n n = int(input())\n ...
eJztfUuuJDuSnQZaSOCNGw03/qmZehUClIKAbtWgAeFVD6oBAYIALUJajvYmng893D1uvnpZpYGAyhzcYN4bwfDwoBntHDtm/J//9n/X//Nv+O8//P0a/Mf//ss///ov//qnX/7d65f49muJ/O3XeCX84KjgR8WPhh/926/5NTCa335NrzjWS16xXhjxivWq8cIE+RV8XawXzlesV9ZXrJfG+gNevF7Il6f18vZKwTHes74S3rW/UtH/qh6aftn59KH/rBlivPKaIrVX5hx5zdFfOeP9cuF4TZDzKze8MvP1eeCiMi4gvcp6ee6vgpcf...
null
15,132
Bob and Ben
Bob and Ben are playing a game with forests! The game's rules are as follows: * The game starts with a [forest](http://mathworld.wolfram.com/Forest.html) of $n$ trees. * Bob always moves first and they take alternating turns. The first player with no available move loses the game. - During each move, the player remove...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String bobAndBen(List<List<Integer>> trees)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\npublic class d {\npublic static void main(String[] args) throws IOException {\n\tinput.init(System.in);\n\tPrintWriter out...
{ "solution": "import java.util.Scanner;\n\nclass Solution{\n static void solve(){\n Scanner sc=new Scanner(System.in);\n int ngame=sc.nextInt();\n for(int i=0;i<ngame;++i){\n int ntree=sc.nextInt(), xor=0;\n for(int j=0;j<ntree;++j){\n int nnode=sc.nextInt();\n sc.nextInt();\n...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tint game(int n) {\n\t\tif (n == 2) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (n % 2 == 1) {\n\t\t\treturn 1;\n\t\t}\n\t\treturn 2;\n\t}\n\n\tvoid solve() {\n\t\tint tc = in.nextInt();\n\t\tfor (int t =...
{ "class_name": null, "func_sign": [ "bobAndBen(trees)" ], "solution": "import sys\n\nfor _ in range(int(sys.stdin.readline())):\n ones, twos, rest = 0, 0, 0\n n = int(input())\n for i in range(n):\n m, k = map(int, sys.stdin.readline().split())\n if m == 1:\n ones += 1\n ...
eJzsfTuPNUlynQz+kMbYa+T7QXMBWgJIV4AGoEGuQWe5xi5AgCAg/XOdR2b17bq90ylDgkTUGrnzdd+uW5UVGY8TESf+x9/8t//5X//mv/z3f//lX/74p7/8+Ze//fgl/vrH2EII+L+P9CzP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP8izP...
null
21,918
Tower Breakers - The Final Battle
Our unsung tower-breaking heroes (players $P_1$ and $P_2$) only have one tower left, and they've decided to break it for a special game commemorating the end of $5$ days of Game Theory! The rules are as follows: - $P_1$ always moves first, and both players always move optimally. - Initially there is $1$ tower of heigh...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int towerBreakers(long n)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n \n static final long maxx = 100000000...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n public static int maxcost = 127;\n\n public static void main(String[] args) throws IOException {\n in = new InputReader(System.in);\n out = new PrintWriter(Sy...
{ "class_name": null, "func_sign": [ "towerBreakers(n)" ], "solution": "largest = 1000000000000000000\nT = int(input())\nheight = [0]*1000\nheight[0] = 1\nfor i in range(1,261):\n for j in range(1,int(i**0.5)+1):\n height[i] += height[i-j*j]\n if(height[i]>largest):\n break\n\nwh...
eJyNms2OJTkRhVnwBuxYjXrBaoTs8D9PgkQhFjALNsMsZiQkNBIPAe/Ld44zb/ne7uqhVdV1K9Nph8MR55yIrH//+r+//d2v/O+Pv+HDn/716e/f//DTj5/+8M2n1t++b6lHiZb5mGtrM61U+Bh1jmgt1bfv+yx5lDm5XGefY+SRGNFyaimP9fZ9pNEYUHvVg4wcoy59LrlE6mPw5Gyr1jxCD65cCwvwMcVcKbqu5jpCQxufV521rV5syBq9jap1cl6R04jJx86E0Xv28FHSyDH0maV7T1jBzkqvjSW5XEbPpZTIjJg9am9VlyOVmWpf...
null
59
Permutation game
Alice and Bob play the following game: 1. They choose a permutation of the numbers $1$ to $n$. 2. Alice plays first and they alternate. 3. In a turn, they can remove any one remaining number from the permutation. 4. The game ends when the remaining numbers form an increasing sequence of $1$ or more numbers. The ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String permutationGame(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\tprivate void solution() throws IOException {\n\t\tint ts = in.nextInt();\n\t\twhile (ts-- > 0...
{ "solution": "import java.io.*; \nimport java.util.*; \nimport java.text.*; \nimport java.math.*; \nimport java.util.regex.*; \n\npublic class Solution { \n\n public static Scanner sc = new Scanner(System.in); \n public static void main(String[] args) { \n int t = ni(); \n for(int i=0; i...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n static int[] perm;\n static Integer[][] res;\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int cases = sc.nextInt();\n for (int i = 0; i < cases; i++) {\n p...
{ "class_name": null, "func_sign": [ "permutationGame(arr)" ], "solution": "States = {}\n\ndef win(L) :\n# print(L)\n# print(States)\n r = States.get(tuple(L), None)\n if r :\n return r\n if isSorted(L) :\n r = False\n else :\n r = False\n for l in L :\n if not win(extract(l,L)) :\n ...
eJydVk1r21AQ7KGn/oqHzqFo36fUW/orClUpNPEhNCg5OFAIhf6I9v92Z/bZVmQ7shISYp6edmdnZ2f95/2/nx/e8efLrX74+tzcjY9P2+aTa+Iw9sMozrvgiksuu+g61/O0d3YeeV5cN4xhGHEiw1j0d/p8GJsr12x+PW5utpvb7w9P25rh88OPYby+v7vZzP81v6/cBIoGlWTx9xmdYmidiBPvRPNGJwnZz+Q6HTgTd1CsNUVG2ICYSBEZn4Gj5k641w5jAi2RBQIVgOF1QSTiEkLTC8Za4StkR0/iG/h4lR3ARupcU8YJJkAVBYV6...
null
46
Stone Piles
There are $N$ piles of stones where the ith pile has $x_i$ stones in it. Alice and Bob play the following game: 1. Alice starts, and they alternate turns. 2. In a turn, a player can choose any one of the piles of stones and divide the stones in it into any number of unequal piles such that no two of the newly created...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String stonePiles(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Solution implements Runnable {\n\n // leave empty to read from stdin/stdout\n ...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.util.HashSet;\nimport java.util.ArrayList;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java...
{ "class_name": null, "func_sign": [ "stonePiles(arr)" ], "solution": "from collections import Counter\n\nncases = int(input())\nndigs = [0, 1]\nwhile len(ndigs) <= 50:\n ndigs += [ndigs[-1]+1] * len(ndigs)\nlosers = set([1, 2, 4, 8])\nfor _ in range(ncases):\n npiles = int(input())\n ctr = Counter...
eJzNmD9vJEUQxQn4AoiEsOX4hKaru6enyThEgIREioQRATggWS7wSUgIiQ8B35d6v6q1wNi+Ww5LeL3e8Uz/qXpV9V71/vb+Hx99+B4/X3/gF9/8cvXj6dXr26tPytW8PnV/12JbsV5qK/UobRY7Sq26c3A5S9tLr6Va6Zuu/cJa6Ufps+yldV2aj/LJTTPrVmrXw6E1zUf7aqVtXGpMHznFx5auOdensV2ffAVfu64ySzc9988ui7S1T/D1hvZrq/RdqzXd8G2NDd2gha2NZbDIHfAJq2CY+xnWDTnQhpbQ7SEL3RK9fN1V9uuTDUfG...
null
800
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 for...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int chocolateGame(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\tpublic static void main(String[] args) {\n\t\tnew Solution().run();\n\t}\n\n\tBufferedReader br;\n\t...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n /*\n * Complete the chocolateGame function below.\n */\n static long chocolateGame(int[] arr) {\n long result = (arr.length - 1L)*arr.length/2;...
{ "solution": "import java.util.Scanner;\nimport java.io.StreamTokenizer;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.TreeMap;\nimport java.io.PrintStream;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/...
{ "class_name": null, "func_sign": [ "chocolateGame(arr)" ], "solution": "from operator import xor\nfrom itertools import accumulate, chain\nfrom collections import defaultdict\nfrom bisect import bisect\nfrom sys import stderr\n\ndef main():\n npiles = int(input())\n piles = [int(f) for f in input()....
eJztncuu40rSnT34H4TY4wMjb5ER0U9iwGX0oLsGPak+gzpAA40GPPfUL+uZV1Da2qJESqQu+1JnFWOt+EpboigyyUySSfJ//9f/+D//77/+2//898s/fvz+x8+XvwwvOaVvP1oZGOvi5bfh5fu/fv/+t5/f//7Xf/7xcz8bSxPMx5f//DYczVvDS7mp9iQ2lGSeTNNQLHu31odq3Qo0mNdu0mzwqjlJToN3qV6SDvhvsaQepC3VbGnINbuDHaRdi6kNuadeGgZQS1k13tetVsWHh6wmVktuQzYXSVYxPnxHrhjVUDI+p0WCquN9DROZ...
null
3,568
The Prime Game
Manasa loves the [nim game](http://en.wikipedia.org/wiki/Nim), in which there are $n$ buckets, each having $A_i$ balls. Two players play alternately. Each turn consists of removing some non-zero number of balls from one of the bucket. A player with lack of moves looses. But, Manasa having played it so many times, she g...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String winner(List<Integer> A)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static final int[] M = {2, 3, 5, ...
{ "solution": "import java.io.*; \nimport java.util.*; \nimport java.text.*; \nimport java.math.*; \nimport java.util.regex.*; \n\npublic class Solution { \n\n public static void main(String[] args) { \n int t = ni(); \n for(int i=0; i<t; i++){ \n System.out.println(solve()); \n ...
{ "solution": "import java.util.HashSet;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**...
{ "class_name": null, "func_sign": [ "winner(A)" ], "solution": "def firstwins(sizes):\n nim = 0\n for size in sizes:\n nim ^= (size % 9) // 2\n return nim != 0\n\nncases = int(input())\nfor _ in range(ncases):\n nbuckets = int(input())\n sizes = [int(fld) for fld in input().split()]\n...
eJxEnTmybVlSbRFoAQrqtlRQV11kSzAjOoAShgASCk3Hx/B1Ivl8IuK9e8/ZexVeTJ8+/f/++d//7V/+9Z/+43//9p9//tf//Pff/v797fzx5zln/PHnHWvd+Z1ZW53fPW2t9fXytf6N1UY9X6v7zPm1cU79avtG/GX9xplnlW+tWWf/6qqljt1X/EX/zp27rG+0b359fG197X51zhs/287mR1pfq9evx3etXkqJT/jqPSO+6LaySnzO/lr7zhorvnP1eXZ8Uj0rnrKufvYaZ5yvTz4t/u/dZ9/43PjG/cVT9+433vHV+O87e+t1nvjd...
null
2,497
A stones game
Koga and Ryuho, new generation Athena's saints, are training to improve their control over the cosmos. According to the ancient Masters, a saint's power to control the cosmos strengthens, when one allows the energy of the universe to flow within the body and then concentrates it. This energy can even be used to explode...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int half(int n)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.OutputStream;\nimport java.io.Writer;\nimport java.io.IOException;\n\npublic class StonesGame {\n static public void ...
{ "class_name": null, "func_sign": [ "half(n)" ], "solution": "import time\nimport sys\nimport itertools\n\nstart = time.time()\n\ndef f(x):\n\tif (x == 1) or (x % 2 == 1):\n\t\treturn 1\n\tp, log = 1, 1\n\twhile p * 2 <= x:\n\t\tp *= 2\n\t\tlog += 1\n\txor = log ^ 1\n\tans = x + 1\n\t# print(p, log, xor)\n...
eJztm8mqZcl1ho0x+DWKHAsRfaMnMTiNBlINPEnVoAoERuCH8AP7+/+42dxz9j6ZNbNhSUHFynN3E7FiNf9q9n//y7/96x//+Z/+/b8+/OenX3779cOffvrQPn4qveY8Sl8fP80yd2o9f/w0SqujzF4+fqot9zV249cPf/jpw89//+Xnv/z681///Lfffn17SGl9zo+fuCCPunhk/vCPP/z0zVt4yuy99LQ2j8671TXbvH1efn5C//iplT1LWoNn7T5zHzy158ZyKzf0WUeta/DUPVspe+Vx+4KaZuGemmfrZ91vS394a2MvfY/U64Ba...
null
26,946
Tastes Like Winning
Stephanie just learned about a game called *Nim* in which there are two players and $n$ piles of stones. During each turn, a player must choose any non-empty pile and take as many stones as they want. The first player who cannot complete their turn (i.e., because all piles are empty) loses. Stephanie knows that, for...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int tastesLikeWinning(int n, int m)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n private static final long mod ...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class TastesLikeWinning {\n private static final long mod = 1000000007;\n private static long m;\n private static long pow;\n \n public static void main(String[] args) {\...
{ "solution": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class G {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n...
{ "class_name": null, "func_sign": [ "tastesLikeWinning(n, m)" ], "solution": "_=input().split()\nmod=10**9+7\nn=int(_[0])\nm=int(_[1])\nM = pow(2, m, mod) - 1\ncomb_n_1 = (M%mod)* ((M-1)%mod)\nnim_n_2 = 0 #total number combinations that is nim for n-2 stacks\nnim_n_1 = 0 #total number combinations that is ...
eJyVk71Kg1EMhh16IYdvLpLfk8QrEVQctINL7dBCQQTvwEW9XqPtIOcjlmY6w3nyJm+St8Xn1+LiN67f83HzMj2tN7vtdNUmo4bspsi362nZptV+s3rYrh7vn3fb4xcyiDAQml6X7Q/q3ByQAmo0Ahw6aR9QStQtIqhEpWfujqwDihqtE7mhlqwLGpOYDKwEs7dQdSQvacNu6B3HfhkUoSECG2CtjWquc7cUspvWjVQZam3prCbKY9fGAeDNyBh7iTMbp3E+8xsCSbCxSmSGmtee81Ie+S4AHLkqvXfz2rocFwGq2Fh+qw3D+V84RL2R...
null
128
Find the Point
Consider two points, $p = (p_x, p_y)$ and $q = (q_x, q_y)$. We consider the inversion or [point reflection](https://en.wikipedia.org/wiki/Point_reflection), $r = (r_x, r_y)$, of point $p$ across point $q$ to be a $180°$ rotation of point $p$ around $q$. Given $n$ sets of points $p$ and $q$, find $r$ for each pair of p...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> findPoint(int px, int py, int qx, int qy)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public s...
{ "solution": "/**\n * symetry\n */\n\nimport java.util.Scanner;\n\npublic class symetry {\n\n public static void main(String[] args) {\n\n Scanner scan = new Scanner(System.in);\n int N = scan.nextInt();\n\n for (int i = 0; i < N; i++) {\n int X1, X2, Y1, Y2;\n \n ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n Scanner s=new Scanner(System.in);\n int t=s.nextInt();\n for(...
{ "class_name": null, "func_sign": [ "findPoint(px, py, qx, qy)" ], "solution": "def symp(Px,Py,Qx,Qy):\n return '{} {}'.format(2*Qx-Px,2*Qy-Py)\n\nfor i in range(int(input())):\n print(symp(*[int(i) for i in input().split()]))", "template": "#\n# Complete the 'findPoint' function below.\n#\n# The f...
eJzll91qLUUQhb3w3lco9vVpmer/8UkEI15oLkSIB8kBQQQfQt/X9VVPTrY7meCFoGCSvdMz010/a62q7vnt0z9++uyT+PnyBw2++uXy/cP7D4+XL+zifvfgxcq06daqLizlYqOb71yUbsndssbZys6DVMfdw8jWiqW9Wioy0XT7uJ5a16alzlDGNk0u5tNamL576NnS0IQ819NUbbjtumJp2oceV+vdFM3lnV3uf35//+3j/Xff/Pjh8Snqqki01GWzyz0hp0KQdVO8pXCrM/TGsFbLhOl5syyzeSc+PXHFVaZubJqcq/xnPZv58us7...
null
1,111
Maximum Draws
A person is getting ready to leave and needs a pair of matching socks. If there are $n$ colors of socks in the drawer, how many socks need to be removed to be certain of having a matching pair? **Example** $n = 2$ There are $2$ colors of socks in the drawer. If they remove $2$ socks, they may not match. The mi...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int maximumDraws(int n)" ], "script_name": "Solution", "solution": "import java.util.*;\n\n/**\n * Created with IntelliJ IDEA.\n * User: Admin\n * Date: 10/25/13\n * Time: 5:28 PM\n * To change this template use File | Settings | File Templates.\n */...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String totalCasesStr = br.readLine();\n int totalCases = Integer.parseI...
{ "class_name": null, "func_sign": [ "maximumDraws(n)" ], "solution": "t = int(input())\nfor i in range(t):\n n = int(input())\n print(n+1)", "template": "#\n# Complete the 'maximumDraws' function below.\n#\n# The function is expected to return an INTEGER.\n# The function accepts INTEGER n as parame...
eJztncuuLUlOhkFixku0zriF4n7hKRgisRAD6AGTogfdEhJqiYfggfH/2ZFrnVPsGnDpAR2lUzsz914ZGWE77N9/xEr/+1/87d/85Z//2d/927d//um3v//dt7/+1bf5+sn+5ddPY7bXT7vk0u262y9aT6Vv/vbt17/69pt//e1v/vF3v/mnf/iX3/8u7l2vn4pu7HGjXffiN47E37794de/+nhYp7XPf1+0XLj7+fdDMzl7673llrOf+iDaGnnYOEoeY9jTamrLhrCG/Wnq/zVatesy+Pje065yr9k/U+2WktJ5bK/Tfs6qxv033mkb...
null
1,161
Handshake
At the annual meeting of Board of Directors of Acme Inc. If everyone attending shakes hands exactly one time with every other attendee, how many handshakes are there? **Example** $n = 3$ There are $3$ attendees, $p1$, $p2$ and $p3$. $p1$ shakes hands with $p2$ and $p3$, and $p2$ shakes hands with $p3$. Now the...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int handshake(int n)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n ...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static HashMap<Integer, Integer> table;\n \n public static void main(String[] args) throws IOException {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solut...
{ "class_name": null, "func_sign": [ "handshake(n)" ], "solution": "t = int(input())\nfor i in range(t):\n #Nc2\n n= int(input());\n print(int((n*(n-1))/2))", "template": "#\n# Complete the 'handshake' function below.\n#\n# The function is expected to return an INTEGER.\n# The function accepts IN...
eJztnU2ObUmylWkwkFK1n5D//zASBIkQgmrQKV6jnoSEkBgEDIQZsta3POJmZtWFRweBdDKle3ZEnLO3u7n9LFtm7ue//tP//m//xz/hv3/xL3Xxr/7zH//Dn//+H/7yx3/+hz+O88uf5zlr//Lntnb75c9dF6NO/VtO1b99V/12Nf/Qxz5LP5Rzr/6kN53bi34xx9x+mUU/9bmb3uUP6976uK6OHnNP7q53nrH8qLvae+LkvoMfuj91qp/Qb+fup3C/06f+vWP6x9MvzxyD98yql7H75p3+1ShdIxx6HyO5eTNz8jDrYsxt9fHHv/vD...
null
40,465
Minimum Height Triangle
Given integers $b$ and $a$, find the smallest integer $h$, such that there exists a triangle of height $h$, base $b$, having an area of at least $a$. ![image](https://s3.amazonaws.com/hr-assets/0/1496306792-f2c37eea44-triangle.jpg) **Example** $b = 4$ $a = 6$ The minimum height $h$ is $3$. One example is a...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int lowestTriangle(int trianglebase, int area)" ], "script_name": "Solution", "solution": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static int lowestTriangle(int base, int area){\n int h=(2*area)/base;\n if((((double)(2*area))/base)>h){\n return h+1;\n ...
{ "class_name": null, "func_sign": [ "lowestTriangle(trianglebase, area)" ], "solution": "#!/bin/python3\nfrom math import ceil\nimport sys\n\ndef lowestTriangle(base, area):\n return (2*area+base-1)//base\n\nbase, area = input().strip().split(' ')\nbase, area = [int(base), int(area)]\nheight = lowestTri...
eJyVk79KBEEMxi2utfMBwtSHTCaZ/PFJBBUL3cLmvGIPDkTwIfR9XVYEyZHbNdXA5Ddf8iXzsfm62lzMcXs5He7eystufxjLDRQmsW6gYk31fle2UIbjfngah+fH18P4m1Xet/CHwirCYFIrSgqhtICZ9OYNjNHYUi5ShISsYC6iOSWRMqFq4Kr1jFakWqUqDs2IlFKKAtWdeiXgroy+ui8U79yAHNFyF3ukaCqRwVGEci2MGHdyUWhKeqaxkxIB/5Nb58iJn/uTXZrjjBJmxJJe9ABym+NICdrqd32OxXKiRFskMDEM1i+ZAubjnr71...
null
27,196
Army Game
Luke is daydreaming in Math class. He has a sheet of graph paper with $n$ rows and $m$ columns, and he imagines that there is an army base in each cell for a total of $n \cdot m$ bases. He wants to drop supplies at strategic points on the sheet, marking each drop point with a red dot. If a base contains at least one pa...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int gameWithCells(int n, int m)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[]...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int m = in.nextInt();\n Sys...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int m = in.nextInt();\n int...
{ "class_name": null, "func_sign": [ "gameWithCells(n, m)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nn,m = input().strip().split(' ')\nn,m = [int(n),int(m)]\n\nprint(((n+1)//2)*((m+1)//2))\n", "template": "#\n# Complete the 'gameWithCells' function below.\n#\n# The function is expected to return a...
eJydkU0KwjAQRgU9yJB1kUz+pvEkgooL7cJN7aIFQQQPoWdy55mMxYVMmWDNKpD3Zd7MXGf353TSn+UjXVZndaibrlULUB5wXasCVHVqql1b7bfHrv28WXUp4Iu1GdYw1mRYZCx6Autk3DpuQhHQkixDQXOfkCLoxQiVlkciYaYJVwYuRRqsXID4/wTRyUJYRj7TAN7IQqkDPtcxOwDUWou419z+jWf+lwK5IiaFBrEY4x+pvliKjksZMD8PzGZ27QabRhk2JaOTGXgtjzYY8sl8c5u/ABSAIdM=
null
17,750
Leonardo's Prime Factors
Leonardo loves primes and created $q$ queries where each query takes the form of an integer, $n$. For each $n$, count the maximum number of distinct prime factors of any number in the inclusive range $[1, n]$. **Note:** Recall that a prime number is only divisible by $1$ and itself, and $1$ is *not* a prime number. ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int primeCount(long n)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\...
{ "solution": "\nimport java.util.Scanner;\n\npublic class Solution {\n\n static Scanner scan;\n\n static StringBuilder sb;\n\n static int[] primeFactore = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };\n\n public static void main(String[] args) {\n scan = new Scanner(System.in);\n...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.util.stream.IntStream;\n\npublic class Solution {\n public static final HashSet<Integer> primes = new HashSet<Integer>(Arrays.asList(2,3));\n public static final ArrayList<Integer> primesArr = new ArrayList<>(Arrays.asList(2,3));\n public sta...
{ "class_name": null, "func_sign": [ "primeCount(n)" ], "solution": "q = input()\n\nprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59]\n\ni = 0\nwhile i < int(q):\n n = int(input())\n maxFacts = -1\n product = 1\n k = 0\n while n >= product:\n maxFacts += 1\n ...
eJzsncnOLUuSlRHiQVI5roH3DU+CxJYYQA6YXGpQJSEhJMY8AM+Lfcs8Ijz29ssc6Zby1D3nb2KHu5tbu2zZ//p3/+H//O9/+2/+4//4+3/945//9V/+/u//9vfY6+ePMWqvKaZS6/j80VMsMczaUx7p80cuoY0aU641f/4oJac0+G/t5fNHirm0OduMo33+qCXHZt/MvccUPn80e1K1r6cco/1KSqXYV8ecNXT7b56z2795gxR6sM8cM5ScZ7InjzRb4pkzxGy/bS+Q+gwjjj6zntZGjrX1VCfvUeMcOZdeZg5j2ONLCCnZD9aWY7ef...
null
1,158
Connecting Towns
Cities on a map are connected by a number of roads. The number of roads between each city is in an array and city $0$ is the starting location. The number of roads from city $0$ to city $1$ is the first value in the array, from city $1$ to city $2$ is the second, and so on. How many paths are there from city $0$ t...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int connectingTowns(int n, List<Integer> routes)" ], "script_name": "Solution", "solution": "import java.util.*;\n\n/**\n * Created with IntelliJ IDEA.\n * User: Admin\n * Date: 10/25/13\n * Time: 5:28 PM\n * To change this template use File | Settin...
{ "solution": "import java.util.*;\n\npublic class Solution {\n\n Scanner in;\n public void numRoutes() {\n int numTests = in.nextInt();\n for (int i=0; i<numTests; i++) {\n int numTowns = in.nextInt();\n int numRoutes = 1;\n for (int j=0; j<numTowns-1; j++) {\n ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) throws IOException {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n BufferedReader br = new Buffered...
{ "class_name": null, "func_sign": [ "connectingTowns(n, routes)" ], "solution": "t = int(input())\nfor i in range(t):\n n = int(input())\n p = 1\n r = input().split(' ')\n for i in range(n-1):\n p = p*int(r[i])\n p = p%1234567\n print(p)", "template": "#\n# Complete the 'conn...
eJztncuuJkdWhRnwIKkat1DcdwQS74FEIQbgAZOiB24JCbWExCvA+7K+tX+XaB//7sLuCXRYPllZeTLjsq9rR2as+ve//K+/+Y+/8H9/u3Tyd//26Z+//PZ333/66+dTbZ+/dP3f2jPL0Il+6tnPGv3Zpzyxz7P0996Krp1n7vH088Q8TzvtiV6fplsj4mmLH90W5+nc1otu3U/V02s+czyn9Weop9BvhzuIZ0Z9Zlf7ww/uVhjA5y9n6UILtRS6vz1DPY5y/MzW8zU04jrVZn2i1Gf39TS11XWtatDjmSfUVNWcNLCqwa7SNCB1O9R9...
null
26,273
Cutting Paper Squares
Mary has an $n \times m$ piece of paper that she wants to cut into $1 \times 1$ pieces according to the following rules: - She can only cut *one piece of paper at a time*, meaning she *cannot* fold the paper or layer already-cut pieces on top of one another. - Each cut is a straight line from one side of the paper to...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static long solve(int n, int m)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) ...
{ "solution": "DNE", "template": "class Result {\n\n /*\n * Complete the 'solve' function below.\n *\n * The function is expected to return a LONG_INTEGER.\n * The function accepts following parameters:\n * 1. INTEGER n\n * 2. INTEGER m\n */\n\n public static long solve(int n, in...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class A {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t...
{ "class_name": null, "func_sign": [ "solve(n, m)" ], "solution": "n,m = [int(i) for i in input().strip().split(\" \")]\nprint(n*m - 1)", "template": "#\n# Complete the 'solve' function below.\n#\n# The function is expected to return a LONG_INTEGER.\n# The function accepts following parameters:\n# 1. INT...
eJyVlM1qVEEQhV3oezR3HaT+f/IkgooLnYWbJIuZEAiBPIS+rycxI9KTHrQXzeXSfar6q1P1+Pbn7bs3z+vDNT4+3m/fr24O++1ybGapJpw1siLZSvnT1XYxtt3dze7rfvfty/Vh/3JWnVspxTvMjJtze7gYf4kxNTd5jSoK9yZaanWwt0o5McJ3T0pVAZ00GhVCztW1lMrQkgou97AqJDmJqVBApXM0F3cW5VJM2kxZwMSfuEjWLNbu2aQ2hLJNcGEpViKewaBbEtrtk5Y0cSpXjqBMizBZajGe6ZzZ3Rng6zqJWZR2ROuAZqAU2evE...
null
2,147
Summing the N series
There is a sequence whose $n^{\text{th}}$ term is $$T_n = n^2 - (n-1)^2$$ Evaluate the series $$S_n = T_1 + T_2 + T_3 + \cdots + T_n$$ Find $S_n \bmod (10^9+7)$. **Example** $n = 3$ The series is $1^2-0^2 + 2^2-1^2 + 3^2-2^2 = 1 + 3 + 5 = 9$. **Function Description** Complete the *summingSeries*...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int summingSeries(long n)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.InputStreamReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io...
{ "solution": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.InputStreamReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.mat...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n int T;\n Scanner s = new Scanner(System.in);\n T = s.nextInt(); s.nextLine();\n for (int i = 0; i < T; i++) {\n BigInteger n = ...
{ "class_name": null, "func_sign": [ "summingSeries(n)" ], "solution": "t = int(input())\nwhile (t):\n t -= 1\n n = int(input())\n print(pow(n,2, 1000000007))", "template": "#\n# Complete the 'summingSeries' function below.\n#\n# The function is expected to return an INTEGER.\n# The function accepts LO...
eJzVlr9uJkUQxAnIeImT4xPqP9M93bwISBgI4AISc8GdhISQeAh4X369tg/f3rciImADa7/d2Z6q6qoe//H5X99/8dlxffM1N9/+dvfzw9v37+6+enW37x/UTE1brUL2Lr1/iO1SO3WtHZrqsya39G6XFdbJmm3SobF0h5VQptJVlqRqVWjxjXCpbY29+GrdP6zgSUV0Udg17h/uXr+6e/Pr2zc/vnvz0w+/vH/3jKq7vWOqyl4JNGFHzSz1YPPlYOMVC5alaPSU37qyrAZdJSBSWu5+f/3qBV2odJnYZoeoktw5sKq8YBzLlhRP0qzZ...
null
686
Restaurant
Martha is interviewing at Subway. One of the rounds of the interview requires her to cut a bread of size $l \times b$ into smaller identical pieces such that each piece is a square having maximum possible side length with no left over piece of bread.
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int restaurant(int l, int b)" ], "script_name": "Solution", "solution": "\nimport java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\...
{ "solution": "\nimport java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n public static void ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) throws Exception {\n \t\n \tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \tint T = Integer.parseInt(br.readLine());\n \tStringBuilder sb = new Strin...
{ "class_name": null, "func_sign": [ "restaurant(l, b)" ], "solution": "\ndef maximum_squares(l, b):\n if(l > b):\n x = b\n else:\n x = l\n \n GCF = 0 \n for i in range(1, x+1):\n if(l%i == 0 and b%i == 0):\n GCF = i\n \n print(int((l*b)/(G...
eJydnU+uJUlPxRmwkFSPEcr4H8FKkCjEAL4BkwaJDwkJIbEI2B8ztsE5P8d7dTPvzULQaqmr37s3M8J22MfHdtS//+l//vc//Qn//OV/6Q9/9a+//f3v//jPf/ztL47f0o/fax7HaPrDb392/PaHf/nHP/ztH//wd3/zD//8x/2Rks8+xm//9mfHy/fyj99TOmY9f/w+az9mLo/fX9mf6qvnNm9PaT9+L6e+Pbr+MOaxmn6S1jryGD9+b/M8atUfUu9Hmc9vGLX6Af1cS29qLXk1ua3c/eLSxv29WT9PeR5z6Xu11iP3qS+OfvSqr6ax...
null
1,162
Diwali Lights
On the eve of [Diwali](https://en.wikipedia.org/wiki/Diwali), Hari is decorating his house with a serial light bulb set. The serial light bulb set has N bulbs placed sequentially on a string which is programmed to change patterns every second. If at least one bulb in the set is on at any given instant of time, how many...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static long lights(int n)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n ...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int T = s.nextInt();\n int M = 100000; // 17 bits\n ...
{ "solution": "import java.math.*;\nimport java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n\n BigInteger s = new BigInteger(\"2\"), m = new BigInteger(\"100000\"), one = new BigInteger(\"1\");\n int...
{ "class_name": null, "func_sign": [ "lights(n)" ], "solution": "t = int(input())\nfor i in range(t):\n n = int(input())\n res = (2**n - 1)%100000\n print (res)", "template": "#\n# Complete the 'lights' function below.\n#\n# The function is expected to return a LONG_INTEGER.\n# The function accep...
eJztvU2OfcuS5QUSA0m9dglt/3ZnJEgcRAOyQedRjSoJCSHRYAhMiznhtn7L9ol7M29Wg2qkKuMpXsT/Rpx9zt7u5vaxbJnZ//Xf/Pf/7//9X/9X/8P/8bf/9e///j/+h7/9d//wtznG5+/t8/e1Pn8/vc3P3/vn7+Xz9zrvzzPP/cV9QW33W6/PfWkp91fzWfcX/mcZuui+Saml3qvqnvmb2ev9d5v32/1L2c++/yhDb7njz2tzZY8/zxWf0J64hVb0Hn2duI94l7LiNb3cO633X+tZcWGJ+1zn/nPMER8z48J1f1t3L/FGcUst3q49...
null
2,536
Sherlock and Divisors
Watson gives an integer $N$ to Sherlock and asks him: What is the number of divisors of $N$ that are divisible by `2`?. **Input Format** First line contains $T$, the number of testcases. This is followed by $T$ lines each containing an integer $N$. **Output Format** For each testcase, print the required an...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int divisors(int n)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchExcep...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Solution {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n\t\n\tstatic void solve() throws Exception {\n\t\tint t = nextInt();\n\t\tfor (int tt = 0; tt < t; ++tt) {\n\t\t\tint n = ...
{ "class_name": null, "func_sign": [ "divisors(n)" ], "solution": "even = lambda x: x & 1 == 0\n\ndef f(x):\n div = 1\n ret = 0\n while div * div < x:\n if x % div == 0:\n if even(div):\n ret += 1\n if even(x // div):\n ret += 1\n di...
eJyNWkuuLTkRZMBCWnfcQnY6nbZZCRIPMYAeMHn0oFtCQi2xCNgIM3ZHRLjKdp1771MfndatruPyNzIiMuv967f/+d/bb/T5w39x8cd/vv3t648///T2++/eLL58jZGHty9fx/zkwcv05WtO+LHnYV++FjRoLUdG65ZT7+H4PXDPMhpZ2493PF6tlZbuW7nUL1/R3tJouaK3kT28NzyYa71b9c4muYya8TQHbqWWXnFZSu2l4xYuu0d0q+N+rA1cekevHd3XsMSZWXv7/ru3H/7x4w9/+emHv/757z//dK0Xk+LK0BzfXPR/3ANzXSYN...
null
2,475
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_ sep...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(int n, int m)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchE...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Solution {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = ...
{ "solution": "#include <iostream>\nusing namespace std;\nlong long int n,m;\nlong long int see(){\n unsigned long long re=1,i=0;\n while(i++<n)\n re*=m--;\n for(i=n;i>1;i--)\n re /=i;\n return re%1000000007;\n}\nmain(){\n int t;\n cin>>t;\n while(t--){\n cin >> n >> m;\n ...
{ "class_name": null, "func_sign": [ "solve(n, m)" ], "solution": "MOD = 1000000007\n\nt = int(input())\n\ndef f(c0, c1):\n\tc1 -= 1\n\tres = 1\n\tfor i in range(c0 + 1, c0 + c1 + 1):\n\t\tres = res * i // (i - c0)\n\treturn res % MOD\n\nfor _ in range(t):\n\tc0, c1 = map(int, input().split())\n\tprint(f(c0...
eJx9mk3uZEcRxFlwkNJssVBV1jcnQcKIBXjBZmBhS0jIEoeAw7HjKPwi8rUw/5m2LXt6ut+rl5UfEZFZ7x+//Nd/fvUL//Pbf/Phd3//9OfPf/3h+0+/KZ9atG8/993L5I/eSp/8fcxeeu98WLWM8e3nxQW3c8m+rdwa336OwtezR1mdG+49Ze3FDe0U7tttlbM2P6xT7uH6sW/pfLHG4sqtZ97S2uXaE2WPyk/L97ZZvXbjSXdpbWzhGdFm6Zfr2uhlLH6JNUs0Fl91l9WOrdKlHfsj+Hs/o9jsurTBNrmhL32PWTxrxihzaMcYU3d+...
null
2,581
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...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<String> solve(List<Integer> arr, List<List<Integer>> queries)" ], "script_name": "Solution", "solution": "import java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Solution {\n\n public static void ma...
{ "solution": "import java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Solution {\n\n public static void main(String[] args) throws IOException {\n ArrayList<String> result = new ArrayList<String>();\n int ar[] = new int[100001];\n\n Scanner sc = new...
{ "solution": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport ja...
{ "class_name": null, "func_sign": [ "solve(arr, queries)" ], "solution": "n = int(input())\na = list(map(int, input().split()))\nq = int(input())\n\ndef solve(x, y):\n if a[x] % 2 == 1:\n return \"Odd\"\n if a[x] == 0:\n return \"Even\"\n if y > x and a[x + 1] == 0:\n return \...
eJy8vbuudUuyrYWBcHiJVJnoGL3nPfGxcZEoCYO9DZziGPsgJITEo5MRLb7MsYpT9c/xr31Qqdaaa84xes9L3DKiRcv/57/+n/67//a/+a/+5//rL//b3/7jf/q3v/z36S/zr397Utv/K6mmlXrKf/3bW/76t5z2X4b9o6Rh/2j2u26/8/+s9p/7c93+87XP9fPX1/7wl/+Q/vKv/+d//Nf/9d/+9V/+l//9P/1bvO9//Jd/+evf/of/41//9te/+Y/3H7/6pX60f/7l//4P6WMKeyg1vXvo7x7TY+Py31Qbps8kx3/6gP2n1353/3qn...
null
1,428
Special Multiple
You are given an integer _N_. Can you find the least positive integer _X_ made up of only 9's and 0's, such that, X is a multiple of _N_? **Update** _X_ is made up of one or more occurences of 9 and zero or more occurences of 0. **Input Format** The first line contains an integer T which denotes the number of t...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String solve(int n)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimpor...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Queue;\n\npublic class Solution {\n static InputStream is;\n...
{ "solution": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.LinkedList;\nimport java.util.Collection;\nimport java.util.List;\nimport java.io.IOException;\nimport ja...
{ "class_name": null, "func_sign": [ "solve(n)" ], "solution": "__author__ = 'bozo'\nimport sys\n\nif __name__ == '__main__':\n T = int(sys.stdin.readline())\n\n for i in range(0, T):\n n = int(sys.stdin.readline())\n k = 1\n while int(str(bin(k))[2:].replace(\"1\", \"9\")) % n !=...
eJztWk3OLEcRZMFBrLe2UP11TxeHYI3Eh1iAF2weXhgJCSFxCDgGOw5IR1RVZmTN8FlesGJsv+f56equysyIjMycv//8n//+1c/4z6//db/4zV+//PHr93/+4csvv/lytI+v9XF+fL3/ayXhr3r/lcvH13zgVb3uV1e/Xz3wKt2X5Hq/Lf1+Vcq9/Lovy/1ecN5vWrvwMZbX+2257rcVb3F5zfzo/qufuGvBs+8LWs9zF+1xX/Dg53iFbVQ8shz3I6/7AlyU0/1XPbGn+6uOG5T7TX4c918n/rp3VCpePO5n4aENDywnbscT49GFl318...
null
1,427
Is Fibo
You are given an integer, $N$. Write a program to determine if $N$ is an element of the _Fibonacci sequence_. The first few elements of the Fibonacci sequence are $0,1,1,2,3,5,8,13, \cdots$. A Fibonacci sequence is one where every element is a sum of the previous two elements in the sequence. The first two elements ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String isFibo(long n)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchExc...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static HashSet<Long> fibs = new HashSet();\n public static void main(String[] args) {\n long max = 10000000000l;\n long a = 1, b = 1, c;\n ...
{ "solution": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\n\npublic class Solution {\n\tpublic static long longValueOf( String str )\n\t{\n\t long ival = 0;\n\t \n\t for(int i = 0; i < str.length(); ++i) {\n\t \tival *= 10;\n\t \tival += str.charAt(i...
{ "class_name": null, "func_sign": [ "isFibo(n)" ], "solution": "#!/usr/env/bin python\n\nimport sys\n\n\nif __name__ == '__main__':\n T = int(sys.stdin.readline())\n \n fibonacci = [1, 1]\n while fibonacci [-1] <= 10**10:\n fibonacci.append(fibonacci[-1] + fibonacci[-2])\n \n for _...
eJzsfcuuJElynRba6g+0aPR6Fv5+8AMIcENAOwFKgADJXnDTMwB7AAIEAX267Bxzd7PIapLTVfmqpiQM+9a9mREe7vY4ZnbM4v/+9//9v/7n//hv/+dff/ynn//0519+/Ksffqzh9nOKfeTQbz/30WerTX7T+owlTflx1BxzL/LH3EqoAx8vvXT5QJKfR6vyxRhzmSHHLlers4waq/xNfpaLpLm+MlJOfX99phBxzZ5rTfsDoTe5QO5YSoojN7l/rFOuNXJJecb9wcjPzNRGrnL52HKKc+JjowV8PhZZcZHf5Bm6PIBcsIYkf2h55jLk...
null
1,255
K Candy Store
Jim enters a candy shop which has N different types of candies, each candy is of the same price. Jim has enough money to buy K candies. In how many different ways can he purchase K candies if there are infinite candies of each kind? **Input Format** The first line contains an integer T, the number of tests. This ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(int n, int k)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */...
{ "solution": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n//package Combinatorics;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStre...
{ "class_name": null, "func_sign": [ "solve(n, k)" ], "solution": "def nCr(n,r):\n if(n-r<r): return nCr(n,n-r)\n rt = 1\n for i in range(1,r+1):\n rt = rt * (n-i+1) // i\n return rt\n\nt = int(input())\n\nfor i in range(t):\n k = int(input())\n n = int(input())\n print(nCr(n+k-1...
eJyVWsuuZEkNZMGHtK5YjlDa6XzxJUg0YgG9YHOZxYyEhJD4CJDY8atEhJ11r/p2NWK6u1R1Tj6cfoTDzvnHL//1n1/9Qv/99t/48ru/vfz59ceff3r5zaeX8M+vMfrn1zHm59fl6/Pr8fH5dc/At2j41jFkGl5E49uJZ93wbDXMiLXrxQh863y7NdgaV3aufDgYi7pho3m0Hn/yH+dPbmun8SeGDj7qWNzi/tzbsLhj5o7gGtoa8yeFkDhzNEp3eAAsdDSBH5vDNk+nWTwcZxo34Ow58Sscs8fiOtjOKadh8uidy3fO4+EXD9Uwwvhs...
null
3,272
Bus Station
There are $n$ **groups of friends**, and each group is numbered from 1 to $n$. The $i$<sup>th</sup> group contains $a_i$ people. They live near a bus stop, and only a single bus operates on this route. An empty bus arrives at the bus stop and all the groups want to travel by the bus. However, **group of friends** ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static List<Integer> solve(List<Integer> a)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.uti...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.InputMismatchException;\nimport java.util.List;\n\npublic class Solution {\...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Solution {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n\t\n\tstatic void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tint sum = 0;\n\t\tfor...
{ "class_name": null, "func_sign": [ "solve(a)" ], "solution": "from sys import stdin as cin,stdout as cout\ndef factors(n):\n return set(x for tup in ([i, n//i] \n for i in range(1, int(n**0.5)+1) if n % i == 0) for x in tup)\nn = int(cin.readline())\na = list(map(int,input().split()))\nm...
eJx8nUuudUuSlGkwBAZwdNvViPeDkSCREg2oBp2kGlkSUgmJ8TEq4vtsnSyUpSSlvLr3/8/Zez0iPNzNzcz/97//T//nX/7Dv/vP//LHf//zP/3zX/74jz9/1D/9eZdb/vTnP/7h549//J//9I//9S//+N/+y//45798f89f/vG//uHn//mV+ac/1/e/nzvb+Zmt9p++6/ypdfa/+zGt7Pa3n9Pe57T3i/vM/8/vlb/9tfou9t7yvr+Wn1Fu/2lnl5/b+/uoMsrPub39jLrHz1xr/exZ6t/9/FVGa3/zBbu/KzvlzvdJ+33NvT9rlf1z...
null
2,372
Possible Path
Adam is standing at point $(a, b)$ in an infinite 2D grid. He wants to know if he can reach point $(x, y)$ or not. The only operation he can do is to move to point $(a + b, b), (a, a + b), (a - b, b), \text{or} (a, b - a)$ from some point $(a, b)$. It is given that he can move to any point on this 2D grid, i.e., the po...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String solve(long a, long b, long x, long y)" ], "script_name": "Solution", "solution": "\n import java.io.BufferedReader;\n import java.io.IOException;\n import java.io.InputStreamReader;\n import java.math.BigInteger;\n import java.u...
{ "solution": "\n import java.io.BufferedReader;\n import java.io.IOException;\n import java.io.InputStreamReader;\n import java.math.BigInteger;\n import java.util.*;\n import java.util.regex.Pattern;\n\n public class Solution {\n public static void main(String[] args) throws IOException ...
{ "solution": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.List;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nim...
{ "class_name": null, "func_sign": [ "solve(a, b, x, y)" ], "solution": "t = int(input())\n\ndef gcd (a, b):\n if b == 0:\n return a\n return gcd (b, a % b)\n\nfor i in range (t):\n a, b, x, y = map (int, input().split())\n \n if gcd (a, b) == gcd (x, y):\n print (\"YES\")\n ...
eJydlz+PnEUMxinoKeioRldHaMb2+A89LRQ0IA5RwBU0S4pEQkKR+BDwffn5vYS7XHY3Ibu5zbtzM2P78ePHvr8+/eeLzz45Xt9/zsOPf978dnr+8sXNV+NGbk9bY82Ve6xdYh47ZeyaLrOCJ+F5yY7bk0WpLRMbUuV721LO5Nq7snSIzDU9Zt6ebp6Nm7s/nt/98uLu159/f/nitbEfvv7u9sTHzatn45EPdXta6V4Vy8YSzxk6uRsfZkyRNTxlS5TdnlyxNS0HxnBwTh/mtWVZ5DDc0s13Lpy5xTgb3FjCeY0a2yv3dmFtbnHb5YQl...
null
44,457
Constructing a Number
Manipulating numbers is at the core of a programmer's job. To test how well you know their properties, you are asked to solve the following problem. You are given $n$ non-negative integers $a_1$, $a_2$, ..., $a_n$. You want to know whether it's possible to construct a new integer using all the digits of these numbers ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String canConstruct(List<Integer> a)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.I...
{ "solution": "DNE", "template": "class Result {\n\n /*\n * Complete the 'canConstruct' function below.\n *\n * The function is expected to return a STRING.\n * The function accepts INTEGER_ARRAY a as parameter.\n */\n\n public static String canConstruct(List<Integer> a) {\n // Return \...
{ "solution": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Main {\n static MyScanner sc;\n private static PrintWriter out;\n static long M2 = 1_000_000_000L + 7;\n\n public static void main(String[] s) throws Exception {\n StringBuilder stringBuilder = new StringBuilder();\...
{ "class_name": null, "func_sign": [ "canConstruct(a)" ], "solution": "#!/bin/python3\n\nimport sys\n\ndef canConstruct(a):\n return 'Yes' if not sum(a) % 3 else 'No'\n\nif __name__ == \"__main__\":\n t = int(input().strip())\n for a0 in range(t):\n n = int(input().strip())\n a = list...
eJzNm8GOJLtxRb3whyRmLRhkkEEyrH/wWobH8MJ+C29GAvwEGBAE6Au8kv7X57J61EV2sqfbhmTPQz9UV2dlkoyIG/dGRP3hb//0p1/+zfz3q//ixT/97su/f/vNb3/+8vfXl/z1W/Wv3/Llaf6rfuX0/d/1+va4fdvz/dv1/u1++3ZL92+X+7fb/dtx+3a3+7fvd9nvdznudznudzmed/nlF9eXn/7zNz/9688//du//Pq3P7+c+j/+9B9fv335/S+uJ0tghYo1vHWP3NZD6SN3aymzPv7rpdXcdMpea+dl5+KaU1itTQvxNDjVtJzU...
null
6,714
Identify Smith Numbers
A _Smith number_ is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding $1$). The first few such numbers are $4$, $22$, $27$, $58$, $85$, $94$, and $121$. **Example:** $378 = 2 \times 3 \times 3 \times 3 \times 7$ So, it...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int solve(int n)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n in = new InputReader(System.in);\n out = new PrintWriter(System.out, true);\n \n long N =...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n in = new InputReader(System.in);\n out = new PrintWriter(System.out, true);\n \n long N =...
{ "class_name": null, "func_sign": [ "solve(n)" ], "solution": "import math\ndef findsum (a):\n r=0\n for g in range (len(a)):\n r+=int(a[g])\n return r\nk=int(input(\"\"))\nn=k\nans=findsum(str(n))\nfor y in range (2, int(math.sqrt(k)+1)):\n while (k%y==0):\n k/=y\n ans-=findsum(str...
eJyVksEKwjAMhgV9kNHzkKVJ28QnEVQ86A5e5g4bDETwIRRvPqtDFKSjI8sp0C/tn//vbfF4zWefWj/7ZnMxp6puG7PKDNO2Mnlmyq4uD0153J/b5ntUmGue/aGOkyhEaAA9SuQI1SKEfCCnxpkJQb+ieBCb1h7j0IsHdohWP2IF2XkaMXOwg0OxVKDoH1GTaeFxTmkTY9JOuFQwhJCOM+a993oZQIEYPaVHBr4Vv5oQjloQjPysnt3dl29oghmk
null
27,146
Twins
Lia is fascinated by anything she considers to be a *twin*. She calls a pairs of positive integers, $i$ and $j$, twins if: * They are both prime. A [prime](https://en.wikipedia.org/wiki/Prime_number) number is an integer greater than $1$ that has no positive divisors other than $1$ and itself. * Their absolute differ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(int n, int m)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Solution {\n\n\tpublic static void main(String[] args) throws NumberFor...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class C {\n InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n \n void solve(...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class C {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t...
{ "class_name": null, "func_sign": [ "solve(n, m)" ], "solution": "limit=1000000\nbeg,end=map(int,input().strip().split(' '))\nis_prime=[False]*(limit+1)\nprime=[]\nfor x in range(1,int(limit**0.5)+1):\n for y in range(1,int(limit**0.5)+1):\n n = 4*x**2 + y**2\n\n if n<=limit and (n%12==1 o...
eJyNk8tKQ0EMhl30QcJZF8llkkl8koJKF9qFm9pFC4IIPoS+rzmloKTMwayy+L/J5c98rr63q5tzbDaZ3L9PL/vD6TjdwcQqRMbqkJlahPPDflrDtHs77J6Ou+ft6+l40abOp481/MGNmxh3ZcisibjYEOcrOuEmrq6QWe9MpuPi5FqLUyTeW4fMlFiRxsVFCt04OqMb5AQkgjhmu1ZYqTUlIVDSnEv6EBasbUdvzOFkkFkPRFyYulNdmoahijUwZPHwMZyu1r7DbbZZOoR3UfcmC7hgNcyc81VjYAsMllioHlEnJxgbVEsRjA/xqi0Y...
null
6,129
Fibonacci Finding (easy)
You're given three numbers: $A$, $B$, and $N$, and all you have to do is to find the number $F_N$ where $$F_0=A \\\ F_1=B \\\ F_i=F_{i-1}+F_{i-2} ~for ~i \geq 2$$ As the number can be very large, output it modulo $10^9+7$. Consider the following link: http://en.wikipedia.org/wiki/Fibonacci_number#Matrix_form
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int solve(int a, int b, int n)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMi...
{ "solution": "import java.io.*;\n\npublic class HR_fibonacci_finding_easy {\n\n final static long MOD = 1000000007;\n\n static long[][] mul(long[][] a, long[][] b) {\n long[][] c = new long[a.length][a.length];\n for (int i = 0; i < a.length; ++i) {\n for (int j = 0; j < a.length; ++j)...
{ "solution": "import java.io.*;\n\npublic class HR_fibonacci_finding_easy {\n\n final static long MOD = 1000000007;\n\n static long[][] mul(long[][] a, long[][] b) {\n long[][] c = new long[a.length][a.length];\n for (int i = 0; i < a.length; ++i) {\n for (int j = 0; j < a.length; ++j)...
{ "class_name": null, "func_sign": [ "solve(a, b, n)" ], "solution": "\nmod = 1000000007\n\ndef mul(A, B):\n\tres = [[0, 0], [0, 0]]\n\tfor i in range(2):\n\t\tfor j in range(2):\n\t\t\tfor h in range(2):\n\t\t\t\tres[i][j] = res[i][j] + A[i][h] * B[h][j]\n\t\t\t\tres[i][j] %= mod\n\treturn res\n\t\n\t\nt =...
eJyVncuOZclVhhnwIFs1tlDcL8yZ8QBINGIAHnhSeGBLlixLPARIPC7ft05V484T2VS0JSrJk2fviFi3f13jP//2v//xf/4m/vunf+CHf/7zl999/f0f//Dl758vuf30tfSa8yh9PbPMnVrPzyitjjJ7+elrbbmvsVt++F2rq6/+zN5LT2v/9HXkze9mm8/oY6Ra13ha2bOkNX76OnefuY/y9Nx4bM1Pn3X4R/Onr3u2UvbK4xltrbJm3U/fI/U6WNTiKfxlms9eo9c+6nwWf1NTGpk1j1VYMY/Oa6XBf+nZNZdaZi4uK7vG2Z/FsmZv...
null
3,081
Little Panda Power
**Little Panda** has a thing for powers and modulus and he likes challenges. His friend **Lucy**, however, is impractical and challenges **Panda** to find both positive and negative powers of a number modulo a particular number. We all know that $A^{-1}\bmod X$ refers to the modular inverse of $A$ modulo $X$ (see [Wiki...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(int a, int b, int x)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMi...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class LAP {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = \"\";...
{ "solution": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class Solution {\n\n int gcd(int a,int b,long[] x){\n\n if(a==0){\n x[0]=0;\n x[1]=1;\n return b;\n }\n long[] x1=new long[2];\n int d=gcd(b%a,a,x1);\n ...
{ "class_name": null, "func_sign": [ "solve(a, b, x)" ], "solution": "t = int(input())\n\ndef extended_gcd(aa, bb):\n lastremainder, remainder = abs(aa), abs(bb)\n x, lastx, y, lasty = 0, 1, 1, 0\n while remainder:\n lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, rem...
eJyVnE2ubctRhGlAj0EsvTYbrfqvYgbMAImHaIAbdB5u2BISssQgYL7EF5l77fOufUA217737LN+qvInMjKyNv/1l//z13//F/7PP/yV/vGP//nTv/3y29//7qe/u346P/+y165lXWWWeu256v3zL2WXdber3OecfZ1T99an7bRzl6ucvua4+tJH/S51j+tVxmn3uWpvdW098u6jl+s1xmz6u9z6hT7urbS9rtc+c4196XlrjZ9/qafWzvt18zW7FrP0iDJXadfeu9d2jTbuu+vSdbTUvkfVCurd1q1F/PQ310+/+Y/f/uZffvebf/3n...
null
2,561
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...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String solve(long i)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchExce...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Solution {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = ...
{ "solution": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n/**\n *\n * @...
{ "class_name": null, "func_sign": [ "solve(i)" ], "solution": "from math import ceil\nT = int(input())\nfor _ in range(T):\n x = int(input())\n n = int(ceil((1 + x) ** 0.5 - 1))\n if n % 2 == 1:\n print('odd')\n else:\n print('even')", "template": "#\n# Complete the 'solve' func...
eJztmctuJkkRhVnwICOvRyjyEhkRPAkSjVgwvWDjmcWAkBASDwFPxI6n4jtRZgDb7f5/i2GBuluyyuWqzLicOHEi688//evfH37S/37xNy5++ceH3z5+97vvH37+1cP48Oj7w+PD1189fPzDdx9/8/3Hb3797e++f/rrt9988/Cnr7/6z+frzufnPY+z9sh1VvnRddQYnnaSZcysaq5aHx43N3N7BtanrX1W6MU5fNeayRO1TtRa6R8e1445RzlrpI2x061Y7pw8gxW1YcQM7rJczYq5XA/7Yd/jY2hlC/PN/bd8+fDYPz7+/uPjy8tX...
null
2,324
Akhil and GF
After dating for a long time, Akhil is finally going to propose to his girlfriend. She is very strong in mathematics, and will accept his proposal, if and only if Akhil solves a problem given by her. The problem is given below. Help Akhil solve it. Akhil is given two numbers N and M, and he has to tell her the remaind...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(long n, int m)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatch...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Solution {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = ...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Solution {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n\t\n\tstatic void solve() throws Exception {\n\t\tint t = nextInt();\n\t\tfor (int tt = 0; tt < t; ++tt) {\n\t\t\tlong n =...
{ "class_name": null, "func_sign": [ "solve(n, m)" ], "solution": "T = int(input())\nfor tt in range(T):\n N,M = [int(x) for x in input().split()]\n ans = pow(10,N,9*M)\n ans = (ans - 1) // 9\n print(ans)", "template": "#\n# Complete the 'solve' function below.\n#\n# The function is expected t...
eJylk01KA0EQhV3oPZpZB6n/H08iqLjQLNzEIAkoEvAQel/LKIhOd0CsVUNPffPq1euX47enk6N9nT/U4eJ5ulutt5vprE14uZKwoExAR5FEbwbuYiZ8uZoWbVo+rpc3m+Xt9f1289UlqpkICdNu0X7SKJEcLDUDmQCbAKgLqQ1pXKQw1pzTxIHZXVON2NVKGys5eg5pVEOIEM5hjFLCmFggUxybqUUQwxjGBohaAjo0NiX9UC7ApNE4EJxEY0hzdQ3GzpxoIoagkl7GCjZ1IKCycAwLRCSijjIA8LpkUHDBbKgJDs7jOZGNamHOHZrU...
null
3,334
Little Ashish's Huge Donation
Little Ashish is doing internship at multiple places. Instead of giving parties to his friends he decided to donate candies to children. He likes solving puzzles and playing games. Hence he plays a small game. Suppose there are $N$ children. The rules of the game are: 1. The $i^{th}$ child gets $i^{2}$ candies ($1 \...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(long x)" ], "script_name": "Solution", "solution": "import java.util.*;\nclass Solution {\n public static int getpos(long n,long[] arr){\n int k=Arrays.binarySearch(arr,n);\n if(k<0) return -k-2;\n else return k;\n ...
{ "solution": "import java.util.*;\nclass Solution {\n public static int getpos(long n,long[] arr){\n int k=Arrays.binarySearch(arr,n);\n if(k<0) return -k-2;\n else return k;\n }\n public static void main(String[] args) {\n Scanner in=new Scanner(System.in);\n int big=3200...
{ "solution": "\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\nimport static java.util.Arrays.*;\n\npublic class Solution {\n\tprivate static final int mod = (int)1e9+7;\n\n\tfinal Random random = new Random(0);\n\tfinal IOFast io = new IOFast();\n\n\t/// MAIN CODE\n\tpublic void run() throws IOExcep...
{ "class_name": null, "func_sign": [ "solve(x)" ], "solution": "t = int(input())\n\nfor _ in range(t):\n n = int(input())\n l = 0\n r = n\n while (r - l > 1):\n m = (l + r) // 2\n if (m * (m + 1) * (2 * m + 1) // 6 > n):\n r = m\n else:\n l = m\n if ...
eJyVms2ursdRhRlwIZHHUdT/P1wJEkYMwAMmJoNEQkJIXATcJTNugOdZ/Vkx2zkWOXG8vb/zvf12V61ataqq/+Ov/+t/fvdX+fO3/81//N2/fffPP/7+j3/47m9+891u3/94Vun73DHPLqNdPum11dXKmruXUfvlO2Xe1etts+76/Y+1nlnOPWOvWufikd1aHaf1Mfdoy0X2Kay5ey+HfxYP8ZJ1WXK2PeocrHrWGYeFym5jnO9/nKWVORr/O2OO/f2Pt97a7jp19bHb4St93Dv7YSfs7frqPmq58/BP6b7y+x9XP3P6tlFqm4v939NP...
null
2,301
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. ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static long solve(long n)" ], "script_name": "Solution", "solution": "import java.io.*;\n\npublic class Solution {\n\n\tpublic Solution () {\n\t\tlong N = sc.nextLong();\n\n\t\tlong p = 1, q = 5 * N, m;\n\t\twhile (q - p > 1) {\n\t\t\tm = (p+q)/2;\n\t\t\tif...
{ "solution": "import java.io.*;\n\npublic class Solution {\n\n public Solution () {\n long N = sc.nextLong();\n\n long p = 1, q = 5 * N, m;\n while (q - p > 1) {\n m = (p+q)/2;\n if (eval(m, N))\n q = m;\n else\n p = m;\n }...
{ "solution": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport ja...
{ "class_name": null, "func_sign": [ "solve(n)" ], "solution": "from sys import stdin\nfrom math import log, ceil\nT = int(stdin.readline())\ndef invf(n):\n if n == 0:\n return 0\n return sum((n//5**i) for i in range(1, int((log(n,5))) +1))\ndef bsearch(inv, y):\n lb = 1\n ub = y*5\n w...
eJylnMuupMtRhRnwINYZWyjvFx6CMRIHMQAPmBw8sCUkhMRDwPvyfSurG7ubNkg+wGZ37ar88xKxYsWKyPqPv/yv/jd/kf/+9tf88nf/9tM///Lb3//up7/+1U9z/PxLPb3eVm69i9/mz7/Mvu+pt8+++izj/PzLWn3tOu/Z89xe9s+/9HHOuqOt3Xnt3J9/abe2XdblXbW3Unml9TPv6LfOwV/Wz7/sfW855/Qz1pm9ME4dfKa3Psq9Y/OpexcfmncuZnQar6x+e+9jltJHXYtn1TXGqmWOy4B18J492ihnlbnP4PmOU/Ypd/CWXc6d...
null
4,731
Number of zero-xor subsets
You are given an integer $N$. Consider set $S = \{0,\ 1,\ldots ,\ 2 ^ N - 1\} $. How many subsets $A\subset S$ with $ \bigoplus_{x \in A}x = 0$ ($ \oplus $ denotes xor operation) are there? Print your answer modulo $(10^9 + 7)$. Note that the xorsum of an empty set is zero! **Input Format** The first line con...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(long n)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchExcepti...
{ "solution": "import java.io.*;\n\npublic class HR_number_of_subsets {\n\n final static long MOD = 1000000007;\n\n static long modPow(long x, long pow, long mod) {\n long r = 1;\n while (pow > 0) {\n if (pow % 2 == 1) {\n r = r * x % mod;\n }\n pow ...
{ "solution": "import java.io.*;\n\npublic class HR_number_of_subsets {\n\n final static long MOD = 1000000007;\n\n static long modPow(long x, long pow, long mod) {\n long r = 1;\n while (pow > 0) {\n if (pow % 2 == 1) {\n r = r * x % mod;\n }\n pow ...
{ "class_name": null, "func_sign": [ "solve(n)" ], "solution": "import sys, random\nfrom math import sqrt\n\ndef solve():\n stdin = sys.stdin\n\n MOD = 10 ** 9 + 7\n T = int(stdin.readline())\n\n for _ in range(T):\n N = int(stdin.readline())\n ex = (pow(2, N, MOD - 1) - N) % (MOD - 1)\n print(...
eJx0vUuubVuSXKcCG5KIMgvzP9dUSwTwQSqQWVAlxEISECAIUCvVHvoYtm+CyGQUMuPde8/Ze6358Y+5ufn/9x/+t//9//8P/8t/+n/+9n/+/b/+t3/52//6T3/rf/39/vX3v/3Hf/rbP//f//Wf//O//PN/+T/+r//2L79/fPe76/a5/vb//sd/+je/9PX99fVWv/eM/vV/+CF99nXPHN+/+ZD9199Pe3e2v/4+59x8wpj3zlkfPu/2n9cb//iD56nvXr3V83/97tf6HvWfc+836kP7Pnvs8dXfnbu+7+w2/+171I+tve9p/utff9/9...
null
30,186
Breaking Sticks
You recently received a bag of chocolate sticks for Halloween. To prevent you from compulsively eating all the chocolate sticks in one go, your dietician devises the following fun game. In each move, you choose one of the sticks from your bag. Then, you either eat it, or break it into some number of equally-sized par...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static long longestSequence(List<Long> a)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Inp...
{ "solution": "DNE", "template": "class Result {\n\n /*\n * Complete the 'longestSequence' function below.\n *\n * The function is expected to return a LONG_INTEGER.\n * The function accepts LONG_INTEGER_ARRAY a as parameter.\n */\n\n public static long longestSequence(List<Long> a) {\n ...
{ "solution": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\...
{ "class_name": null, "func_sign": [ "longestSequence(a)" ], "solution": "#!/bin/python3\n\nimport os\n\ndef solve(x):\n os.system(\"factor {} > factors.txt\".format(x))\n with open(\"factors.txt\") as f:\n factors = [int(x) for x in f.read().split()[1:]]\n prod = 1\n ans = x\n ...
eJztms2uZTcRRhnwIFbPkCJku/zLkyDRiAFkwKTJIJEioUg8BLwiM96BtXxzfG/f9G0yQUioT7o7x2fvbZfr56uvyvtvv/zHv371i/P57T/58ru/vvvzh2+++/bdb9K7Fe8/9D7SrDPt2tMaLe2W04qaRpmpZX4fOUWpaeaR2lznt95WCn5f3lNyar2m3jf39FRLpLF9nu/84ZHB9GVnvqfZGcZIpT19X6ukqDWt1njKFXoarOSKo2dW30iW6vY2/i4uLwT2VuTl7sJkPDBGT63m1CcPrlQRopTUI5gquJeNTATNKxXGc+Sn3xC6cPeY...
null
6,061
Cheese and Random Toppings
*Waiter:* Good day, sir! What would you like to order? *Lucas:* One Cheese & Random Toppings (CRT) pizza for me, please. *Waiter:* Very good, sir. There are $N$ toppings to choose from, but you can choose only $R$ toppings. *Lucas:* Hmm, let's see... ...Then Lucas started writing down all the ways to choose...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int solve(int n, int r, int m)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMi...
{ "solution": "import java.io.*;\nimport java.math.BigInteger;\n\npublic class HR_cheese_and_random_toppings {\n\n private static long crt(long a1, long mod1, long a2, long mod2) {\n long inv1 = modInv(mod1, mod2);\n long inv2 = modInv(mod2, mod1);\n long mod = mod1 * mod2;\n long c1 = ...
{ "solution": "import java.io.*;\nimport java.math.BigInteger;\n\npublic class HR_cheese_and_random_toppings {\n\n private static long crt(long a1, long mod1, long a2, long mod2) {\n long inv1 = modInv(mod1, mod2);\n long inv2 = modInv(mod2, mod1);\n long mod = mod1 * mod2;\n long c1 = ...
{ "class_name": null, "func_sign": [ "solve(n, r, m)" ], "solution": "import sys, random\nfrom math import sqrt\n\ndef fact_p_count(n, p):\n n //= p\n m = n\n while n >= p:\n n //= p\n m += n\n return m\n\ndef mod_inverse(n, s=0):\n if s == 0:\n s = n - 1\n inv = [0] * (s + 1)\n inv[1] = 1\n...
eJydlEtKA0EQhl3oPYpZi9T74UkEoy40CzfRRQRBBA+h97UiiYJkxE7PYoph6uu/qv7ut+OP5cnR17q47uDyZbpfPT6tp3OYaLHyTK/0QNDQTDJUkP7CUSSL1XQK0/L5cXm7Xt7dPDytt4laFR5q0+sp/OKVq1k0RaXS+h8Cqshmo83ycA/ICJMzBcxSUKQcyMNsiEISgoTELSfZvSBci5SGKOoUTlgByowaWQyiKpQjFA5JSzcB4UQvQSDqIrN8Xo0KIlPuwW0GJxGUYOLCUihAihhDlSlyhZYC9Rut1KC1SZEXDjXa1dlEAqLtpBsb...
null
27,017
Satisfactory Pairs
Given a positive integer, $n$, find and print the number of pairs of positive integers $(a, b)$, where $a < b$, that exist such that the equation $x \cdot a + y \cdot b = n$ (where $x$ and $y$ are positive integers) has at least one solution.
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(int n)" ], "script_name": "Solution", "solution": "import java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n in.close...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class E2 {\n InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n \n void solve...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class E2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\...
{ "class_name": null, "func_sign": [ "solve(n)" ], "solution": "# https://www.hackerrank.com/contests/w26/challenges/pairs-again\nimport datetime\nimport gc\nfrom math import sqrt\n\ndef getMultipliers2(n):\n size = int(sqrt(n))\n result = [[None]*(2*size+1) for i in range(n + 1)]\n for i in range(...
eJx9kk1KBEEMRmcx4DWaWg+Sn0oq8SSCigvthZtxFj0giOAh9L7WiAtJkcqqoeuRfC/53H9f7Xe/dbvrH3fv5eV4Om/lZilEaqr3x3JYyvp2Wp+29fnx9bz9/UZABiUtH4flH4XE4pJSzAqiNUAsUmedOuJDI9XmNYUaNKnjdGjWIIUqEzsP06kZ5o3UOxQQArc8kLAocOxiJi1FjMkhpiHptvMw3ogsIgZ9tFw19/wCEKhcM4WX+eaj1YmeaAYulc+s1GqVSJFfKqUcXAAHSAlrnhaRxBiHPbRGswEFq4NFATiPxUYiEP32hVeZqOsn...
null
781
Largest Non-Coprime Submatrix
Given a matrix you need to find the submatrix with the largest number of elements, where the GCD (Greatest Common Divisor) of its elements is greater than one. A submatrix of the matrix is a sub-section composed of contiguous rows and columns of the original matrix. <br/> **Input** Two numbers n,m in the first line. F...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(List<List<Integer>> matrix)" ], "script_name": "Solution", "solution": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Solution {\n\n\tpub...
{ "solution": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Solution {\n\n public static void main(String [] args ) {\n try{\n String str; \n BufferedReader br = new Buffe...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n public static int gcd(int x,int y){\n while(x!=0 && y!=0){\n int t=y;\n y=x%y;\n x=t;\n }\n return x+y;\n }\n\n public static void main(String[] args) throws IOException{\n /* Ente...
{ "class_name": null, "func_sign": [ "solve(matrix)" ], "solution": "from sys import stderr\n\ndef main():\n print(solve(readcase()))\n\ndef readcase():\n n, m = readints()\n mtx = []\n for _ in range(n):\n mtx.append(readints())\n assert len(mtx[0])==m\n return mtx\n\ndef readi...
eJyMnbuObduSVTHK4itS1y5jvB98CRJHwoAycA4YhYSEkPgWvpTRWp95BFUqhHGv9tk7c605xyMePXr0+J9/92//9f/6u3/17/773/7Tn//lv/7j3/7Nz9/qT/3jz3Xa+uPPv/39z9/+4b/9l3/4D//4D//x3//n//qPvz/xt//x9z//12/MP/6sa/+Mc/vPKn3/9Lr7zxjt/H9/yORrb9vjjz93He/32prlPUit/f259H/5cfo/+6T3OLvc8TPaPj+31fLTztw/t6z36b2s98Cnvi8cd/2cXerP2vN9y53n/Xd7P9l2f7/zHv+n9/2e...
null
1,138
Easy math
Charlie and Johnny play a game. For every integer *X* Charlie gives, Johnny has to find the smallest positive integer *Y*, such that X * Y contains only 4's and 0's and starts with one or more 4's followed by zero or more 0's. (i.e.), 404 is an invalid number but 400 is a valid number. If *a* is the number of 4's and...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(int x)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport j...
{ "solution": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport ...
{ "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class Solution\n{\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 64 * 1024);\n\n final St...
{ "class_name": null, "func_sign": [ "solve(x)" ], "solution": "from math import gcd\nfrom collections import Counter\n\ntestcases = int(input())\n\ndef factorization(n):\n facts = Counter()\n while not n%2:\n facts.update({2:1})\n n //= 2\n tryval = 3\n while tryval**2 <= n:\n ...
eJztncuObkmWlBnwIKUct5DfLzwJEoEYQCExIOlBtdQSaomHgCHvitlnHieLzDolHuDvlmqfiPj/vX27r4stW+ae//Nf/+//9n/+Ff/37/6L/vHv/8cv//XXf/ynv/zyb//0S/36da5d19evv/zDn3758z//45//01/+/J//43//p798f+CMX/7lH/70V1/pX7/2cu75+vWcoy/u1er++fd76/rQGKPoo3P19bvbTf2xLt+u3e0b3dbyUY/qlDrbT2/eyhnvi8tf1NvsfvWvPebvHlN1z9mGP7br+Pp1teOnlNL0w76t6LV223p+b3vo...
null
39
Equations
Find the number of positive integral solutions for the equations $$\frac{1}{x} + \frac{1}{y} = \frac{1}{N!}$$ **Input Format** An integer N  **Output Format** The number of positive integral solutions for the above equation modulo 1000007 **Constraints** $1 \le N \le 10^6$ **Sample Input00** 1 ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(int n)" ], "script_name": "Solution", "solution": "/* Enter your code here. Read input from STDIN. Print output to STDOUT */\nimport java.io.*;\npublic class Solution {\n public static void main(String args[]) {\n String line;\n int ...
{ "solution": "import java.io.*;\npublic class Solution {\n public static void main(String args[]) {\n String line;\n int N=1;\n try {\n BufferedReader is = new BufferedReader(new InputStreamReader(System.in));\n line = is.readLine();\n N = Integer.parseInt(line);\n } catch(Exception e) {\...
{ "solution": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Solution {\n\tpublic static void main(String args[]) throws Exception {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString line = br.readLine();\n\t\tint N = Integer.parseInt(line);...
{ "class_name": null, "func_sign": [ "solve(n)" ], "solution": "primes = []\na = range(2,1000001)\nwhile len(a)>0:\n if a[0]<1000:\n primes.append(a[0])\n a = [i for i in a if i%a[0]!=0]\n else:\n break\nprimes = primes + a\n \nn = int(input())\nm = 1\nfor p in primes:\n b =...
eJx9kk1KBEEMhQU9SFPrQVL5jycRVFxoL9yMs+iBARE8hJ7QnaewGFxImnRWBZWv8uq9fFx9/VxenOv2exzu3trL/nBc2s3U1IDd7/dtN7X5dJiflvn58fW4/F0bGxG09930j+ldjaFkEECCEoOKqCWiFgiREDMTo5Lp3WElDd0pamliTF0zI2obFpBLxGoOMQiXjJMNJdk2VupWMiyMaCsPELlmDHAEmOfASK3WxhLMeU6vbc4/r41KnXV0Oem+sUwYkrvrPeqowbnfsH5eOZhyUISEtecqKoAJYQisPVTXISIhMco3PEJB45VR56oh...
null
12,630
Divisor Exploration 3
You are given $q$ queries where each query is in the form of three integers, $m$, $a$ and $d$, such that: $$n = \prod\limits_{i = 1}^{m} p_i^{a+i} \text{, where } p_i \text{ is the } i^{th} \text{ prime.}$$ Using this value of $n$ along with the given $d$, create a tree $T$ as follows :- + The value $n$ is the ro...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int divisorExploration(int m, int a, int d)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class E2 {\n InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n \n public sta...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution \n{\n public static final long REM=1000000007;\n public static long[] sieve = new long[10000]; \n public static long[] pbase = new long[1001]; \n public stat...
{ "class_name": null, "func_sign": [ "divisorExploration(m, a, d)" ], "solution": "#!/bin/python3\nimport math\nimport os\nimport sys\n\n# Complete the 'divisorExploration' function below.\n# The function is expected to return an INTEGER.\n# The function accepts following parameters:\n# 1. INTEGER m\n# 2....
eJztms2uZbdxhTPwgxA98sAISBZ/8yQB0oYHiQaZtD2QAAOBgDxE/KaeZZLvq31kC1d9ZSHwIECuAN0+5+xNslhctWoVyf/81Z/++9f/kP/985/58C//8enfv/zhu28//VP5NPrnL2NGmXOW3ffnL7fPclaUO+rnLyd6WW2VUX2yaonWyq6LNvvw6ypznM9fgifH11q1t05vh9fm5y+9RVm30YlfZul7l+Uw7dbSV9mT5itWaeP15ZxWordyxuDJpdM9ynLIaBgzbrnrambpdMGbPDizLP7fV8MwnxaNjw371hpldMyam9a79KBXJjGZ...
null
5,505
Superpowers of 2
You will be given two integers $a, b$. You are required to output the result of $2^{(2^a)}$ mod $b$. **Constraints** $1 \le a, b \le 10^6$
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(int a, int b)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchE...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class D {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = \"\";\n...
{ "solution": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class SuperpowersOf2_new {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tint phi(int x) {\n\t\tint ret = x;\n\t\tfor (int i = 2; i * i <= x; i++) {\n\t\t\tif (x % i == 0) {\n\t\t\t\t...
{ "class_name": null, "func_sign": [ "solve(a, b)" ], "solution": "ip = input().split(' ')\na = int(ip[0])\nb = int(ip[1])\nprint(pow(2, 2**a, b));", "template": "#\n# Complete the 'solve' function below.\n#\n# The function is expected to return an INTEGER.\n# The function accepts following parameters:\n#...
eJyVk7tKg0EQhS3yIMNfB5n7xcrOVxBULDSFTUyRQEACPoS+r0tIIfuzIZlqYefbc3bO7vfi92Fxc6zH+7Z4+po+1pvddrqDScXTEsKTI57X0xKm1X6zetuu3l8/d9tTlyEx6XRYwj+U0F0hHZF8SHJRmndkunExpFJqDlEpVM0OFRLSgCz3GKMZor1dSRdMqAg8I+ranPWijIJewCkSMkTJnbBHrcRQQC2UaohWGEk/Xi9TBimiHM+3bSpij0ozrFDNkYxFPZy0V1WT8gAOibNXVbGZYaAhMHOIx7qGAL769MsJblaQ9eJ+Q3AzGecy...
null
2,597
Divisibility of Power
You are given an array $A$ of size $N$. You are asked to answer $Q$ queries. Each query is of the form : $\text{i j x}$ You need to print `Yes` if $x$ divides the value returned from $find(i,j)$ function, otherwise print `No`. find(int i,int j) { if(i>j) return 1; ans = pow(A[i],find(i+1,j)) ...
hackerrank
Medium
{ "class_name": null, "func_sign": [ "static String[] solve(long[] a, int[][] queries)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMi...
null
{ "solution": "import java.lang.*;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Solution {\n public static void main(String[] args) {\n new Solver().run();\n }\n}\n\nclass Solver {\n\n void run() {\n in = new BufferedReader(new InputStreamReader(System.in));\n ...
{ "class_name": null, "func_sign": [ "solve(a, queries)" ], "solution": "import math \n\nn = int(input())\na = list(map(int, input().split()))\n\nnxt = [0] * (n + 1)\nnxt[n] = n\nfor i in range(n - 1, -1, -1):\n if a[i] <= 1:\n nxt[i] = i\n else:\n nxt[i] = nxt[i + 1]\n\nq = int(input())...
eJykvcuurVmSpUWDB1kK0azGvF94CNogtkQDskHHqySypJIQEs/MEzC+YTbX9iwyMiKSUla4+zl7r/X/82KXYcOG/d//7f84/p//7r/5n//Pv/zvf/yn//zPf/nvP3+pd4+fP8bsu41PG7ue/tm1nPFZ5e52P733ecqn9b17++y+J381biufNWqr4zPqXeOz9y7rM0vr9zNXqed+7qz9rs/qfbX6maeV8zmtN/3cXX3U/jlrzd4/bdWrX9N3r3k+t9zBj+jXR/lMPWDdH/7q7s+YZdalJ5xnzs/ap8z2mbuuOj9b/85LrF22vqi3dtpH...
null
1,050
Devu Vs Police
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...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(int n1, int k1, int n2, int k2, int n)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Solution {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = ...
{ "solution": "import java.util.Scanner;\n\n\npublic class Solution {\n\t\n\tstatic Scanner sc;\n\t\n\tstatic int n1, k1, n2, k2, m;\n\t\n\tstatic int[] ps = new int[446];\n\tstatic {\n\t\tps[0] = 2;\n\t\tint plen = 1;\n\t\tfor(int i = 3; i * i <= 10000000; i += 2) {\n\t\t\tint j = 0;\n\t\t\tfor(;j < plen && i % ps[j...
{ "class_name": null, "func_sign": [ "solve(n1, k1, n2, k2, n)" ], "solution": "lim = 3200\nmark = bytearray(lim)\nprimes = [2]\nfor i in range(3,lim,2):\n if mark[i]: continue\n primes.append(i)\n for j in range(3*i,lim,2*i):\n mark[j] = 1\ndef factor(n):\n f = {}\n for p in primes:\n i...
eJyVVM2KE2EQ9CA+R5PzIv3/48Gb7yC44kFz8LLuIQuCCD6Evq81SRaRzATyhcAHM1XdVdU9v17+effqxfG8f4vLhx+7rw+PT4fdG9rJ/YN7matUUXWWeBuT8MhwFHVzRvQMBQub5/3D7o52+++P+8+H/ZdP354Oz0zqE1G7n3f0P/9IyxR4yJYXhs1IucZVB7dhKZNOGp9k180Cji6D+bKAZ9tkjhKYEq1XkzO6x/tOYubG4UOlCQHbCjyDXfKygDaUm0ZQsoXW4lXWwpUjJF0yM8U02hLCmwWykiVjpQC6bcgQshYu9Uiq0Wie6CWW...
null
4,028
A Weird Function
Ma5termind is going through the Euler's book of knowledge when he finds the following function: def function(L,R): sum=0 for i in range(L,R+1): #[L,R] for j in range(1,i+1): #[1,i] cnt=0 if (j)*(j+1) == 2*i : for k in range(1,i+1): #[1,i] ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static long solve(long l, long r)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismat...
{ "solution": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class HR_a_weird_function {\n\n static long[] divs;\n static {\n divs = new long[2000001];\n for (int i = 2; i < divs.length; ++i) {\n if (divs[i] == 0) {\n divs[i] = i;...
{ "solution": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class HR_a_weird_function {\n\n static long[] divs;\n static {\n divs = new long[2000001];\n for (int i = 2; i < divs.length; ++i) {\n if (divs[i] == 0) {\n divs[i] = i;...
{ "class_name": null, "func_sign": [ "solve(l, r)" ], "solution": "import sys, random\nfrom math import sqrt\n\ndef gcd(a, b):\n while 1:\n if b == 0:\n return a\n a %= b\n if a == 0:\n return b\n b %= a\n\ndef function(L,R):\n sum=0\n for i in range(L,R+1): #[L,R]\n for j...
eJylnM2qLUmWnDXQgwQ5boT/h7seQjOBQLfRQKqBJqkeVEODEOghpPeVfWa+7zlk1U0aVFQu23bP3hH+u/58Rfzvf/t//+M//hv/7z/9B334z//zt//++z/9819/+/fPb++P31c5by/PqqXMCR2n1WeJDP11ljbKM8u7RfY8rde9y5rj2au0ukdd7ZQfv585Wp+lrD7rI7LHepf+piu+ta5S37HXaM9b9aO37Lb74YKtzbfq9vq06nmrvv/bPzy//eVf/ukv//Wvf/lv/+V//PNfb1Orrrz2j991M31zjx+/99r2bnW9s5fa9A+tjPmq...
null
11,996
Divisor Exploration
You are given $D$ datasets where each dataset is in the form of two integers, $m$ and $a$, such that: $$n = \prod\limits_{i = 1}^{m} p_i^{a+i} \text{, where } p_i \text{ is the } i^{th} \text{ prime.}$$ For each dataset, find and print the following on a new line: $$\sum\limits_{d|n} \sigma_{0}(d)$$ where $\sigma...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(int m, int a)" ], "script_name": "Solution", "solution": "import java.util.*;\nimport java.io.*;\n// Aditya Chatterjee \npublic class solution_3\n{\n public static long mod = 1000000007;\n\tpublic static void main(String args[])\n\t{\n ...
{ "solution": "import java.util.*;\nimport java.io.*;\n// Aditya Chatterjee \npublic class solution_3\n{\n public static long mod = 1000000007;\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n long num[] = new long[200002];\n num[0] = 1; num[1] = 1; n...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class C {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t...
{ "class_name": null, "func_sign": [ "solve(m, a)" ], "solution": "def gcd_ext(a, b):\n s = 0\n t = 1\n while b:\n q, r = divmod(a, b)\n s, t = t, s - q * t\n a, b = b, r\n return s\n\ndef cache_factorials(n, p):\n factorials = [1]\n for i in range(1, n + 1):\n ...
eJzVfUvONbtSJY0aiHXaCNkOPxkJEj+qRtVt0DlF4yIhlZCKOcAY6DFG1gpn+hHp71T1SiBxbv755bbD8Vixwrl3+P/8t3/7j3/5C/2/v/l3XPzt//7t73//h3/8829/7X6TX7+Li/7X76G4jP9Wh+vf/tL99qd/+oc//Y8//+l//vf/9Y9/fp6NvqeWPB7oMYlIifHX7y2EWEOKv/3zX7ptXPwliAsND7j444it91SDxwOltB6K1GTGwQApBBc4a8ouxPDr99qKi6FA8oY7HndSjC7jiRIxGz6SS3OZ0pXuaq8/zl96CL2Jx8qTF+9j...
null
95
Ants
N ants are in a circular race. The length of the race is 1000 meters and ant number i is initially Vi meters far from starting point (point 0) of the race in clockwise order. All the ants walk with a speed of 0.1 meters per second, some of them walk in clockwise order, some in counter clockwise order. When two ants mee...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(List<Integer> V)" ], "script_name": "Solution", "solution": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\npublic class Solution {\n\tstatic class Foo54 {\n\t\tint N;\n\t\tint[] arr;\n\t\tvoid main() {\n\t\t\tBu...
{ "solution": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\npublic class Solution {\n static class Foo54 {\n int N;\n int[] arr;\n void main() {\n BufferedReader br = null;\n try {\n br = new BufferedReader(new InputStreamReade...
{ "solution": " import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n Scanner scan = new Scanner(System.in);\n int n=scan...
{ "class_name": null, "func_sign": [ "solve(V)" ], "solution": "#!/bin/python3\n\n\nN = int(input())\nV = [int(i) for i in input().strip().split()]\nV.sort()\nnoOfLaps = (10**5)*2\nefR = 6 #not needed\nresult = 2*noOfLaps*(N//2)*(N-N//2)\n\npause = 0\n\nfor i in range(N-1):\n if pause != 1:\n if V...
eJzNl8FuJkUMhDlw5R2snFeou213t3kSJII4wB64hD3sSkgIiYeAV+TGO/BV/4mEspmg5USU0Z/MeLrtclW5/98+/+OvLz47P1//yR/f/HL348O7D+/vvrK7fv+wR9w/3L2xu7c/v3v7/fu3P3z304f3j4/b3a9v7B/hg/AZtrtfvhJNP8/ey/uHvrbVWrxbNszb5QLjxRU6L0SVVbhldJsZNsKKj86KNYb1ajb8upje2ksrD1au1iyXCrOgPhZiqz2aRRh5z5225+Raln1an4R7WXeS6Wm9EU1iu+W/4NLi2e4CIpzktWxjqdFZcvG/...
null
2,310
Prime Sum
The problem is quite simple. You're given a number N and a positive integer K. Tell if N can be represented as a sum of K prime numbers (not necessarily distinct). **Input Format** The first line contains a single integer T, denoting the number of test cases. Each of the next T lines contains two positive integer...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String solve(long n, long k)" ], "script_name": "Solution", "solution": "import java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\nimport java.util.NoSuchElementException;\nimport java.io.OutputStreamWrite...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Solution {\n static InputStream is;\n static PrintWriter ou...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Solution {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint MAX = 10000000;\n\t\tboolean[] isPrime = new boolean[MAX];\n\t\ti...
{ "class_name": null, "func_sign": [ "solve(n, k)" ], "solution": "import random\nimport sys\n\ndef is_probable_prime(n, k = 7):\n\tif n < 6:\n\t\treturn [False, False, True, True, False, True][n]\n\tif n & 1 == 0:\n\t\treturn False\n\ts, d = 0, n - 1\n\twhile d & 1 == 0:\n\t\ts, d = s + 1, d >> 1\n\t# Use ...
eJydmUuObEcRhhmwCyapHlsoH5GZESyCMYhGDOAOmLQt2ZaQkCUWAatjxkr4/shqY5qqriruldu3q8/JR+T/iuy//fwf//rFz/LPb/7JP37315c/v33z/Xcvvyov6/WtWfhorcUqfN1tTetbHw+rq9dZOt/MvTyi2yrTXt/c9qqtDLPBN3XMPotZ0zdRfL98VV6+/OWbL3/87suf/vD1999d5vr1169v+u+3X7796Rd99PLDV+UnqxqTKYNZ+vAVpdXWR/gOraR7WVU/ZsK+o43CtG33sthLDPPeyjI9un14Y2HLWLL1Gnu0MXI72vPu...
null
115
nCr
Given two integers $n$ and $r$. In how many ways can $r$ items be chosen from $n$ items?
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(int n, int r)" ], "script_name": "Solution", "solution": "import java.util.*;\n\npublic class Solution {\n static int[][] mod11;\n static int[][] mod13;\n static int[][] mod37;\n static int[][] mod27; // [x][0] = x! mod 27, [x][1] = y m...
{ "solution": "import java.util.*;\n\npublic class Solution {\n static int[][] mod11;\n static int[][] mod13;\n static int[][] mod37;\n static int[][] mod27; // [x][0] = x! mod 27, [x][1] = y mod 27, such that y * (x! mod 27) = 1 mod 27.\n \n static HashMap<Integer, int[][]> map;\n public static void main(Stri...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static int[][] mod11;\n\tprivate static int[][] mod13;\n\tprivate static int[][] mod37;\n\tprivate static int[][] mod27;\n\tprivate static HashMap<Integer, int[][]> map;\n\n\tpublic static void main(String[] args) {\n\t\tSca...
{ "class_name": null, "func_sign": [ "solve(n, r)" ], "solution": "invList = {27 : [0, 1, 14, -1, 7, 11, -1, 4, 17, -1, 19, 5, -1, 25, 2, -1, 22, 8, -1, 10, 23, -1, 16, 20, -1, 13, 26],\\\n11 : [0, 1, 6, 4, 3, 9, 2, 8, 7, 5, 10],\\\n13 : [0, 1, 7, 9, 10, 8, 11, 2, 5, 3, 4, 6, 12],\\\n37 : [0, 1, 19, 25, 28,...
eJztnMuubtdxnd1I0728wALbgjHvl7xGOgEiww1HjXQUNSTAgCHAD+G8b75vrCNaOjokNykmMeRDbkib/16XeakaNWpUzf9f/tP//s//9W/yz3/7W3757//8zf/89W9+99tv/svzTVu//HUtf/jnKX/yX//26y9/3ca6tY+ntj7m2h+8a9XdTp9PL2eN+tG77tlr9vWM209b54N31T5PaX0/a99S64dvc4S86HGEd92PrkdxlP3yocOsH77vXcfyh4UsH72PQc4y6lMZ5Z7to/d984vnm1/9029+9Y+//dX/+If/9bvfftr3yg2//HXJ...
null
4,503
Fibonacci GCD
Fibonacci numbers have the following form: $$F_1 = 1 \\\ F_2 = 1 \\\ F_3 = 2 \\\ \vdots \\\ F_n = F_{n-2}+F_{n-1}$$ We have an array $a_1, a_2, \ldots, a_N$ which contains $N$ elements. We want to find $\gcd(F_{a_1},F_{a_2},F_{a_3}, \cdots ,F_{a_N} )$. **Input Format** The first line contains $N$, where $...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(long a)" ], "script_name": "Solution", "solution": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimpo...
{ "solution": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic...
{ "solution": "import java.io.*;\nimport java.util.*;\n\nclass a\n{\n\tstatic int MOD=1000000000+7;\n\tpublic static void main(String[] args)throws IOException \n\t{\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st;\n\t\tPrintWriter pw=new PrintWriter(System.out);\n...
{ "class_name": null, "func_sign": [ "solve(a)" ], "solution": "P = 10**9 + 7\n\nfrom math import gcd\nfrom functools import reduce, lru_cache\n\n@lru_cache(maxsize = None)\ndef fib(n):\n if n == 0:\n return 0\n if n == 1:\n return 1\n if (n & 1) == 1:\n return (fib(n // 2) * f...
eJyMvU2ubcu2lecEBXm6aRLxHzEoCRJHImFegsyFxENCspCoiMvoKtC+r899jSxZeljge87Ze605x4joP6231vr//Df//v/5v//n//Ef/q+//ee//9f/9i9/+3f/9Lf+19/v/W6/9+x72l9//9u//ae//fN//6///H/+yz//p//4X/7bv/z+3Pja6Hvtv/2Pf/tP/9tf33/9fc515x13nTn/+vvuq512X9/v5J/efqP38V7LL3r5Ja99t+Xf/PX39cbd4/Rvr/n/+2v7/+f39fyYc1qbbd78pi+/vrX+zrfPuvlPt/fXxh535g+Os88c...
null
5,396
Fibonacci LCM
After Derek (of district 5) discovered how to compute the greatest common divisor (gcd) of Fibonacci numbers, he now tried to answer the next obvious question: how does one compute the *least common multiple* (lcm) of Fibonacci numbers? Unfortunately, Derek found out that this wasn't as easy as the original problem, so...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(List<Integer> f)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n \npublic static int mod = 1000000007;\n\n...
{ "solution": "import java.io.*;\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class HR_fibonacci_lcm {\n\n final static long MOD = 1000000007;\n final static long MOD2 = 1000000006;\n\n static long[][] mul(long[][] a, long[][] b) {\n long[][] c = new long[a.length][a.length];\n f...
{ "solution": "import java.io.*;\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class HR_fibonacci_lcm {\n\n final static long MOD = 1000000007;\n final static long MOD2 = 1000000006;\n\n static long[][] mul(long[][] a, long[][] b) {\n long[][] c = new long[a.length][a.length];\n f...
{ "class_name": null, "func_sign": [ "solve(f)" ], "solution": "import sys, random\nfrom math import sqrt\n\ndef gcd(a, b):\n while 1:\n if b == 0:\n return a\n a %= b\n if a == 0:\n return b\n b %= a\n\ndef fib_mod(n, mod):\n if n <= 2:\n return (((n + 1) >> 1) % mod, ((n + 2) >>...
eJztms2uJslVRRnwIFaNLRT/EcmTIFGIgfGASeGBLVlClngIeF/W2lnVUSr7GjMDq6v7dmfl/b7YEednn31O5n/87X/9av1N/vzDZy7+8d8//euX3/zut5/+/hefdvv85ZxTyin185f19LHLOg83n6c9fe3++cus7bS51/j8pZ5VVi9jcXedXp+x+Ow4pT/z85f+nNX3bnxnlN5n39NFa92t1M0H2nhqnevhLjB9ncrNUctTx1O8ZOnen1ZAKuM8axYux5rjtApmbXt0duWmWz98qbtq23X2MUpgW5u5W8tafPps7o66+zM862ycoG+O...
null
2,462
GCD Product
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...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(int n, int m)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchE...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Solution {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = ...
{ "solution": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\npublic class T {\n\n static MyScanner sc;\n private static PrintWriter out;\n\n private static int[] primes = new int[]{\n\n 2, 3, 5, 7, 11, 13, 17...
{ "class_name": null, "func_sign": [ "solve(n, m)" ], "solution": "#!/usr/bin/env python\n\nimport math, sys\n\n\nMOD = 1000000007\n\n\ndef rwh_primes2(n):\n \"\"\"Input n>=6, Returns a list of primes, 2 <= p < n\n http://stackoverflow.com/a/2068548/406772\"\"\"\n\n if n < 3:\n return []\n ...
eJx1lLtKBFEMhi18kDD1IrlffBJBxUK3sFGLFQQR7O1E39ezs1sIZxNSDJz58uf8yczn+e/3+dkaV1/j4fp9eXx6ed0tl7CI40gIxpHLBpbt28v2frd9uHt+3R3fKXZFU5Kbp+VjA//orGQhhHGcXtbwFjFwwZp4RVIBKyRuWE5DKo1Zm/AQUGtQUyBGgeKMWZyEuDwMSDCErG1BRDGL5wJMwxlRIMq07K5fTKOCZc4FLDyA0yMb1lFDU/UEC92N6YQOtMPN2HfHM3SwFY429+7yWBzCCReIjpmdrApZlTrGTExQui4LpBMj8nI/Yb5D...
null
5,747
Eugene and Big Number
Eugene must do his homework, but he is struggling. He has three integer numbers: *A*, *N*, *M*. He writes number *A* on the board *N* times **in a row**. Let's call the resulting big number *X*. Help Eugene find *X* [modulo](https://en.wikipedia.org/wiki/Modulo_operation) *M*.
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(int a, long n, int m)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputM...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class EABN {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = \"\"...
{ "solution": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.List;\nimport java.util.function.Function;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchExcept...
{ "class_name": null, "func_sign": [ "solve(a, n, m)" ], "solution": "for i in range(int(input())):\n a, b, c = map(int, input().split(' '))\n\n if len(str(a)) == 1:\n ans = pow(10,b,9*(c))\n ans = a*((ans - 1) // 9)\n print(ans%c)\n\n elif len(str(a)) == 2:\n ans = pow...
eJyNmc2OJTkRhVnwIFaxQyPksB12mCdBohELmAWbYhYzEhIaiYeA9+U7znur8uZPd1/1T9XNzHDEiRMnws7//PZ/9rvfrM+ffs8Pf/732z/ef/rl57c/pjdrX96H5xRz9GnRLM+WInr2GM2+vEcpadbh4W4xzVOd7mPm6l/ep7dU5uApt+JzpJ7HaL23+uW9tZ5ajmG91pFrT1Zrqxkr2JyeSngto7CSF56rXoaN+eW9N34defTaZ+BE8tmy9V7w06alyHga1qyNlkbgc4ky8KWm5s1qzq2VgislbHpu8eXdjdV99jKLueWaSskRdZZC...
null