Dataset Viewer
Auto-converted to Parquet Duplicate
id
int64
prompt
string
test_cases
list
606
Write a program that reads a degree value from standard input and converts it to radians, then prints the result to standard output. The conversion formula is: radians = degrees * (π/180)
[ { "stdin": "90", "stdout": "1.5707963267948966" }, { "stdin": "60", "stdout": "1.0471975511965976" }, { "stdin": "120", "stdout": "2.0943951023931953" } ]
604
Write a program to reverse the order of words in a given string. The program should read a string from standard input, reverse the order of its words while preserving the words themselves, and output the result.
[ { "stdin": "python program", "stdout": "program python" }, { "stdin": "java language", "stdout": "language java" }, { "stdin": "indian man", "stdout": "man indian" } ]
602
Write a program that reads a string from standard input and finds the first repeated character in the given string. If no character is repeated, the program should output "None". The program should: 1. Read a string from standard input 2. Find the first character that appears more than once in the string 3. Output tha...
[ { "stdin": "abcabc", "stdout": "a" }, { "stdin": "abc", "stdout": "None" }, { "stdin": "123123", "stdout": "1" } ]
608
Write a program that reads an integer n from standard input and outputs the nth Bell number. The Bell numbers are a sequence of numbers in partition theory, where B(n) represents the number of ways to partition a set with n elements. The program should calculate and print B(n) for a given n.
[ { "stdin": "2", "stdout": "2" }, { "stdin": "3", "stdout": "5" }, { "stdin": "4", "stdout": "15" } ]
618
Write a program that divides two lists element-wise using the map and lambda function. The program should read two lines of input, each containing space-separated numbers representing the two lists. It should divide corresponding elements from the first list by elements in the second list and output the result as a li...
[ { "stdin": "4 5 6\n1 2 3", "stdout": "[4.0, 2.5, 2.0]" }, { "stdin": "3 2\n1 4", "stdout": "[3.0, 0.5]" }, { "stdin": "90 120\n50 70", "stdout": "[1.8, 1.7142857142857142]" } ]
603
Write a program that reads an integer n and outputs all ludic numbers smaller than or equal to n. A ludic number is generated through a sieving process similar to the Sieve of Eratosthenes. Starting with the natural numbers, the process iteratively removes elements from the list: for each ludic number encountered, rem...
[ { "stdin": "10", "stdout": "1, 2, 3, 5, 7" }, { "stdin": "25", "stdout": "1, 2, 3, 5, 7, 11, 13, 17, 23, 25" }, { "stdin": "45", "stdout": "1, 2, 3, 5, 7, 11, 13, 17, 23, 25, 29, 37, 41, 43" } ]
609
Write a program that finds the minimum possible value for a periodic function given three parameters A, B, and N. The program should read three space-separated integers A, B, and N from standard input, compute the minimum value of the periodic function, and output the result. The formula for the minimum value is: flo...
[ { "stdin": "10 20 30", "stdout": "15" }, { "stdin": "1 2 1", "stdout": "0" }, { "stdin": "11 10 9", "stdout": "9" } ]
619
Write a program that takes a string as input and moves all the numbers to the end of the string, preserving the order of both non-digit characters and digits. The program should read a string from standard input and output the modified string where all digits have been moved to the end.
[ { "stdin": "I1love143you55three3000thousand", "stdout": "Iloveyouthreethousand1143553000" }, { "stdin": "Avengers124Assemble", "stdout": "AvengersAssemble124" }, { "stdin": "Its11our12path13to14see15things16do17things", "stdout": "Itsourpathtoseethingsdothings11121314151617" } ]
617
Write a program to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2D plane. The program should read three space-separated integers: `a` (first jump length), `b` (second jump length), and `d` (target x-coordinate). It should output the minimum number of jumps req...
[ { "stdin": "3 4 11", "stdout": "3.5" }, { "stdin": "3 4 0", "stdout": "0" }, { "stdin": "11 14 11", "stdout": "1" } ]
614
Write a program that finds the cumulative sum of all the values present in a given list of tuples. The program should read a list of tuples from standard input and output the cumulative sum of all values in those tuples. Input: A single line containing a list of tuples with integer values. Output: A single integer re...
[ { "stdin": "[(1, 3), (5, 6, 7), (2, 6)]", "stdout": "30" }, { "stdin": "[(2, 4), (6, 7, 8), (3, 7)]", "stdout": "37" }, { "stdin": "[(3, 5), (7, 8, 9), (4, 8)]", "stdout": "44" } ]
605
Write a program that checks if a given integer is a prime number. The program should read an integer from standard input and output "True" if the number is prime, or "False" if it is not prime.
[ { "stdin": "13", "stdout": "True" }, { "stdin": "7", "stdout": "True" }, { "stdin": "-1010", "stdout": "False" } ]
616
Write a program that performs the modulo of tuple elements in the given two tuples. The program reads two tuples of integers (as comma-separated values on separate lines) and outputs the result of performing element-wise modulo operation (first tuple element modulo second tuple element) as a comma-separated tuple. In...
[ { "stdin": "10,4,5,6\n5,6,7,5", "stdout": "0,4,5,1" }, { "stdin": "11,5,6,7\n6,7,8,6", "stdout": "5,5,6,1" }, { "stdin": "12,6,7,8\n7,8,9,7", "stdout": "5,6,7,1" } ]
620
Write a program that finds the largest subset where each pair is divisible. The program reads: - First line: an integer n, the length of the array - Second line: n space-separated integers representing the array The program outputs: - A single integer representing the size of the largest subset where each pair of ele...
[ { "stdin": "6\n1 3 6 13 17 18", "stdout": "4" }, { "stdin": "5\n10 5 3 15 20", "stdout": "3" }, { "stdin": "6\n18 1 3 6 13 17", "stdout": "4" } ]
610
Write a program that removes the k'th element from a given list. The program should read: 1. A list of integers (space-separated on one line) 2. An integer k representing the position to remove (1-indexed) The program should output the list with the k'th element removed, as space-separated integers.
[ { "stdin": "1 1 2 3 4 4 5 1\n3", "stdout": "1 1 3 4 4 5 1" }, { "stdin": "0 0 1 2 3 4 4 5 6 6 6 7 8 9 4 4\n4", "stdout": "0 0 1 3 4 4 5 6 6 6 7 8 9 4 4" }, { "stdin": "10 10 15 19 18 18 17 26 26 17 18 10\n5", "stdout": "10 10 15 19 18 17 26 26 17 18 10" } ]
607
Write a program that searches for a pattern (literal string) within a given text using regex and finds the location where the pattern occurs in the original string. The program should: 1. Read two lines from standard input: - First line: the text to search in - Second line: the pattern to search for 2. Use regex...
[ { "stdin": "The quick brown fox jumps over the lazy dog.\nfox", "stdout": "fox 16 19" }, { "stdin": "Its been a very crazy procedure right\ncrazy", "stdout": "crazy 16 21" }, { "stdin": "Hardest choices required strongest will\nwill", "stdout": "will 35 39" } ]
611
Write a program to find the maximum of the Nth column from a given tuple list. Your program should: 1. Read a list of tuples on the first line (as a string representation) 2. Read the column index N on the second line 3. Output the maximum value found in column N across all tuples For example, given the tuple list [(...
[ { "stdin": "[(5, 6, 7), (1, 3, 5), (8, 9, 19)]\n2", "stdout": "19" }, { "stdin": "[(6, 7, 8), (2, 4, 6), (9, 10, 20)]\n1", "stdout": "10" }, { "stdin": "[(7, 8, 9), (3, 5, 7), (10, 11, 21)]\n1", "stdout": "11" } ]
601
Write a program to find the longest chain which can be formed from the given set of pairs. A pair (a, b) can be followed by another pair (c, d) in a chain if a > d. The program should read pairs from input and output the length of the longest possible chain. Input format: - First line: n (the number of pairs) - Next ...
[ { "stdin": "4\n5 24\n15 25\n27 40\n50 60", "stdout": "3" }, { "stdin": "4\n1 2\n3 4\n5 6\n7 8", "stdout": "4" }, { "stdin": "5\n19 10\n11 12\n13 14\n15 16\n31 54", "stdout": "5" } ]
615
Write a program that reads a tuple of tuples from standard input and outputs the average value of the numbers in each column. The program should: 1. Read a tuple of tuples from standard input (each inner tuple has the same length) 2. Calculate the average of numbers in each column (position) 3. Output the list of aver...
[ { "stdin": "((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4))", "stdout": "[30.5, 34.25, 27.0, 23.25]" }, { "stdin": "((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3))", "stdout": "[25.5, -18.0, 3.75]" }, { "stdin": "((100, 100, 100, 120), (300, 450, 560, 450), ...
613
Write a program that finds the maximum value in each record list as a tuple attribute in the given tuple list. The program should read from standard input a list of records, where each record is a tuple containing a key (string) and a list of integers. For each record, the program should output the key paired with the...
[ { "stdin": "3\nkey1 3 4 5\nkey2 1 4 2\nkey3 9 3", "stdout": "key1,5\nkey2,4\nkey3,9" }, { "stdin": "3\nkey1 4 5 6\nkey2 2 5 3\nkey3 10 4", "stdout": "key1,6\nkey2,5\nkey3,10" }, { "stdin": "3\nkey1 5 6 7\nkey2 3 6 4\nkey3 11 5", "stdout": "key1,7\nkey2,6\nkey3,11" } ]
621
Write a program that increments the numeric values in the given strings by k. The program should: 1. Read an integer k from the first line of input 2. Read a comma-separated list of strings from the second line 3. For each string in the list, if it represents a numeric value, increment it by k; otherwise, leave it unc...
[ { "stdin": "6\nMSM, 234, is, 98, 123, best, 4", "stdout": "MSM, 240, is, 104, 129, best, 10" }, { "stdin": "12\nDart, 356, is, 88, 169, Super, 6", "stdout": "Dart, 368, is, 100, 181, Super, 18" }, { "stdin": "33\nFlutter, 451, is, 44, 96, Magnificent, 12", "stdout": "Flutter, 484, is...
624
Write a program that reads a string from standard input and converts it to uppercase, then outputs the result.
[ { "stdin": "person", "stdout": "PERSON" }, { "stdin": "final", "stdout": "FINAL" }, { "stdin": "Valid", "stdout": "VALID" } ]
623
Write a program to find the n-th power of individual elements in a list using a lambda function. The program should: 1. Read a list of integers from the first line of input (space-separated) 2. Read an integer n (the exponent) from the second line of input 3. Use a lambda function with map to compute the n-th power of...
[ { "stdin": "1 2 3 4 5 6 7 8 9 10\n2", "stdout": "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]" }, { "stdin": "10 20 30\n3", "stdout": "[1000, 8000, 27000]" }, { "stdin": "12 15\n5", "stdout": "[248832, 759375]" } ]
625
Write a program that reads a list of integers from standard input and interchanges the first and last elements in the list. The program should output the modified list with the first and last elements swapped. Input: A single line containing space-separated integers representing the list elements. Output: A single lin...
[ { "stdin": "1 2 3", "stdout": "3 2 1" }, { "stdin": "1 2 3 4 4", "stdout": "4 2 3 4 1" }, { "stdin": "4 5 6", "stdout": "6 5 4" } ]
629
Write a program that reads a list of integers and finds all even numbers from the list. The program should: 1. Read a line of space-separated integers from standard input 2. Filter the list to keep only even numbers (numbers divisible by 2) 3. Output the filtered list of even numbers to standard output
[ { "stdin": "1 2 3 4 5", "stdout": "[2, 4]" }, { "stdin": "4 5 6 7 8 0 1", "stdout": "[4, 6, 8, 0]" }, { "stdin": "8 12 15 19", "stdout": "[8, 12]" } ]
626
Write a program that finds the area of the largest triangle that can be inscribed in a semicircle. Given a semicircle with radius r, find the maximum area of a triangle that can be inscribed in the semicircle. The maximum area of a triangle inscribed in a semicircle of radius r is r². Input: A single integer or float...
[ { "stdin": "0", "stdout": "0" }, { "stdin": "-1", "stdout": "-1" }, { "stdin": "2", "stdout": "4" } ]
633
Write a program that reads an array of numbers and finds the sum of XOR of all pairs of numbers in the given array. The program should: - Read the size of the array from the first line of input - Read the array elements from the second line of input (space-separated integers) - Calculate the sum of XOR values for all ...
[ { "stdin": "4\n5 9 7 6", "stdout": "47" }, { "stdin": "3\n7 3 5", "stdout": "12" }, { "stdin": "2\n7 3", "stdout": "4" } ]
622
Write a program to find the median of two sorted arrays of the same size. The program should read: 1. An integer n representing the size of each array 2. n space-separated integers representing the first sorted array 3. n space-separated integers representing the second sorted array The program should output the medi...
[ { "stdin": "5\n1 12 15 26 38\n2 13 17 30 45", "stdout": "16.0" }, { "stdin": "4\n2 4 8 9\n7 13 19 28", "stdout": "8.5" }, { "stdin": "6\n3 6 14 23 36 42\n2 18 27 39 49 55", "stdout": "25.0" } ]
634
Write a program that reads a positive integer n from standard input and outputs the sum of the fourth powers of the first n even natural numbers. For example, for n=2, the first 2 even natural numbers are 2 and 4. The sum of their fourth powers is 2^4 + 4^4 = 16 + 256 = 272.
[ { "stdin": "2", "stdout": "272" }, { "stdin": "3", "stdout": "1568" }, { "stdin": "4", "stdout": "5664" } ]
637
Write a program that checks whether a transaction has no profit and no loss. A transaction has no profit and no loss when the sale amount equals the actual cost. The program should read two integers from input: - The first integer is the actual cost - The second integer is the sale amount The program should output Tr...
[ { "stdin": "1500\n1200", "stdout": "False" }, { "stdin": "100\n100", "stdout": "True" }, { "stdin": "2000\n5000", "stdout": "False" } ]
638
Write a program to calculate the wind chill index. The program should read two values from standard input: 1. Wind speed (v) in km/h 2. Temperature (t) in degrees Celsius Calculate the wind chill index using the formula: windchill = 13.12 + 0.6215*t - 11.37*v^0.16 + 0.3965*t*v^0.16 Output the wind chill index as an ...
[ { "stdin": "120 35", "stdout": "40" }, { "stdin": "40 70", "stdout": "86" }, { "stdin": "10 100", "stdout": "116" } ]
631
Write a program that reads strings from input and replaces whitespaces with underscores (and vice versa) using regex. For each input string, output the transformed string where spaces are replaced with underscores.
[ { "stdin": "Jumanji The Jungle", "stdout": "Jumanji_The_Jungle" }, { "stdin": "The Avengers", "stdout": "The_Avengers" }, { "stdin": "Fast and Furious", "stdout": "Fast_and_Furious" } ]
627
Write a program to find the smallest missing number from the given array. The program should: 1. Read an array of integers from the first line of input (space-separated) 2. Read the start index from the second line 3. Read the end index from the third line 4. Find and output the smallest missing number in the array be...
[ { "stdin": "0 1 2 3\n0\n3", "stdout": "4" }, { "stdin": "0 1 2 6 9\n0\n4", "stdout": "3" }, { "stdin": "2 3 5 8 9\n0\n4", "stdout": "0" } ]
636
Write a program that checks if the roots of a quadratic equation are reciprocals of each other or not. Given a quadratic equation of the form ax² + bx + c = 0, determine whether the roots are reciprocals of each other. The program should read three integers a, b, and c (the coefficients of the quadratic equation) and...
[ { "stdin": "2 0 2", "stdout": "Yes" }, { "stdin": "2 -5 2", "stdout": "Yes" }, { "stdin": "1 2 3", "stdout": "No" } ]
632
Write a program that reads a list of integers from standard input and moves all zeroes to the end of the list, then outputs the resulting list. The program should: 1. Read a comma-separated list of integers from a single line of input 2. Move all zeros to the end of the list while maintaining the relative order of non...
[ { "stdin": "1,0,2,0,3,4", "stdout": "1,2,3,4,0,0" }, { "stdin": "2,3,2,0,0,4,0,5,0", "stdout": "2,3,2,4,5,0,0,0,0" }, { "stdin": "0,1,0,1,1", "stdout": "1,1,1,0,0" } ]
641
Write a program that reads an integer n and outputs the nth nonagonal number. A nonagonal number is a figurate number that represents a nonagon (9-sided polygon). The nth nonagonal number can be calculated using the formula: n * (7n - 5) / 2.
[ { "stdin": "10", "stdout": "325" }, { "stdin": "15", "stdout": "750" }, { "stdin": "18", "stdout": "1089" } ]
635
Write a program that reads a list of integers from standard input, pushes all values into a heap, and then pops off the smallest values one at a time to output them in sorted order. The program should: 1. Read a single line containing space-separated integers 2. Push all values into a min-heap 3. Pop off values one at...
[ { "stdin": "1 3 5 7 9 2 4 6 8 0", "stdout": "0 1 2 3 4 5 6 7 8 9" }, { "stdin": "25 35 22 85 14 65 75 25 58", "stdout": "14 22 25 25 35 58 65 75 85" }, { "stdin": "7 1 9 5", "stdout": "1 5 7 9" } ]
640
Write a program that removes the parenthesis area in a string. The program should read a string from standard input and output the string with all parenthesized content (and optional preceding space) removed.
[ { "stdin": "python (chrome)", "stdout": "python" }, { "stdin": "string(.abc)", "stdout": "string" }, { "stdin": "alpha(num)", "stdout": "alpha" } ]
612
Write a program that reads a list of lists from standard input and merges elements at corresponding positions across all sublists (transposes the matrix). The input consists of multiple lines, where each line contains space-separated elements. The program should output the transposed result, with each line representin...
[ { "stdin": "x y\na b\nm n", "stdout": "x a m\ny b n" }, { "stdin": "1 2\n3 4\n5 6\n7 8", "stdout": "1 3 5 7\n2 4 6 8" }, { "stdin": "x y z\na b c\nm n o", "stdout": "x a m\ny b n\nz c o" } ]
628
Write a program that reads a string from standard input and replaces all spaces in the string with '%20'. Output the modified string. The program should: 1. Read a string from standard input 2. Replace all spaces with the sequence '%20' 3. Output the result to standard output 4. Return -1 if the resulting string lengt...
[ { "stdin": "My Name is Dawood", "stdout": "My%20Name%20is%20Dawood" }, { "stdin": "I am a Programmer", "stdout": "I%20am%20a%20Programmer" }, { "stdin": "I love Coding", "stdout": "I%20love%20Coding" } ]
630
Write a program that extracts all the adjacent coordinates of a given coordinate tuple. The program should read a coordinate tuple from standard input (as a tuple representation) and output all adjacent coordinates. For a coordinate in n-dimensional space, adjacent coordinates include all combinations where each dimen...
[ { "stdin": "(3, 4)", "stdout": "[[2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5]]" }, { "stdin": "(4, 5)", "stdout": "[[3, 4], [3, 5], [3, 6], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6]]" }, { "stdin": "(5, 6)", "stdout": "[[4, 5], [4, 6], [4, 7], [5, 5], [...
643
Write a program that reads a text string and matches if it contains the letter 'z' not at the start or end of a word. The program should: - Read a text string from standard input - Check if the string contains 'z' in the middle of a word (not at word boundaries) - Output "Found a match!" if such a 'z' is found - Outp...
[ { "stdin": "pythonzabc.", "stdout": "Found a match!" }, { "stdin": "xyzabc.", "stdout": "Found a match!" }, { "stdin": " lang .", "stdout": "Not matched!" } ]
646
Write a program that counts the number of cubes of size k in a cube of size n. The program should read two integers from standard input: - N: the size of the large cube - K: the size of the small cube The program should output a single integer representing the number of k×k×k cubes that can fit in an n×n×n cube.
[ { "stdin": "2 1", "stdout": "8" }, { "stdin": "5 2", "stdout": "64" }, { "stdin": "1 1", "stdout": "1" } ]
639
Write a program that reads a list of names and outputs the sum of the lengths of names after removing the names that start with a lowercase letter. The program should: 1. Read names from input (one per line) 2. Filter out names that do not start with an uppercase letter or contain non-lowercase characters after the fi...
[ { "stdin": "sally\nDylan\nrebecca\nDiana\nJoanne\nkeith", "stdout": "16" }, { "stdin": "php\nres\nPython\nabcd\nJava\naaa", "stdout": "10" }, { "stdin": "abcd\nPython\nabba\naba", "stdout": "6" } ]
654
Write a program that reads the dimensions of a rectangle (length and breadth) from standard input and outputs its perimeter. The perimeter of a rectangle is calculated as 2 × (length + breadth). Input: Two space-separated integers representing the length and breadth of the rectangle. Output: A single integer represen...
[ { "stdin": "10 20", "stdout": "60" }, { "stdin": "10 5", "stdout": "30" }, { "stdin": "4 2", "stdout": "12" } ]
648
Write a program that exchanges the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given list. The program should read a list of integers from standard input (space-separated on a single line) and output the result (space-separated values) to standard output.
[ { "stdin": "0 1 2 3 4 5", "stdout": "1 0 3 2 5 4" }, { "stdin": "5 6 7 8 9 10", "stdout": "6 5 8 7 10 9" }, { "stdin": "25 35 45 55 75 95", "stdout": "35 25 55 45 95 75" } ]
655
Write a program that reads an integer n from standard input and outputs the sum of fifth powers of the first n natural numbers. The program should calculate: 1^5 + 2^5 + 3^5 + ... + n^5 and print the result.
[ { "stdin": "2", "stdout": "33" }, { "stdin": "4", "stdout": "1300" }, { "stdin": "3", "stdout": "276" } ]
644
Write a program that reverses an array up to a given position. The program should: 1. Read an array of integers from the first line of input (space-separated) 2. Read a position k from the second line of input 3. Reverse the elements from index 0 to k-1 (inclusive), keeping elements from index k onwards unchanged 4. O...
[ { "stdin": "1 2 3 4 5 6\n4", "stdout": "4 3 2 1 5 6" }, { "stdin": "4 5 6 7\n2", "stdout": "5 4 6 7" }, { "stdin": "9 8 7 6 5\n3", "stdout": "7 8 9 6 5" } ]
647
Write a program that reads a string and splits it at uppercase letters. Each word in the result starts with an uppercase letter followed by zero or more non-uppercase letters. Output the resulting list of split words.
[ { "stdin": "PythonProgramLanguage", "stdout": "['Python', 'Program', 'Language']" }, { "stdin": "PythonProgram", "stdout": "['Python', 'Program']" }, { "stdin": "ProgrammingLanguage", "stdout": "['Programming', 'Language']" } ]
645
Write a program that finds the product of the kth index elements across multiple tuples. The program should: 1. Read the index K from input 2. Read a list of tuples from input 3. Extract the element at index K from each tuple 4. Calculate and output the product of all these elements Input format: - Line 1: An integer...
[ { "stdin": "2\n[(5, 6, 7), (1, 3, 5), (8, 9, 19)]", "stdout": "665" }, { "stdin": "1\n[(6, 7, 8), (2, 4, 6), (9, 10, 20)]", "stdout": "280" }, { "stdin": "0\n[(7, 8, 9), (3, 5, 7), (10, 11, 21)]", "stdout": "210" } ]
651
Write a program to check if one tuple is a subset of another tuple. The program should read two lines of input: - The first line contains space-separated integers representing the first tuple - The second line contains space-separated integers representing the second tuple The program should output True if the second...
[ { "stdin": "10 4 5 6\n5 10", "stdout": "True" }, { "stdin": "1 2 3 4\n5 6", "stdout": "False" }, { "stdin": "7 8 9 10\n10 8", "stdout": "True" } ]
649
Write a program that reads a list of numbers and a range specified by two indices, then calculates and outputs the sum of the numbers in the list between those indices (inclusive). The program should: 1. Read a list of numbers from the first line of input (space-separated integers) 2. Read two indices m and n from the...
[ { "stdin": "2 1 5 6 8 3 4 9 10 11 8 12\n8 10", "stdout": "29" }, { "stdin": "1 2 3 4 5\n1 2", "stdout": "5" }, { "stdin": "1 0 1 2 5 6\n4 5", "stdout": "11" } ]
653
Write a program to group a sequence of key-value pairs into a dictionary of lists using the collections module. The program should read from standard input a list of key-value pairs (as tuples), and output to standard output the resulting dictionary where each key is mapped to a list of all its associated values.
[ { "stdin": "[('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]", "stdout": "{'yellow': [1, 3], 'blue': [2, 4], 'red': [1]}" }, { "stdin": "[('yellow', 10), ('blue', 20), ('yellow', 30), ('blue', 40), ('red', 10)]", "stdout": "{'yellow': [10, 30], 'blue': [20, 40], 'red': [10]}"...
657
Write a program that reads an integer from standard input and outputs the first digit in the factorial of that number. The program should: 1. Read an integer n from stdin 2. Calculate the factorial of n 3. Find and output the first (leftmost) digit of that factorial
[ { "stdin": "5", "stdout": "1" }, { "stdin": "10", "stdout": "3" }, { "stdin": "7", "stdout": "5" } ]
642
Write a program to remove similar rows from the given tuple matrix. The program should read a matrix where rows contain tuples, normalize each row by sorting its tuples and removing duplicates, and output the set of unique normalized rows. Input format: - First line: number of rows N - Next N lines: each line contain...
[ { "stdin": "3\n(4,5),(3,2)\n(2,2),(4,6)\n(3,2),(4,5)", "stdout": "{((2, 2), (4, 6)), ((3, 2), (4, 5))}" }, { "stdin": "3\n(5,6),(4,3)\n(3,3),(5,7)\n(4,3),(5,6)", "stdout": "{((3, 3), (5, 7)), ((4, 3), (5, 6))}" }, { "stdin": "3\n(6,7),(5,4)\n(4,4),(6,8)\n(5,4),(6,7)", "stdout": "{((4...
650
Write a program that checks whether two given arrays are equal or not. Two arrays are considered equal if they have the same length and contain the same elements (in any order). The program should read: - First line: n (length of first array) - Second line: n space-separated integers (first array) - Third line: m (len...
[ { "stdin": "3\n1 2 3\n3\n3 2 1", "stdout": "True" }, { "stdin": "3\n1 1 1\n3\n2 2 2", "stdout": "False" }, { "stdin": "2\n8 9\n3\n4 5 6", "stdout": "False" } ]
658
Write a program to find the item with maximum occurrences in a given list. The program should read a list of space-separated integers from standard input and output the item that appears most frequently in the list.
[ { "stdin": "2 3 8 4 7 9 8 2 6 5 1 6 1 2 3 4 6 9 1 2", "stdout": "2" }, { "stdin": "1 3 5 7 1 3 13 15 17 5 7 9 1 11", "stdout": "1" }, { "stdin": "1 2 3 2 4 5 1 1 1", "stdout": "1" } ]
656
Write a program to find the minimum sum of absolute differences of two arrays. The program should read: - First line: an integer n (the size of both arrays) - Second line: n space-separated integers representing array a - Third line: n space-separated integers representing array b The program should output the minimu...
[ { "stdin": "3\n3 2 1\n2 1 3", "stdout": "0" }, { "stdin": "3\n1 2 3\n4 5 6", "stdout": "9" }, { "stdin": "4\n4 1 8 7\n2 3 6 5", "stdout": "6" } ]
652
Write a program that reads a tuple matrix from standard input and flattens it into a tuple list where each tuple represents each column. The input will be a string representation of a nested list of tuples (a matrix). The program should output the flattened result as a string representation of a list of tuples, where e...
[ { "stdin": "[[(4, 5), (7, 8)], [(10, 13), (18, 17)], [(0, 4), (10, 1)]]", "stdout": "[(4, 7, 10, 18, 0, 10), (5, 8, 13, 17, 4, 1)]" }, { "stdin": "[[(5, 6), (8, 9)], [(11, 14), (19, 18)], [(1, 5), (11, 2)]]", "stdout": "[(5, 8, 11, 19, 1, 11), (6, 9, 14, 18, 5, 2)]" }, { "stdin": "[[(6, ...
659
Write a program that reads a list of integers from standard input and prints all duplicate elements from the list. A duplicate element is one that appears more than once in the list. The program should print the duplicates in the order they are first found to be duplicated (i.e., each duplicate should appear only once...
[ { "stdin": "10 20 30 20 20 30 40 50 -20 60 60 -20 -20", "stdout": "20 30 -20 60" }, { "stdin": "-1 1 -1 8", "stdout": "-1" }, { "stdin": "1 2 3 1 2", "stdout": "1 2" } ]
666
Write a program to count the occurrence of a character in a string. The program should read two lines from standard input: - The first line contains a string - The second line contains a single character to count Output the count of how many times the character appears in the string.
[ { "stdin": "Python\no", "stdout": "1" }, { "stdin": "little\nt", "stdout": "2" }, { "stdin": "assert\ns", "stdout": "2" } ]
660
Write a program that reads two ranges and outputs two points such that the points represent the minimum left boundary and maximum right boundary of the ranges. Specifically, given two ranges [l1, r1] and [l2, r2], the program should output the minimum of the left boundaries and the maximum of the right boundaries. In...
[ { "stdin": "5 10 1 5", "stdout": "1 10" }, { "stdin": "3 5 7 9", "stdout": "3 9" }, { "stdin": "1 5 2 8", "stdout": "1 8" } ]
668
Write a program that reads a string and a character from standard input, and replaces multiple consecutive occurrences of that character with a single occurrence. The program should: 1. Read a string from the first line of input 2. Read a character from the second line of input 3. Replace all occurrences of 2 or more ...
[ { "stdin": "peep\ne", "stdout": "pep" }, { "stdin": "Greek\ne", "stdout": "Grek" }, { "stdin": "Moon\no", "stdout": "Mon" } ]
667
Write a program that counts the number of vowels in a string. The program should read two lines from standard input: the first line is a string, and the second line is a string containing the vowel characters to match against. The program should output the count of vowels found in the input string.
[ { "stdin": "corner\nAaEeIiOoUu", "stdout": "2" }, { "stdin": "valid\nAaEeIiOoUu", "stdout": "2" }, { "stdin": "true\nAaEeIiOoUu", "stdout": "2" } ]
664
Write a program that reads an even number from standard input and outputs the average of all even numbers from 2 to that number (inclusive). If the input is an odd number, output "Invalid Input".
[ { "stdin": "2", "stdout": "2" }, { "stdin": "4", "stdout": "3" }, { "stdin": "100", "stdout": "51" } ]
662
Write a program that reads a dictionary from standard input and outputs a dictionary with sorted lists. The program should read a dictionary where the values are lists, sort each list in place, and output the resulting dictionary. Input: A dictionary in JSON format where keys are strings and values are lists of integ...
[ { "stdin": "{\"n1\": [2, 3, 1], \"n2\": [5, 1, 2], \"n3\": [3, 2, 4]}", "stdout": "{\"n1\": [1, 2, 3], \"n2\": [1, 2, 5], \"n3\": [2, 3, 4]}" }, { "stdin": "{\"n1\": [25, 37, 41], \"n2\": [41, 54, 63], \"n3\": [29, 38, 93]}", "stdout": "{\"n1\": [25, 37, 41], \"n2\": [41, 54, 63], \"n3\": [29, 3...
661
Write a program that finds the maximum sum that can be formed from an array such that no three consecutive elements are all included in the sum. The program should read an array of integers from standard input and output the maximum possible sum where no three consecutive elements from the original array are all selec...
[ { "stdin": "100 1000 100 1000 1", "stdout": "2101" }, { "stdin": "3000 2000 1000 3 10", "stdout": "5013" }, { "stdin": "1 2 3 4 5 6 7 8", "stdout": "27" } ]
663
Write a program to find the largest possible value of k such that k modulo x is y, where k is between 0 and n (inclusive). The program should read three space-separated integers n, x, and y from standard input, and output the largest value of k in the range [0, n] such that k mod x equals y. If no such value exists, o...
[ { "stdin": "15 10 5", "stdout": "15" }, { "stdin": "187 10 5", "stdout": "185" }, { "stdin": "16 11 1", "stdout": "12" } ]
665
Write a program that reads a list of numbers from standard input, shifts the first element to the end of the list, and outputs the resulting list. The program should: 1. Read a single line containing a list of space-separated integers 2. Move the first element of the list to the end 3. Output the resulting list as spa...
[ { "stdin": "1 2 3 4", "stdout": "2 3 4 1" }, { "stdin": "2 3 4 1 5 0", "stdout": "3 4 1 5 0 2" }, { "stdin": "5 4 3 2 1", "stdout": "4 3 2 1 5" } ]
678
Write a program that reads a string from standard input and removes all spaces from it. The program should output the resulting string without spaces.
[ { "stdin": "a b c", "stdout": "abc" }, { "stdin": "1 2 3", "stdout": "123" }, { "stdin": " b c", "stdout": "bc" } ]
672
Write a program that finds the maximum of three numbers. The program should read three integers from standard input and output the maximum value. Input: Three integers separated by spaces Output: The maximum of the three integers
[ { "stdin": "10 20 30", "stdout": "30" }, { "stdin": "55 47 39", "stdout": "55" }, { "stdin": "10 49 30", "stdout": "49" } ]
676
Write a program that removes everything except alphanumeric characters from the given input string by using regex. The program should read a string from standard input and output the processed string (with only alphanumeric characters remaining) to standard output.
[ { "stdin": "**//Google Android// - 12. ", "stdout": "GoogleAndroid12" }, { "stdin": "****//Google Flutter//*** - 36. ", "stdout": "GoogleFlutter36" }, { "stdin": "**//Google Firebase// - 478. ", "stdout": "GoogleFirebase478" } ]
674
Write a program that removes duplicate words from a given string using the collections module. The program should read a string from standard input and output the string with duplicate words removed, preserving the order of first occurrence of each word. Use the collections module (specifically OrderedDict) to accom...
[ { "stdin": "Python Exercises Practice Solution Exercises", "stdout": "Python Exercises Practice Solution" }, { "stdin": "Python Exercises Practice Solution Python", "stdout": "Python Exercises Practice Solution" }, { "stdin": "Python Exercises Practice Solution Practice", "stdout": "...
673
Write a program that reads a list of integers from standard input and converts them into a single integer by concatenating their digits. The program should: 1. Read a line containing space-separated integers 2. Concatenate all the integers together 3. Output the resulting single integer
[ { "stdin": "1 2 3", "stdout": "123" }, { "stdin": "4 5 6", "stdout": "456" }, { "stdin": "7 8 9", "stdout": "789" } ]
670
Write a program that reads a sequence of numbers and checks whether the sequence is in non-decreasing (ascending) order. The program should: 1. Read a single line containing space-separated integers 2. Check if the sequence is sorted in non-decreasing order (i.e., each element is less than or equal to the next) 3. Out...
[ { "stdin": "-4 -3 -2 -1", "stdout": "True" }, { "stdin": "1 2 3", "stdout": "True" }, { "stdin": "3 2 1", "stdout": "False" } ]
675
Write a program that reads four integers from standard input: two integers to add (x and y), and a range defined by two integers (m and n). The program should add the two integers. However, if the sum is within the given range [m, n), it should output 20. Otherwise, it should output the sum itself.
[ { "stdin": "2 10 11 20", "stdout": "20" }, { "stdin": "15 17 1 10", "stdout": "32" }, { "stdin": "10 15 5 30", "stdout": "20" } ]
669
Write a program that checks whether a given IP address is valid or not using regex. The program should: - Read an IP address from standard input - Validate the IP address using regex to ensure all four octets are numbers between 0 and 255 - Output "Valid IP address" if the IP is valid, or "Invalid IP address" if it is...
[ { "stdin": "192.168.0.1", "stdout": "Valid IP address" }, { "stdin": "110.234.52.124", "stdout": "Valid IP address" }, { "stdin": "366.1.2.2", "stdout": "Invalid IP address" } ]
671
Write a program that reads an integer from standard input and sets the rightmost unset bit of that integer, then outputs the result. The rightmost unset bit is the least significant bit that is currently 0 in the binary representation of the number. The program should set this bit to 1 and output the resulting number....
[ { "stdin": "21", "stdout": "23" }, { "stdin": "11", "stdout": "15" }, { "stdin": "15", "stdout": "15" } ]
681
Write a program that finds the smallest prime divisor of a number. The program should read an integer n from standard input and output the smallest prime divisor of that number.
[ { "stdin": "10", "stdout": "2" }, { "stdin": "25", "stdout": "5" }, { "stdin": "31", "stdout": "31" } ]
683
Write a program that reads a number from standard input and checks whether the given number can be represented by the sum of two squares or not. Output "True" if it can be represented as the sum of two squares, and "False" otherwise.
[ { "stdin": "25", "stdout": "True" }, { "stdin": "24", "stdout": "False" }, { "stdin": "17", "stdout": "True" } ]
685
Write a program that reads an integer n from standard input and prints the sum of all prime numbers between 1 and n (inclusive).
[ { "stdin": "10", "stdout": "17" }, { "stdin": "20", "stdout": "77" }, { "stdin": "5", "stdout": "10" } ]
680
Write a program that checks whether a sequence of numbers has an increasing trend or not. The program should: - Read a sequence of numbers from standard input (space-separated integers on a single line) - Check if the sequence is in non-decreasing order (increasing trend) - Output "True" if the sequence has an increas...
[ { "stdin": "1 2 3 4", "stdout": "True" }, { "stdin": "4 3 2 1", "stdout": "False" }, { "stdin": "0 1 4 9", "stdout": "True" } ]
679
Write a program that accesses dictionary keys by index. The program should: 1. Read a dictionary (as a dictionary literal) from the first line of input 2. Read an index from the second line of input 3. Output the key at the specified index The keys are ordered as they appear in the dictionary. The index is 0-based.
[ { "stdin": "{'physics': 80, 'math': 90, 'chemistry': 86}\n0", "stdout": "physics" }, { "stdin": "{'python':10, 'java': 20, 'C++':30}\n2", "stdout": "C++" }, { "stdin": "{'program':15,'computer':45}\n1", "stdout": "computer" } ]
682
Write a program that multiplies two lists using map and lambda function. The program should read two lists from standard input, where each list is represented as space-separated integers on separate lines. It should multiply the corresponding elements from both lists element-wise using the map and lambda functions, an...
[ { "stdin": "1 2 3\n4 5 6", "stdout": "4, 10, 18" }, { "stdin": "1 2\n3 4", "stdout": "3, 8" }, { "stdin": "90 120\n50 70", "stdout": "4500, 8400" } ]
693
Write a program that removes multiple consecutive spaces in a string by using regex. The program should read a string from standard input and output the string with multiple consecutive spaces replaced by a single space.
[ { "stdin": "Google Assistant", "stdout": "Google Assistant" }, { "stdin": "Quad Core", "stdout": "Quad Core" }, { "stdin": "ChromeCast Built-in", "stdout": "ChromeCast Built-in" } ]
687
Write a program to find the greatest common divisor (gcd) of two integers by using recursion. The program should read two integers from standard input and output their GCD to standard output.
[ { "stdin": "12 14", "stdout": "2" }, { "stdin": "13 17", "stdout": "1" }, { "stdin": "9 3", "stdout": "3" } ]
688
Write a program that reads two numbers representing the real and imaginary parts of a complex number, and outputs the length (magnitude) of that complex number. Input: Two space-separated numbers on a single line Output: A single number representing the length of the complex number
[ { "stdin": "3 4", "stdout": "5.0" }, { "stdin": "9 10", "stdout": "13.45362404707371" }, { "stdin": "7 9", "stdout": "11.40175425099138" } ]
686
Write a program that reads a sequence of integers and finds the frequency of each element. The program should: 1. Read a line of comma-separated integers from standard input 2. Count the frequency of each element 3. Output the frequencies as a dictionary string representation, maintaining the order in which elements f...
[ { "stdin": "4,5,4,5,6,6,5,5,4", "stdout": "{4: 3, 5: 4, 6: 2}" }, { "stdin": "7,8,8,9,4,7,6,5,4", "stdout": "{7: 2, 8: 2, 9: 1, 4: 2, 6: 1, 5: 1}" }, { "stdin": "1,4,3,1,4,5,2,6,2,7", "stdout": "{1: 2, 4: 2, 3: 1, 5: 1, 2: 2, 6: 1, 7: 1}" } ]
684
Write a program that counts the occurrences of a character in a string repeated to fill exactly 10 characters total. The program should: 1. Read a string and a character from standard input 2. Count how many times the character appears when the string is repeated enough times to fill exactly 10 character positions 3. ...
[ { "stdin": "abcac a", "stdout": "4" }, { "stdin": "abca c", "stdout": "2" }, { "stdin": "aba a", "stdout": "7" } ]
692
Write a program that finds the last two digits in the factorial of a given number. Your program should read an integer N from standard input and output the last two digits of N! (N factorial) modulo 100.
[ { "stdin": "7", "stdout": "40" }, { "stdin": "5", "stdout": "20" }, { "stdin": "2", "stdout": "2" } ]
690
Write a program to multiply consecutive numbers of a given list. The program should read a list of numbers from standard input (space-separated integers on a single line), compute the product of each pair of consecutive numbers, and output the resulting list to standard output (space-separated integers on a single lin...
[ { "stdin": "1 1 3 4 4 5 6 7", "stdout": "1 3 12 16 20 30 42" }, { "stdin": "4 5 8 9 6 10", "stdout": "20 40 72 54 60" }, { "stdin": "1 2 3 4 5 6 7 8 9 10", "stdout": "2 6 12 20 30 42 56 72 90" } ]
697
Write a program to find the number of even elements in the given list using a lambda function. The program should read a list of integers from standard input (space-separated on a single line) and output the count of even elements using a lambda function with filter.
[ { "stdin": "1 2 3 5 7 8 9 10", "stdout": "3" }, { "stdin": "10 15 14 13 -18 12 -20", "stdout": "5" }, { "stdin": "1 2 4 8 9", "stdout": "3" } ]
695
Write a program that reads two tuples and checks if each element of the second tuple is greater than its corresponding element in the first tuple. The program should: 1. Read two tuples from input, where each tuple contains comma-separated integers 2. Check if each element of the second tuple is greater than its corr...
[ { "stdin": "10, 4, 5\n13, 5, 18", "stdout": "True" }, { "stdin": "1, 2, 3\n2, 1, 4", "stdout": "False" }, { "stdin": "4, 5, 6\n5, 6, 7", "stdout": "True" } ]
689
Write a program to find the minimum number of jumps needed to reach the end of an array for a given array of integers, where each element represents the maximum number of steps that can be made forward from that element. The program should: 1. Read the array size n from the first line of input 2. Read the array of n i...
[ { "stdin": "6\n1 3 6 1 0 9", "stdout": "3" }, { "stdin": "11\n1 3 5 8 9 2 6 7 6 8 9", "stdout": "3" }, { "stdin": "11\n1 1 1 1 1 1 1 1 1 1 1", "stdout": "10" } ]
691
Write a program that groups the 1st elements on the basis of 2nd elements in the given tuple list. The program should read a list of tuples from standard input, where each tuple contains two integers. It should group the first elements (indices 0) based on their corresponding second elements (indices 1), and output th...
[ { "stdin": "[(6, 5), (2, 7), (2, 5), (8, 7), (9, 8), (3, 7)]", "stdout": "{5: [6, 2], 7: [2, 8, 3], 8: [9]}" }, { "stdin": "[(7, 6), (3, 8), (3, 6), (9, 8), (10, 9), (4, 8)]", "stdout": "{6: [7, 3], 8: [3, 9, 4], 9: [10]}" }, { "stdin": "[(8, 7), (4, 9), (4, 7), (10, 9), (11, 10), (5, 9)...
677
Write a program that checks if three given angles form a valid triangle. A valid triangle has angles that sum to exactly 180 degrees. The program should read three integers representing angles and output "True" if they form a valid triangle, or "False" otherwise.
[ { "stdin": "60 50 90", "stdout": "False" }, { "stdin": "45 75 60", "stdout": "True" }, { "stdin": "30 50 100", "stdout": "True" } ]
696
Write a program to zip two given lists of lists. The program should read two lists of lists from standard input (in JSON format), concatenate corresponding elements from each list together, and output the result to standard output (also in JSON format). For example: - Input: Two lists `[[1, 3], [5, 7], [9, 11]]` and ...
[ { "stdin": "[[1, 3], [5, 7], [9, 11]]\n[[2, 4], [6, 8], [10, 12, 14]]", "stdout": "[[1, 3, 2, 4], [5, 7, 6, 8], [9, 11, 10, 12, 14]]" }, { "stdin": "[[1, 2], [3, 4], [5, 6]]\n[[7, 8], [9, 10], [11, 12]]", "stdout": "[[1, 2, 7, 8], [3, 4, 9, 10], [5, 6, 11, 12]]" }, { "stdin": "[[\"a\", \...
699
Write a program that finds the minimum number of swaps required to convert one binary string to another. The program should: - Read two binary strings from standard input (one per line) - Calculate the minimum number of swaps needed to convert the first string to the second string - Output the result: either the minim...
[ { "stdin": "1101\n1110", "stdout": "1" }, { "stdin": "1111\n0100", "stdout": "Not Possible" }, { "stdin": "1110000\n0001101", "stdout": "3" } ]
694
Write a program that extracts unique values from the given dictionary values. The program reads a dictionary from standard input, where the dictionary has string keys and list values containing integers. It should extract all unique integers from all the lists in the dictionary and output them in sorted order. Input:...
[ { "stdin": "{\"msm\": [5, 6, 7, 8], \"is\": [10, 11, 7, 5], \"best\": [6, 12, 10, 8], \"for\": [1, 2, 5]}", "stdout": "[1, 2, 5, 6, 7, 8, 10, 11, 12]" }, { "stdin": "{\"Built\": [7, 1, 9, 4], \"for\": [11, 21, 36, 14, 9], \"ISP\": [4, 1, 21, 39, 47], \"TV\": [1, 32, 38]}", "stdout": "[1, 4, 7, 9...
701
Write a program to find the equilibrium index of a given array. An equilibrium index of an array is an index such that the sum of elements at lower indices is equal to the sum of elements at higher indices. If no such index exists, return -1. Input: A single line containing space-separated integers representing the a...
[ { "stdin": "1 2 3 4 1 2 3", "stdout": "3" }, { "stdin": "-7 1 5 2 -4 3 0", "stdout": "3" }, { "stdin": "1 2 3", "stdout": "-1" } ]
703
Write a program that checks whether a given key is present in a dictionary. The program should: 1. Read a dictionary from the first line of input (in Python dictionary literal format) 2. Read a key to search for from the second line of input 3. Output "True" if the key is present in the dictionary, "False" otherwise
[ { "stdin": "{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}\n5", "stdout": "True" }, { "stdin": "{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}\n6", "stdout": "True" }, { "stdin": "{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}\n10", "stdout": "False" } ]
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
151