"{\"inputs\":\"Count all possible strings that can be generated by placing spaces | C program to implement the above approach ; Function to count the number of strings that can be generated by placing spaces between pair of adjacent characters ; Length of the string ; Count of positions for spaces ; Count of possible strings ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\n#include \\nlong long int countNumberOfStrings ( char * s ) { int length = strlen ( s ) ; int n = length - 1 ; long long int count = pow ( 2 , n ) ; return count ; } int main ( ) { char S [ ] = \\\" ABCD \\\" ; printf ( \\\" % lld \\\" , countNumberOfStrings ( S ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of ways to split a binary number such that every part is divisible by 2 | C ++ implementation of the approach ; Function to return the required count ; If the splitting is not possible ; To store the count of zeroes ; Counting the number of zeroes ; Return the final answer ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; #define maxN 20\\n#define maxM 64\\nint cntSplits ( string s ) { if ( s [ s . size ( ) - 1 ] == '1' ) return 0 ; int c_zero = 0 ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) c_zero += ( s [ i ] == '0' ) ; return ( int ) pow ( 2 , c_zero - 1 ) ; } int main ( ) { string s = \\\"10010\\\" ; cout << cntSplits ( s ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum Manhattan distance between a distinct pair from N coordinates | Python3 program for the above approach ; Function to calculate the maximum Manhattan distance ; Stores the maximum distance ; Find Manhattan distance using the formula | x1 - x2 | + | y1 - y2 | ; Updating the maximum ; Driver code ; Given co - ordinates ; Function call\\\"\\nSolution in Python:\",\"targets\":\"import sys\\ndef MaxDist ( A , N ) :\\n\\tmaximum = - sys . maxsize\\n\\tfor i in range ( N ) :\\n\\t\\tsum = 0\\n\\t\\tfor j in range ( i + 1 , N ) :\\n\\t\\t\\tSum = ( abs ( A [ i ] [ 0 ] - A [ j ] [ 0 ] ) + abs ( A [ i ] [ 1 ] - A [ j ] [ 1 ] ) )\\n\\t\\t\\tmaximum = max ( maximum , Sum )\\n\\tprint ( maximum )\\nN = 3\\nA = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 3 , 4 ] ]\\nMaxDist ( A , N )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Matrix Chain Multiplication | DP | A naive recursive implementation that simply follows the above optimal substructure property ; Matrix Ai has dimension p [ i - 1 ] x p [ i ] for i = 1. . n ; place parenthesis at different places between first and last matrix , recursively calculate count of multiplications for each parenthesis placement and return the minimum count ; Return minimum count ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nint MatrixChainOrder ( int p [ ] , int i , int j ) { if ( i == j ) return 0 ; int k ; int min = INT_MAX ; int count ; for ( k = i ; k < j ; k ++ ) { count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ; if ( count < min ) min = count ; } return min ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 3 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Minimum \u2581 number \u2581 of \u2581 multiplications \u2581 is \u2581 % d \u2581 \\\" , MatrixChainOrder ( arr , 1 , n - 1 ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find nth number that contains the digit k or divisible by k . | Function for checking if digit k is in n or not ; finding remainder ; if digit found ; Function for finding nth number ; since k is the first which satisfy the criteria , so consider it in count making count = 1 and starting from i = k + 1 ; checking that the number contain k digit or divisible by k ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function checkdigit ( $ n , $ k ) { while ( $ n ) { $ rem = $ n % 10 ; if ( $ rem == $ k ) return 1 ; $ n = $ n \\/ 10 ; } return 0 ; } function findNthNumber ( $ n , $ k ) { for ( $ i = $ k + 1 , $ count = 1 ; $ count < $ n ; $ i ++ ) { if ( checkdigit ( $ i , $ k ) || ( $ i % $ k == 0 ) ) $ count ++ ; if ( $ count == $ n ) return $ i ; } return -1 ; } $ n = 10 ; $ k = 2 ; echo findNthNumber ( $ n , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Remove minimum numbers from the array to get minimum OR value | C ++ implementation of the approach ; Function to return the minimum deletions to get minimum OR ; To store the minimum element ; Find the minimum element from the array ; To store the frequency of the minimum element ; Find the frequency of the minimum element ; Return the final answer ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int findMinDel ( int * arr , int n ) { int min_num = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) min_num = min ( arr [ i ] , min_num ) ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] == min_num ) cnt ++ ; return n - cnt ; } int main ( ) { int arr [ ] = { 3 , 3 , 2 } ; int n = sizeof ( arr ) \\/ sizeof ( int ) ; cout << findMinDel ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Search an element in a sorted and rotated array with duplicates | C # implementation of the approach ; Function to return the index of the key in arr [ l . . h ] if the key is present otherwise return - 1 ; The tricky case , just update left and right ; If arr [ l ... mid ] is sorted ; As this subarray is sorted , we can quickly check if key lies in any of the halves ; If key does not lie in the first half subarray then divide the other half into two subarrays such that we can quickly check if key lies in the other half ; If arr [ l . . mid ] first subarray is not sorted then arr [ mid ... h ] must be sorted subarray ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int search ( int [ ] arr , int l , int h , int key ) { if ( l > h ) return - 1 ; int mid = ( l + h ) \\/ 2 ; if ( arr [ mid ] == key ) return mid ; if ( ( arr [ l ] == arr [ mid ] ) && ( arr [ h ] == arr [ mid ] ) ) { ++ l ; -- h ; return search ( arr , l , h , key ) } if ( arr [ l ] <= arr [ mid ] ) { if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ; return search ( arr , mid + 1 , h , key ) ; } if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ; return search ( arr , l , mid - 1 , key ) ; } public static void Main ( ) { int [ ] arr = { 3 , 3 , 1 , 2 , 3 , 3 } ; int n = arr . Length ; int key = 3 ; Console . WriteLine ( search ( arr , 0 , n - 1 , key ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Number of coloured 0 's in an N | Function to return the count of coloured 0 s in an n - level hexagon ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def count ( n ) :\\n\\treturn n * ( 3 * n - 1 ) \\/\\/ 2 ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tn = 3 ;\\n\\tprint ( count ( n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimize number of cuts required to break N length stick into N unit length sticks | Python3 program to find minimum time required to split a stick of N length into unit pieces ; Function to return the minimum time required to split stick of N into length into unit pieces ; Return the minimum unit of time required ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"import math\\ndef min_time_to_cut ( N ) :\\n\\tif ( N == 0 ) :\\n\\t\\treturn 0\\n\\treturn int ( math . log2 ( N ) ) + 1\\nN = 100\\nprint ( min_time_to_cut ( N ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Permutation Coefficient | Returns value of Permutation Coefficient P ( n , k ) ; base case ; Calculate value factorials up to n ; P ( n , k ) = n ! \\/ ( n - k ) ! ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def permutationCoeff ( n , k ) :\\n\\tfact = [ 0 for i in range ( n + 1 ) ]\\n\\tfact [ 0 ] = 1\\n\\tfor i in range ( 1 , n + 1 ) :\\n\\t\\tfact [ i ] = i * fact [ i - 1 ]\\n\\treturn int ( fact [ n ] \\/ fact [ n - k ] )\\nn = 10\\nk = 2\\nprint ( \\\" Value \u2581 of \u2581 P ( \\\" , n , \\\" , \u2581 \\\" , k , \\\" ) \u2581 is \u2581 \\\" , permutationCoeff ( n , k ) , sep = \\\" \\\" )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find a Symmetric matrix of order N that contain integers from 0 to N | C ++ implementation of the approach ; Function to generate the required matrix ; Form cyclic array of elements 1 to n - 1 ; Store initial array into final array ; Fill the last row and column with 0 's ; Swap 0 and the number present at the current indexed row ; Also make changes in the last row with the number we swapped ; Print the final array ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void solve ( long long n ) { long long initial_array [ n - 1 ] [ n - 1 ] , final_array [ n ] [ n ] ; for ( long long i = 0 ; i < n - 1 ; ++ i ) initial_array [ 0 ] [ i ] = i + 1 ; for ( long long i = 1 ; i < n - 1 ; ++ i ) for ( long long j = 0 ; j < n - 1 ; ++ j ) initial_array [ i ] [ j ] = initial_array [ i - 1 ] [ ( j + 1 ) % ( n - 1 ) ] ; for ( long long i = 0 ; i < n - 1 ; ++ i ) for ( long long j = 0 ; j < n - 1 ; ++ j ) final_array [ i ] [ j ] = initial_array [ i ] [ j ] ; for ( long long i = 0 ; i < n ; ++ i ) final_array [ i ] [ n - 1 ] = final_array [ n - 1 ] [ i ] = 0 ; for ( long long i = 0 ; i < n ; ++ i ) { long long t0 = final_array [ i ] [ i ] ; long long t1 = final_array [ i ] [ n - 1 ] ; swap ( final_array [ i ] [ i ] , final_array [ i ] [ n - 1 ] ) ; final_array [ n - 1 ] [ i ] = t0 ; } for ( long long i = 0 ; i < n ; ++ i ) { for ( long long j = 0 ; j < n ; ++ j ) cout << final_array [ i ] [ j ] << \\\" \u2581 \\\" ; cout << endl ; } } int main ( ) { long long n = 5 ; solve ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if all substrings of length K of a Binary String has equal count of 0 s and 1 s | Function to check if the substring of length K has equal 0 and 1 ; Traverse the string ; Check if every K - th character is the same or not ; Traverse substring of length K ; If current character is 0 ; Increment count ; Otherwise ; Decrement count ; Check for equal 0 s and 1 s ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def check ( s , k ) :\\n\\tn = len ( s )\\n\\tfor i in range ( k ) :\\n\\t\\tfor j in range ( i , n , k ) :\\n\\t\\t\\tif ( s [ i ] != s [ j ] ) :\\n\\t\\t\\t\\treturn False\\n\\tc = 0\\n\\tfor i in range ( k ) :\\n\\t\\tif ( s [ i ] == '0' ) :\\n\\t\\t\\tc += 1\\n\\t\\telse :\\n\\t\\t\\tc -= 1\\n\\tif ( c == 0 ) :\\n\\t\\treturn True\\n\\telse :\\n\\t\\treturn False\\ns = \\\"101010\\\"\\nk = 2\\nif ( check ( s , k ) != 0 ) :\\n\\tprint ( \\\" Yes \\\" )\\nelse :\\n\\tprint ( \\\" No \\\" )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if a string can be formed from another string using given constraints | Function to check if S2 can be formed of S1 ; Length of Strings ; hash - table to store count ; Store count of each character ; Traverse and check for every character ; If the character of s2 is present in s1 ; If the character of s2 is not present in S1 , then check if previous two ASCII characters are present in S1 ; Driver Code ; Calling function to check\\\"\\nSolution in Javascript:\",\"targets\":\"function check ( S1 , S2 ) { var n1 = S1 . length ; var n2 = S2 . length ; var mp = { } ; for ( var i = 0 ; i < n1 ; i ++ ) { if ( mp . hasOwnProperty ( S1 [ i ] ) ) { mp [ S1 [ i ] ] = mp [ S1 [ i ] ] + 1 ; } else { mp [ S1 [ i ] ] = 1 ; } } for ( var i = 0 ; i < n2 ; i ++ ) { if ( mp . hasOwnProperty ( S2 [ i ] ) ) { mp [ S2 [ i ] ] = mp [ S2 [ i ] ] - 1 ; } else if ( mp . hasOwnProperty ( String . fromCharCode ( S2 [ i ] . charCodeAt ( 0 ) - 1 ) ) && mp . hasOwnProperty ( String . fromCharCode ( S2 [ i ] . charCodeAt ( 0 ) - 2 ) ) ) { mp [ String . fromCharCode ( S2 [ i ] . charCodeAt ( 0 ) - 1 ) ] = mp [ String . fromCharCode ( S2 [ i ] . charCodeAt ( 0 ) - 1 ) ] - 1 ; mp [ String . fromCharCode ( S2 [ i ] . charCodeAt ( 0 ) - 2 ) ] = mp [ String . fromCharCode ( S2 [ i ] . charCodeAt ( 0 ) - 2 ) ] - 1 ; } else { return false ; } } return true ; } var S1 = \\\" \\\" ; var S2 = \\\" \\\" ; if ( check ( S1 , S2 ) ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of points to be removed to get remaining points on one side of axis | Function to find the minimum number of points ; Number of points on the left of Y - axis . ; Number of points on the right of Y - axis . ; Number of points above X - axis . ; Number of points below X - axis . ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function findmin ( p , n ) { let a = 0 , b = 0 , c = 0 , d = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( p [ i ] [ 0 ] <= 0 ) a ++ ; else if ( p [ i ] [ 0 ] >= 0 ) b ++ ; if ( p [ i ] [ 1 ] >= 0 ) c ++ ; else if ( p [ i ] [ 1 ] <= 0 ) d ++ ; } return Math . min ( Math . min ( a , b ) , Math . min ( c , d ) ) ; } let p = [ [ 1 , 1 ] , [ 2 , 2 ] , [ - 1 , - 1 ] , [ - 2 , 2 ] ] let n = p . length ; document . write ( findmin ( p , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count pairs of parentheses sequences such that parentheses are balanced | Function to count the number of pairs ; Hashing function to count the opening and closing brackets ; Traverse for all bracket sequences ; Get the string ; Counts the opening and closing required ; Traverse in the string ; If it is a opening bracket ; Closing bracket ; If openings are there , then close it ; Else increase count of closing ; If requirements of openings are there and no closing ; If requirements of closing are there and no opening ; Perfect ; Divide by two since two perfect makes one pair ; Traverse in the open and find corresponding minimum ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function countPairs ( bracks , num ) { let open = new Map ( ) ; let close = new Map ( ) ; let cnt = 0 ; for ( let i = 0 ; i < num ; i ++ ) { let s = bracks [ i ] ; let l = s . length ; let op = 0 , cl = 0 ; for ( let j = 0 ; j < l ; j ++ ) { if ( s [ j ] == ' ' ) op ++ ; else { if ( op != 0 ) op -- ; else cl ++ ; } } if ( op != 0 && cl == 0 ) open . set ( op , open . get ( op ) == null ? 1 : open . get ( op ) + 1 ) ; if ( cl != 0 && op == 0 ) close . set ( cl , close . get ( cl ) == null ? 1 : close . get ( cl ) + 1 ) ; if ( op == 0 && cl == 0 ) cnt ++ ; } cnt \\/= 2 ; for ( let [ key , value ] of open . entries ( ) ) cnt += Math . min ( value , close . get ( value ) ) ; return cnt ; } let bracks = [ \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" ] ; let num = bracks . length ; document . write ( countPairs ( bracks , num ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"Multiply two integers without using multiplication , division and bitwise operators , and no loops | ; function to multiply two numbers x and y ; 0 multiplied with anything gives 0 ; Add x one by one ; the case where y is negative ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint multiply ( int x , int y ) { if ( y == 0 ) return 0 ; if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ; if ( y < 0 ) return - multiply ( x , - y ) ; } int main ( ) { printf ( \\\" % d \\\" , multiply ( 5 , -11 ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Sort 3 Integers without using if condition or using only max ( ) function | PHP program to print three numbers in sorted order using max function ; Find maximum element ; Find minimum element ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function printSorted ( $ a , $ b , $ c ) { $ get_max = max ( $ a , max ( $ b , $ c ) ) ; $ get_min = - max ( - $ a , max ( - $ b , - $ c ) ) ; $ get_mid = ( $ a + $ b + $ c ) - ( $ get_max + $ get_min ) ; echo $ get_min , \\\" \\\" \u2581 , \u2581 $ get _ mid , \u2581 \\\" \\\" } $ a = 4 ; $ b = 1 ; $ c = 9 ; printSorted ( $ a , $ b , $ c ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Dynamic Programming | High | A naive recursive C program to find maximum tasks . ; Returns the maximum among the 2 numbers ; Returns maximum amount of task that can be done till day n ; If n is less than equal to 0 , then no solution exists ; Determines which task to choose on day n , then returns the maximum till that day ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint max ( int x , int y ) { return ( x > y ? x : y ) ; } int maxTasks ( int high [ ] , int low [ ] , int n ) { if ( n <= 0 ) return 0 ; return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ; } int main ( ) { int n = 5 ; int high [ ] = { 3 , 6 , 8 , 7 , 6 } ; int low [ ] = { 1 , 5 , 4 , 5 , 3 } ; printf ( \\\" % dn \\\" , maxTasks ( high , low , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Length of the longest subsegment which is UpDown after inserting atmost one integer | Function to recursively fill the dp array ; If f ( i , state ) is already calculated then return the value ; Calculate f ( i , state ) according to the recurrence relation and store in dp [ ] [ ] ; Function that calls the resucrsive function to fill the dp array and then returns the result ; dp [ ] [ ] array for storing result of f ( i , 1 ) and f ( 1 , 2 ) ; Populating the array dp [ ] with - 1 ; Make sure that longest UD and DU sequence starting at each index is calculated ; Assume the answer to be - 1 This value will only increase ; y is the length of the longest UD sequence starting at i ; If length is even then add an integer and then a DU sequence starting at i + y ; If length is odd then add an integer and then a UD sequence starting at i + y ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function f ( i , state , A , dp , N ) { if ( i >= N ) return 0 ; else if ( dp [ i ] [ state ] != - 1 ) { return dp [ i ] [ state ] ; } else { if ( i == N - 1 ) dp [ i ] [ state ] = 1 ; else if ( state == 1 && A [ i ] > A [ i + 1 ] ) dp [ i ] [ state ] = 1 ; else if ( state == 2 && A [ i ] < A [ i + 1 ] ) dp [ i ] [ state ] = 1 ; else if ( state == 1 && A [ i ] <= A [ i + 1 ] ) dp [ i ] [ state ] = 1 + f ( i + 1 , 2 , A , dp , N ) ; else if ( state == 2 && A [ i ] >= A [ i + 1 ] ) dp [ i ] [ state ] = 1 + f ( i + 1 , 1 , A , dp , N ) ; return dp [ i ] [ state ] ; } } function maxLenSeq ( A , N ) { let i , j , tmp , y , ans ; let dp = new Array ( 1000 ) ; for ( i = 0 ; i < 1000 ; i ++ ) { dp [ i ] = new Array ( 3 ) ; for ( j = 0 ; j < 3 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } for ( i = 0 ; i < N ; i ++ ) { tmp = f ( i , 1 , A , dp , N ) ; tmp = f ( i , 2 , A , dp , N ) ; } ans = - 1 ; for ( i = 0 ; i < N ; i ++ ) { y = dp [ i ] [ 1 ] ; if ( i + y >= N ) ans = Math . max ( ans , dp [ i ] [ 1 ] + 1 ) ; else if ( y % 2 == 0 ) { ans = Math . max ( ans , dp [ i ] [ 1 ] + 1 + dp [ i + y ] [ 2 ] ) ; } else if ( y % 2 == 1 ) { ans = Math . max ( ans , dp [ i ] [ 1 ] + 1 + dp [ i + y ] [ 1 ] ) ; } } return ans ; } let A = [ 1 , 10 , 3 , 20 , 25 , 24 ] ; let n = A . length ; document . write ( maxLenSeq ( A , n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Number from a given range that requires Kth smallest number of steps to get reduced to 1 | C ++ program for the above approach ; Function to count the number of steps required to reduce val to 1 by the given operations ; Base Case ; If val is even , divide by 2 ; Otherwise , multiply it by 3 and increment by 1 ; Function to find Kth smallest count of steps required for numbers from the range [ L , R ] ; Stores numbers and their respective count of steps ; Count the number of steps for all numbers from the range [ L , R ] ; Insert in the vector ; Sort the vector in ascending order w . r . t . to power value ; Print the K - th smallest number ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; #define ll long long int\\nvector < ll > v ( 1000000 , -1 ) ; ll power_value ( ll val ) { if ( val == 1 ) return 0 ; if ( val % 2 == 0 ) { v [ val ] = power_value ( val \\/ 2 ) + 1 ; return v [ val ] ; } else { ll temp = val * 3 ; temp ++ ; v [ val ] = power_value ( temp ) + 1 ; return v [ val ] ; } } ll getKthNumber ( int l , int r , int k ) { vector < pair < ll , ll > > ans ; for ( ll i = l ; i <= r ; i ++ ) { if ( v [ i ] == -1 ) power_value ( i ) ; } ll j = 0 ; for ( ll i = l ; i <= r ; i ++ ) { ans . push_back ( make_pair ( v [ i ] , i ) ) ; j ++ ; } sort ( ans . begin ( ) , ans . end ( ) ) ; cout << ans [ k - 1 ] . second ; } int main ( ) { int L = 7 , R = 10 , K = 4 ; getKthNumber ( L , R , K ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Print indices of array elements whose removal makes the sum of odd and even | C ++ program to implement the above approach ; Function to find indices of array elements whose removal makes the sum of odd and even indexed array elements equal ; Stores size of array ; Store prefix sum of odd index array elements ; Store prefix sum of even index array elements ; Update even [ 0 ] ; Traverse the given array ; Update odd [ i ] ; Update even [ i ] ; If the current index is an even number ; Update even [ i ] ; If the current index is an odd number ; Update odd [ i ] ; Check if at least one index found or not that satisfies the condition ; Store odd indices sum by removing 0 - th index ; Store even indices sum by removing 0 - th index ; If p and q are equal ; Traverse the array arr [ ] ; If i is an even number ; Update p by removing the i - th element ; Update q by removing the i - th element ; Update q by removing the i - th element ; Update p by removing the i - th element ; If odd index values sum is equal to even index values sum ; Set the find variable ; Print the current index ; If no index found ; Print not possible ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void removeIndicesToMakeSumEqual ( vector < int > & arr ) { int N = arr . size ( ) ; vector < int > odd ( N , 0 ) ; vector < int > even ( N , 0 ) ; even [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { odd [ i ] = odd [ i - 1 ] ; even [ i ] = even [ i - 1 ] ; if ( i % 2 == 0 ) { even [ i ] += arr [ i ] ; } else { odd [ i ] += arr [ i ] ; } } bool find = 0 ; int p = odd [ N - 1 ] ; int q = even [ N - 1 ] - arr [ 0 ] ; if ( p == q ) { cout << \\\"0 \u2581 \\\" ; find = 1 ; } for ( int i = 1 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { p = even [ N - 1 ] - even [ i - 1 ] - arr [ i ] + odd [ i - 1 ] ; q = odd [ N - 1 ] - odd [ i - 1 ] + even [ i - 1 ] ; } else { q = odd [ N - 1 ] - odd [ i - 1 ] - arr [ i ] + even [ i - 1 ] ; p = even [ N - 1 ] - even [ i - 1 ] + odd [ i - 1 ] ; } if ( p == q ) { find = 1 ; cout << i << \\\" \u2581 \\\" ; } } if ( ! find ) { cout << -1 ; } } int main ( ) { vector < int > arr = { 4 , 1 , 6 , 2 } ; removeIndicesToMakeSumEqual ( arr ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Given a HUGE number check if it 's a power of two. | C # program to find whether a number is power of 2 or not ; returns 1 when str is power of 2 return 0 when str is not a power of 2 ; sum stores the intermediate dividend while dividing . ; if the input is \\\"1\\\" then return 0 because 2 ^ k = 1 where k >= 1 and here k = 0 ; Divide the number until it gets reduced to 1 if we are successfully able to reduce the number to 1 it means input string is power of two if in between an odd number appears at the end it means string is not divisible by two hence not a power of 2. ; if the last digit is odd then string is not divisible by 2 hence not a power of two return 0. ; divide the whole string by 2. i is used to track index in current number . j is used to track index for next iteration . ; if num < 2 then we have to take another digit to the right of A [ i ] to make it bigger than A [ i ] . E . g . 214 \\/ 2 -- > 107 ; if it 's not the first index. E.g 214 then we have to include 0. ; for eg . \\\"124\\\" we will not write 064 so if it is the first index just ignore ; After every division by 2 the length of string is changed . ; if the string reaches to 1 then the str is a power of 2. ; Driver code .\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int isPowerOf2 ( string s ) { char [ ] str = s . ToCharArray ( ) ; int len_str = str . Length ; int num = 0 ; if ( len_str == 1 && str [ len_str - 1 ] == '1' ) return 0 ; while ( len_str != 1 str [ len_str - 1 ] != '1' ) { if ( ( str [ len_str - 1 ] - '0' ) % 2 == 1 ) return 0 ; int j = 0 ; for ( int i = 0 ; i < len_str ; i ++ ) { num = num * 10 + ( int ) str [ i ] - ( int ) '0' ; if ( num < 2 ) { if ( i != 0 ) str [ j ++ ] = '0' ; continue ; } str [ j ++ ] = ( char ) ( ( int ) ( num \\/ 2 ) + ( int ) '0' ) ; num = ( num ) - ( num \\/ 2 ) * 2 ; } str [ j ] = ' \\\\0' ; len_str = j ; } return 1 ; } static void Main ( ) { string str1 = \\\"124684622466842024680246842024662202000002\\\" ; string str2 = \\\"1\\\" ; string str3 = \\\"128\\\" ; Console . Write ( isPowerOf2 ( str1 ) + \\\" \\n \\\" + isPowerOf2 ( str2 ) + \\\" \\n \\\" + isPowerOf2 ( str3 ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count number of triplets with product equal to given number | Set 2 | C ++ implementation of above approach ; Function to count such triplets ; Sort the array ; three pointer technique ; Calculate the product of a triplet ; Check if that product is greater than m , decrement mid ; Check if that product is smaller than m , increment start ; Check if that product is equal to m , decrement mid , increment start and increment the count of pairs ; Drivers code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int countTriplets ( int arr [ ] , int n , int m ) { int count = 0 ; sort ( arr , arr + n ) ; int end , start , mid ; for ( end = n - 1 ; end >= 2 ; end -- ) { int start = 0 , mid = end - 1 ; while ( start < mid ) { long int prod = arr [ end ] * arr [ start ] * arr [ mid ] ; if ( prod > m ) mid -- ; else if ( prod < m ) start ++ ; else if ( prod == m ) { count ++ ; mid -- ; start ++ ; } } } return count ; } int main ( ) { int arr [ ] = { 1 , 1 , 1 , 1 , 1 , 1 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int m = 1 ; cout << countTriplets ( arr , n , m ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Number of arrays of size N whose elements are positive integers and sum is K | CPP Program to find the number of arrays of size N whose elements are positive integers and sum is K ; Return nCr ; C [ 0 ] = 1 ; nC0 is 1 ; Compute next row of pascal triangle using the previous row ; Return the number of array that can be formed of size n and sum equals to k . ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int binomialCoeff ( int n , int k ) { int C [ k + 1 ] ; memset ( C , 0 , sizeof ( C ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } int countArray ( int N , int K ) { return binomialCoeff ( K - 1 , N - 1 ) ; } int main ( ) { int N = 2 , K = 3 ; cout << countArray ( N , K ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find minimum adjustment cost of an array | PHP program to find minimum adjustment cost of an array ; Function to find minimum adjustment cost of an array ; dp [ i ] [ j ] stores minimal adjustment cost on changing A [ i ] to j ; handle first element of array separately ; do for rest elements of the array ; replace A [ i ] to j and calculate minimal adjustment cost dp [ i ] [ j ] ; initialize minimal adjustment cost to INT_MAX ; consider all k such that k >= max ( j - target , 0 ) and k <= min ( M , j + target ) and take minimum ; return minimum value from last row of dp table ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php $ M = 100 ; function minAdjustmentCost ( $ A , $ n , $ target ) { global $ M ; $ dp = array ( array ( ) ) ; for ( $ j = 0 ; $ j <= $ M ; $ j ++ ) $ dp [ 0 ] [ $ j ] = abs ( $ j - $ A [ 0 ] ) ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { for ( $ j = 0 ; $ j <= $ M ; $ j ++ ) { $ dp [ $ i ] [ $ j ] = PHP_INT_MAX ; for ( $ k = max ( $ j - $ target , 0 ) ; $ k <= min ( $ M , $ j + $ target ) ; $ k ++ ) $ dp [ $ i ] [ $ j ] = min ( $ dp [ $ i ] [ $ j ] , $ dp [ $ i - 1 ] [ $ k ] + abs ( $ A [ $ i ] - $ j ) ) ; } } $ res = PHP_INT_MAX ; for ( $ j = 0 ; $ j <= $ M ; $ j ++ ) $ res = min ( $ res , $ dp [ $ n - 1 ] [ $ j ] ) ; return $ res ; } $ arr = array ( 55 , 77 , 52 , 61 , 39 , 6 , 25 , 60 , 49 , 47 ) ; $ n = count ( $ arr ) ; $ target = 10 ; echo \\\" Minimum \u2581 adjustment \u2581 cost \u2581 is \u2581 \\\" , minAdjustmentCost ( $ arr , $ n , $ target ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the first repeating element in an array of integers | C ++ program to find first repeating element in arr [ ] ; This function prints the first repeating element in arr [ ] ; This will set k = 1 , if any repeating element found ; max = maximum from ( all elements & n ) ; Array a is for storing 1 st time occurence of element initialized by 0 ; Store 1 in array b if element is duplicate initialized by 0 ; Duplicate element found ; storing 1 st occurence of arr [ i ] ; trace array a & find repeating element with min index ; Driver method to test above method\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void printFirstRepeating ( int arr [ ] , int n ) { int k = 0 ; int max = n ; for ( int i = 0 ; i < n ; i ++ ) if ( max < arr [ i ] ) max = arr [ i ] ; int a [ max + 1 ] = { } ; int b [ max + 1 ] = { } ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ arr [ i ] ] ) { b [ arr [ i ] ] = 1 ; k = 1 ; continue ; } else a [ arr [ i ] ] = i ; } if ( k == 0 ) cout << \\\" No \u2581 repeating \u2581 element \u2581 found \\\" << endl ; else { int min = max + 1 ; for ( int i = 0 ; i < max + 1 ; i ++ ) if ( a [ i ] && min > a [ i ] && b [ i ] ) min = a [ i ] ; cout << arr [ min ] ; } cout << endl ; } int main ( ) { int arr [ ] = { 10 , 5 , 3 , 4 , 3 , 5 , 6 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printFirstRepeating ( arr , n ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check whether a number can be represented as sum of K distinct positive integers | Function that returns true if n can be represented as the sum of exactly k distinct positive integers ; If n can be represented as 1 + 2 + 3 + ... + ( k - 1 ) + ( k + x ) ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def solve ( n , k ) :\\n\\tif ( n >= ( k * ( k + 1 ) ) \\/\\/ 2 ) :\\n\\t\\treturn True\\n\\treturn False\\nif __name__ == ' _ _ main _ _ ' :\\n\\tn = 12\\n\\tk = 4\\n\\tif ( solve ( n , k ) ) :\\n\\t\\tprint ( \\\" Yes \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Rearrange array such that sum of same indexed elements is atmost K | Reverse array ; Function to rearrange array such that sum of similar indexed elements does not exceed K ; Sort the array B [ ] in descending order ; If condition fails ; Prlet the array ; Given arrays\\\"\\nSolution in Javascript:\",\"targets\":\"function reverse ( a ) { let i , n = a . length , t ; for ( i = 0 ; i < n \\/ 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } function rearrangeArray ( A , B , N , K ) { B . sort ( ) ; B = reverse ( B ) ; let flag = true ; for ( let i = 0 ; i < N ; i ++ ) { if ( A [ i ] + B [ i ] > K ) { flag = false ; break ; } } if ( ! flag ) { document . write ( \\\" \\\" + \\\" \\\" ) ; } else { for ( let i = 0 ; i < N ; i ++ ) { document . write ( B [ i ] + \\\" \\\" ) ; } } } let A = [ 1 , 2 , 3 , 4 , 2 ] ; let B = [ 1 , 2 , 3 , 1 , 1 ] ; let N = A . length ; let K = 5 ; rearrangeArray ( A , B , N , K ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Toggling k | Java program to toogle k - th bit of a number ; main function\\\"\\nSolution in Java:\",\"targets\":\"class Toggle { static int toggleKthBit ( int n , int k ) { return ( n ^ ( 1 << ( k - 1 ) ) ) ; } public static void main ( String [ ] args ) { int n = 5 , k = 1 ; System . out . println ( toggleKthBit ( n , k ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if N numbers with Even Sum can be selected from a given Array | Function to check if an odd sum can be made using N integers from the array ; Initialize odd and even counts ; Iterate over the array to count the no . of even and odd integers ; If element is odd ; If element is even ; Check if even_freq is more than N ; If odd_freq is odd ; Consider even count of odd ; Calculate even required ; If even count is less than required count ; Calculate even required ; If even count is less than required count ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function checkEvenSum ( arr , N , size ) { var even_freq = 0 , odd_freq = 0 ; for ( var i = 0 ; i < size ; i ++ ) { if ( arr [ i ] & 1 ) odd_freq ++ ; else even_freq ++ ; } if ( even_freq >= N ) return true ; else { if ( odd_freq & 1 ) { var taken = odd_freq - 1 ; var req = N - taken ; if ( even_freq < req ) { return false ; } else return true ; } else { var taken = odd_freq ; var req = N - taken ; if ( even_freq < req ) { return false ; } else return true ; } } return false ; } var arr = [ 9 , 2 , 3 , 4 , 18 , 7 , 7 , 6 ] ; var size = arr . length ; var N = 5 ; if ( checkEvenSum ( arr , N , size ) ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count subarrays having sum modulo K same as the length of the subarray | C # program for the above approach ; Function that counts the subarrays having sum modulo k equal to the length of subarray ; Stores the count of ( pref [ i ] - i ) % k ; Stores the count of subarray ; Stores prefix sum of the array ; Find prefix sum array ; Base Condition ; Remove the index at present after K indices from the current index ; Update the answer for subarrays ending at the i - th index ; Add the calculated value of current index to count ; Print the count of subarrays ; Driver Code ; Given [ ] arr ; Size of the array ; Given K ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void countSubarrays ( int [ ] a , int n , int k ) { Dictionary < int , int > cnt = new Dictionary < int , int > ( ) ; long ans = 0 ; List < int > pref = new List < int > ( ) ; pref . Add ( 0 ) ; for ( int i = 0 ; i < n ; i ++ ) pref . Add ( ( a [ i ] + pref [ i ] ) % k ) ; cnt . Add ( 0 , 1 ) ; for ( int i = 1 ; i <= n ; i ++ ) { int remIdx = i - k ; if ( remIdx >= 0 ) { if ( cnt . ContainsKey ( ( pref [ remIdx ] - remIdx % k + k ) % k ) ) cnt [ ( pref [ remIdx ] - remIdx % k + k ) % k ] = cnt [ ( pref [ remIdx ] - remIdx % k + k ) % k ] - 1 ; else cnt . Add ( ( pref [ remIdx ] - remIdx % k + k ) % k , - 1 ) ; } if ( cnt . ContainsKey ( ( pref [ i ] - i % k + k ) % k ) ) ans += cnt [ ( pref [ i ] - i % k + k ) % k ] ; if ( cnt . ContainsKey ( ( pref [ i ] - i % k + k ) % k ) ) cnt [ ( pref [ i ] - i % k + k ) % k ] = cnt [ ( pref [ i ] - i % k + k ) % k ] + 1 ; else cnt . Add ( ( pref [ i ] - i % k + k ) % k , 1 ) ; } Console . WriteLine ( ans ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 5 , 3 , 1 , 5 } ; int N = arr . Length ; int K = 4 ; countSubarrays ( arr , N , K ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find all the prime numbers of given number of digits | Python 3 implementation of the approach ; Function for Sieve of Eratosthenes ; Function to print all the prime numbers with d digits ; Range to check integers ; For every integer in the range ; If the current integer is prime ; Driver code ; Generate primes\\\"\\nSolution in Python:\",\"targets\":\"from math import sqrt , pow\\nsz = 100005\\nisPrime = [ True for i in range ( sz + 1 ) ]\\ndef sieve ( ) :\\n\\tisPrime [ 0 ] = isPrime [ 1 ] = False\\n\\tfor i in range ( 2 , int ( sqrt ( sz ) ) + 1 , 1 ) :\\n\\t\\tif ( isPrime [ i ] ) :\\n\\t\\t\\tfor j in range ( i * i , sz , i ) :\\n\\t\\t\\t\\tisPrime [ j ] = False\\ndef findPrimesD ( d ) :\\n\\tleft = int ( pow ( 10 , d - 1 ) )\\n\\tright = int ( pow ( 10 , d ) - 1 )\\n\\tfor i in range ( left , right + 1 , 1 ) :\\n\\t\\tif ( isPrime [ i ] ) :\\n\\t\\t\\tprint ( i , end = \\\" \u2581 \\\" )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tsieve ( )\\n\\td = 1\\n\\tfindPrimesD ( d )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Probability of distributing given balls into two halves having equal count of distinct colors | C ++ program for the above approach ; Stores the count of distinct colors in box1 ; Stores the count of distinct colors in box2 ; Function to calculate the required probability ; Calculate factorial from [ 1 , 10 ] ; Assign all distinct balls to second box ; Total number of balls ; Calculate total number of balls ; If K is an odd number ; Total ways of distributing the balls in two equal halves ; Required number of ways ; Return the required probability ; Function to calculate total number of possible distributions which satisfies the given conditions ; If used balls is equal to K \\/ 2 ; If box1 is equal to box2 ; Base condition ; Stores the number of ways of distributing remaining balls without including the current balls in box1 ; Increment box1 by one ; Iterate over the range [ 1 , balls [ i ] ] ; If all the balls goes to box1 , then decrease box2 by one ; Total number of ways of selecting j balls ; Increment res by total number of valid ways of distributing the remaining balls ; Decrement box1 by one ; Increment box2 by 1 ; Function to calculate factorial of N ; Base Case ; Iterate over the range [ 1 , N ] ; Function to calculate NcR ; Driver Code ; Print the result\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; static int box1 = 0 ; static int box2 = 0 ; static int fact [ 11 ] ; double getProbability ( int balls [ ] , int M ) { factorial ( 10 ) ; box2 = M ; int K = 0 ; for ( int i = 0 ; i < M ; i ++ ) K += balls [ i ] ; if ( K % 2 == 1 ) return 0 ; long all = comb ( K , K \\/ 2 ) ; long validPermutation = validPermutations ( K \\/ 2 , balls , 0 , 0 , M ) ; return ( double ) validPermutation \\/ all ; } long validPermutations ( int n , int balls [ ] , int usedBalls , int i , int M ) { if ( usedBalls == n ) { return box1 == box2 ? 1 : 0 ; } if ( i >= M ) return 0 ; long res = validPermutations ( n , balls , usedBalls , i + 1 , M ) ; box1 ++ ; for ( int j = 1 ; j <= balls [ i ] ; j ++ ) { if ( j == balls [ i ] ) box2 -- ; long combinations = comb ( balls [ i ] , j ) ; res += combinations * validPermutations ( n , balls , usedBalls + j , i + 1 , M ) ; } box1 -- ; box2 ++ ; return res ; } void factorial ( int N ) { fact [ 0 ] = 1 ; for ( int i = 1 ; i <= N ; i ++ ) fact [ i ] = fact [ i - 1 ] * i ; } long comb ( int n , int r ) { long res = fact [ n ] \\/ fact [ r ] ; res \\/= fact [ n - r ] ; return res ; } int main ( ) { int arr [ ] = { 2 , 1 , 1 } ; int N = 4 ; int M = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << ( getProbability ( arr , M ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Largest subtree sum for each vertex of given N | C ++ program for the above approach ; Function to perform the DFS Traversal on the given Tree ; To check if v is leaf vertex ; Initialize answer for vertex v ; Traverse adjacency list of v ; Update maximum subtree sum ; If v is leaf ; Function to calculate maximum subtree sum for each vertex ; Stores the adjacency list ; Add Edegs to the list ; Stores largest subtree sum for each vertex ; Calculate answer ; Print the result ; Driver Code ; Given nodes ; Give N edges ; Given values ; Function Call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; #define V 3\\n#define M 2\\nvoid dfs ( int v , int p , vector < int > adj [ ] , int ans [ ] , int vals [ ] ) { bool isLeaf = 1 ; ans [ v ] = INT_MIN ; for ( int u : adj [ v ] ) { if ( u == p ) continue ; isLeaf = 0 ; dfs ( u , v , adj , ans , vals ) ; ans [ v ] = max ( ans [ u ] + vals [ v ] , max ( ans [ u ] , vals [ u ] ) ) ; } if ( isLeaf ) { ans [ v ] = vals [ v ] ; } } void printAnswer ( int n , int edges [ V ] [ M ] , int values [ ] ) { vector < int > adj [ n ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int u = edges [ i ] [ 0 ] - 1 ; int v = edges [ i ] [ 1 ] - 1 ; adj [ u ] . push_back ( v ) ; adj [ v ] . push_back ( u ) ; } int ans [ n ] ; dfs ( 0 , -1 , adj , ans , values ) ; for ( auto x : ans ) { cout << x << \\\" \u2581 \\\" ; } } int main ( ) { int N = 4 ; int edges [ V ] [ M ] = { { 1 , 2 } , { 1 , 3 } , { 3 , 4 } } ; int values [ ] = { 1 , -1 , 0 , 1 } ; printAnswer ( N , edges , values ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"An efficient way to check whether n | Returns true if n - th Fibonacci number is multiple of 10. ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function isMultipleOf10 ( $ n ) { return ( $ n % 15 == 0 ) ; } $ n = 30 ; if ( isMultipleOf10 ( $ n ) ) echo \\\" Yes \\n \\\" ; else echo \\\" No \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Find all divisors of a natural number | Set 2 | A O ( sqrt ( n ) ) program that prints all divisors in sorted order ; function to print the divisors ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nvoid printDivisors ( int n ) { int i ; for ( i = 1 ; i * i < n ; i ++ ) { if ( n % i == 0 ) printf ( \\\" % d \u2581 \\\" , i ) ; } if ( i - ( n \\/ i ) == 1 ) { i -- ; } for ( ; i >= 1 ; i -- ) { if ( n % i == 0 ) printf ( \\\" % d \u2581 \\\" , n \\/ i ) ; } } int main ( ) { printf ( \\\" The \u2581 divisors \u2581 of \u2581 100 \u2581 are : \u2581 \\n \\\" ) ; printDivisors ( 100 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximum rods to put horizontally such that no two rods overlap on X coordinate | C ++ program for the above approach ; Function to find the maximum number of rods that can be put horizontally ; Stores the result ; Stores the last occupied point ; Traverse the array arr [ ] ; If the current point can be put on the left side ; Increment the ans by 1 ; Update prev ; Else if the given point can be put on the right side ; Increment the ans by 1 ; Update prev ; Otherwise , ; Update prev ; Return the ans ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int findMaximumPoints ( int N , int X [ ] , int H [ ] ) { int ans = 0 ; int prev = INT_MIN ; for ( int i = 0 ; i < N ; ++ i ) { if ( prev < ( X [ i ] - H [ i ] ) ) { ++ ans ; prev = X [ i ] ; } else if ( i == N - 1 || ( X [ i ] + H [ i ] ) < X [ i + 1 ] ) { ++ ans ; prev = X [ i ] + H [ i ] ; } else { prev = X [ i ] ; } } return ans ; } int main ( ) { int X [ ] = { 1 , 2 , 3 } ; int H [ ] = { 2 , 5 , 5 } ; int N = sizeof ( X ) \\/ sizeof ( X [ 0 ] ) ; cout << findMaximumPoints ( N , X , H ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if N rectangles of equal area can be formed from ( 4 * N ) integers | Java implementation of the approach ; Function to check whether we can make n rectangles of equal area ; Sort the array ; Find the area of any one rectangle ; Check whether we have two equal sides for each rectangle and that area of each rectangle formed is the same ; Update the answer to false if any condition fails ; If possible ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static boolean checkRectangles ( int [ ] arr , int n ) { boolean ans = true ; Arrays . sort ( arr ) ; int area = arr [ 0 ] * arr [ 4 * n - 1 ] ; for ( int i = 0 ; i < 2 * n ; i = i + 2 ) { if ( arr [ i ] != arr [ i + 1 ] arr [ 4 * n - i - 1 ] != arr [ 4 * n - i - 2 ] arr [ i ] * arr [ 4 * n - i - 1 ] != area ) { ans = false ; break ; } } if ( ans ) return true ; return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 8 , 2 , 1 , 2 , 4 , 4 , 8 } ; int n = 2 ; if ( checkRectangles ( arr , n ) ) System . out . print ( \\\" Yes \\\" ) ; else System . out . print ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Efficient program to print all prime factors of a given number | Program to print all prime factors ; A function to print all prime factors of a given number n ; Print the number of 2 s that divide n ; n must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; While i divides n , print i and divide n ; This condition is to handle the case when n is a prime number greater than 2 ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"# include \\n# include \\nvoid primeFactors ( int n ) { while ( n % 2 == 0 ) { printf ( \\\" % d \u2581 \\\" , 2 ) ; n = n \\/ 2 ; } for ( int i = 3 ; i <= sqrt ( n ) ; i = i + 2 ) { while ( n % i == 0 ) { printf ( \\\" % d \u2581 \\\" , i ) ; n = n \\/ i ; } } if ( n > 2 ) printf ( \\\" % d \u2581 \\\" , n ) ; } int main ( ) { int n = 315 ; primeFactors ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Highest power of 2 less than or equal to given number | Javascript program to find highest power of 2 smaller than or equal to n . ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function highestPowerof2 ( n ) { let p = parseInt ( Math . log ( n ) \\/ Math . log ( 2 ) , 10 ) ; return Math . pow ( 2 , p ) ; } let n = 10 ; document . write ( highestPowerof2 ( n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Convert vowels into upper case character in a given string | C ++ program to implement the above approach ; Function to convert vowels into uppercase ; Stores the length of str ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; string conVowUpp ( string & str ) { int N = str . length ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' a ' str [ i ] == ' e ' str [ i ] == ' i ' str [ i ] == ' o ' str [ i ] == ' u ' ) { str [ i ] = str [ i ] - ' a ' + ' A ' ; } } return str ; } int main ( ) { string str = \\\" eutopia \\\" ; cout << conVowUpp ( str ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"One line function for factorial of a number | Java program to find factorial of given number ; single line to find factorial ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int factorial ( int n ) { return ( n == 1 n == 0 ) ? 1 : n * factorial ( n - 1 ) ; } public static void main ( String [ ] args ) { int num = 5 ; System . out . println ( \\\" Factorial \u2581 of \u2581 \\\" + num + \\\" \u2581 is \u2581 \\\" + factorial ( num ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Program to print Spiral Pattern | Create row and col to traverse rows and columns ; Variable to determine the movement r = right , l = left , d = down , u = upper ; Array for matrix ; Assign the value ; switch - case to determine the next index ; If right , go right ; if left , go left ; if up , go up ; if down , go down ; Check if the matrix has reached array boundary ; Add the left size for the next boundary ; If 2 rotations has been made , decrease the size left by 1 ; switch - case to rotate the movement ; if right , rotate to down ; if down , rotate to left ; if left , rotate to up ; if up , rotate to right ; Print the matrix ; Driver Code ; Get the size of size ; Print the Spiral Pattern\\\"\\nSolution in Java:\",\"targets\":\"public class GFG { public static void printSpiral ( int size ) { int row = 0 , col = 0 ; int boundary = size - 1 ; int sizeLeft = size - 1 ; int flag = 1 ; char move = ' r ' ; int matrix [ ] [ ] = new int [ size ] [ size ] ; for ( int i = 1 ; i < size * size + 1 ; i ++ ) { matrix [ row ] [ col ] = i ; switch ( move ) { case ' r ' : col += 1 ; break ; case ' l ' : col -= 1 ; break ; case ' u ' : row -= 1 ; break ; case ' d ' : row += 1 ; break ; } if ( i == boundary ) { boundary += sizeLeft ; if ( flag != 2 ) { flag = 2 ; } else { flag = 1 ; sizeLeft -= 1 ; } switch ( move ) { case ' r ' : move = ' d ' ; break ; case ' d ' : move = ' l ' ; break ; case ' l ' : move = ' u ' ; break ; case ' u ' : move = ' r ' ; break ; } } } for ( row = 0 ; row < size ; row ++ ) { for ( col = 0 ; col < size ; col ++ ) { int n = matrix [ row ] [ col ] ; System . out . print ( ( n < 10 ) ? ( n + \\\" \u2581 \\\" ) : ( n + \\\" \u2581 \\\" ) ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int size = 5 ; printSpiral ( size ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"All unique combinations whose sum equals to K | C # implementation of the approach ; Function to find all unique combination of given elements such that their sum is K ; If a unique combination is found ; For all other combinations ; Check if the sum exceeds K ; Check if it is repeated or not ; Take the element into the combination ; Recursive call ; Remove element from the combination ; Function to find all combination of the given elements ; Sort the given elements ; To store combination ; Driver code ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void unique_combination ( int l , int sum , int K , List < int > local , List < int > A ) { if ( sum == K ) { Console . Write ( \\\" { \\\" ) ; for ( int i = 0 ; i < local . Count ; i ++ ) { if ( i != 0 ) Console . Write ( \\\" \u2581 \\\" ) ; Console . Write ( local [ i ] ) ; if ( i != local . Count - 1 ) Console . Write ( \\\" , \u2581 \\\" ) ; } Console . WriteLine ( \\\" } \\\" ) ; return ; } for ( int i = l ; i < A . Count ; i ++ ) { if ( sum + A [ i ] > K ) continue ; if ( i > l && A [ i ] == A [ i - 1 ] ) continue ; local . Add ( A [ i ] ) ; unique_combination ( i + 1 , sum + A [ i ] , K , local , A ) ; local . RemoveAt ( local . Count - 1 ) ; } } static void Combination ( List < int > A , int K ) { A . Sort ( ) ; List < int > local = new List < int > ( ) ; unique_combination ( 0 , 0 , K , local , A ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 10 , 1 , 2 , 7 , 6 , 1 , 5 } ; List < int > A = new List < int > ( arr ) ; int K = 8 ; Combination ( A , K ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Queries to evaluate the given equation in a range [ L , R ] | Function to obtain the middle index of the range ; Recursive function to get the sum of values in the given range from the array . The following are parameters for this function . st . Pointer to segment tree node . Index of current node in the segment tree ss & se . Starting and ending indexes of the segment represented by current node , i . e . , st [ node ] l & r . Starting and ending indexes of range query ; If the segment of this node lies completely within the given range ; Return maximum in the segment ; If the segment of this node lies outside the given range ; If segment of this node lies partially in the given range ; Function to return the maximum in the range from [ l , r ] ; Check for erroneous input values ; Function to conSegment Tree for the subarray [ ss . . se ] ; For a single element ; Otherwise ; Recur for left subtree ; Recur for right subtree ; Function to conSegment Tree from the given array ; Height of Segment Tree ; Maximum size of Segment Tree ; Allocate memory ; Fill the allocated memory ; Return the constructed Segment Tree ; Driver Code ; Build the Segment Tree from the given array\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function getMid ( s , e ) { return ( s + Math . floor ( ( e - s ) \\/ 2 ) ) ; } function MaxUtil ( st , ss , se , l , r , node ) { if ( l <= ss && r >= se ) return st [ node ] ; if ( se < l ss > r ) return - 1 ; let mid = getMid ( ss , se ) ; return Math . max ( MaxUtil ( st , ss , mid , l , r , 2 * node + 1 ) , MaxUtil ( st , mid + 1 , se , l , r , 2 * node + 2 ) ) ; } function getMax ( st , n , l , r ) { if ( l < 0 r > n - 1 l > r ) { document . write ( \\\" \\\" ) ; return - 1 ; } return MaxUtil ( st , 0 , n - 1 , l , r , 0 ) ; } function constructSTUtil ( arr , ss , se , st , si ) { if ( ss == se ) { st [ si ] = arr [ ss ] ; return arr [ ss ] ; } let mid = getMid ( ss , se ) ; st [ si ] = Math . max ( constructSTUtil ( arr , ss , mid , st , si * 2 + 1 ) , constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 ) ) ; return st [ si ] ; } function constructST ( arr , n ) { let x = ( Math . ceil ( Math . log ( n ) ) ) ; let max_size = 2 * Math . pow ( 2 , x ) - 1 ; let st = Array . from ( { length : max_size } , ( _ , i ) => 0 ) ; constructSTUtil ( arr , 0 , n - 1 , st , 0 ) ; return st ; } let arr = [ 5 , 2 , 3 , 0 ] ; let n = arr . length ; let st = constructST ( arr , n ) ; let Q = [ [ 1 , 3 ] , [ 0 , 2 ] ] ; for ( let i = 0 ; i < Q . length ; i ++ ) { let max = getMax ( st , n , Q [ i ] [ 0 ] , Q [ i ] [ 1 ] ) ; let ok = 0 ; for ( let j = 30 ; j >= 0 ; j -- ) { if ( ( max & ( 1 << j ) ) != 0 ) ok = 1 ; if ( ok <= 0 ) continue ; max |= ( 1 << j ) ; } document . write ( max + \\\" \\\" ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find maximum average subarray of k length | Returns beginning index of maximum average subarray of length ' k ' ; Check if ' k ' is valid ; Create and fill array to store cumulative sum . csum [ i ] stores sum of arr [ 0 ] to arr [ i ] ; Initialize max_sm as sum of first subarray ; Find sum of other subarrays and update max_sum if required . ; Return starting index ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function findMaxAverage ( $ arr , $ n , $ k ) { if ( $ k > $ n ) return -1 ; $ csum = array ( ) ; $ csum [ 0 ] = $ arr [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) $ csum [ $ i ] = $ csum [ $ i - 1 ] + $ arr [ $ i ] ; $ max_sum = $ csum [ $ k - 1 ] ; $ max_end = $ k - 1 ; for ( $ i = $ k ; $ i < $ n ; $ i ++ ) { $ curr_sum = $ csum [ $ i ] - $ csum [ $ i - $ k ] ; if ( $ curr_sum > $ max_sum ) { $ max_sum = $ curr_sum ; $ max_end = $ i ; } } return $ max_end - $ k + 1 ; } $ arr = array ( 1 , 12 , -5 , -6 , 50 , 3 ) ; $ k = 4 ; $ n = count ( $ arr ) ; echo \\\" The \u2581 maximum \u2581 average \u2581 subarray \u2581 of \u2581 \\\" , \\\" length \u2581 \\\" , $ k , \\\" \u2581 begins \u2581 at \u2581 index \u2581 \\\" , findMaxAverage ( $ arr , $ n , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Squared triangular number ( Sum of cubes ) | Function to find if the given number is sum of the cubes of first n natural numbers ; Start adding cubes of the numbers from 1 ; If sum becomes equal to s return n ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findS ( $ s ) { $ sum = 0 ; for ( $ n = 1 ; $ sum < $ s ; $ n ++ ) { $ sum += $ n * $ n * $ n ; if ( $ sum == $ s ) return $ n ; } return -1 ; } $ s = 9 ; $ n = findS ( $ s ) ; if ( $ n == -1 ) echo ( \\\" - 1\\\" ) ; else echo ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"N consecutive ropes problem | C ++ implementation of the approach ; Function to return the minimum cost to connect the given ropes ; dp [ i ] [ j ] = minimum cost in range ( i , j ) sum [ i ] [ j ] = sum of range ( i , j ) ; Initializing the sum table ; Computing minimum cost for all the possible interval ( i , j ) Left range ; Right range ; No cost for a single rope ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int MinCost ( int arr [ ] , int n ) { int dp [ n + 5 ] [ n + 5 ] , sum [ n + 5 ] [ n + 5 ] ; memset ( sum , 0 , sizeof ( 0 ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int k = arr [ i ] ; for ( int j = i ; j < n ; j ++ ) { if ( i == j ) sum [ i ] [ j ] = k ; else { k += arr [ j ] ; sum [ i ] [ j ] = k ; } } } for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = i ; j < n ; j ++ ) { dp [ i ] [ j ] = INT_MAX ; if ( i == j ) dp [ i ] [ j ] = 0 ; else { for ( int k = i ; k < j ; k ++ ) { dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] + sum [ i ] [ j ] ) ; } } } } return dp [ 0 ] [ n - 1 ] ; } int main ( ) { int arr [ ] = { 7 , 6 , 8 , 6 , 1 , 1 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << MinCost ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Partition problem | DP | A dynamic programming based C # program for partition problem ; Returns true if arr [ ] can be partitioned in two subsets of equal sum , otherwise false ; Calculate sum of all elements ; initialize top row as true ; initialize leftmost column , except part [ 0 ] [ 0 ] , as 0 ; Fill the partition table in bottom up manner ; uncomment this part to print table for ( i = 0 ; i <= sum \\/ 2 ; i ++ ) { for ( j = 0 ; j <= n ; j ++ ) printf ( \\\" % 4d \\\" , part [ i ] [ j ] ) ; printf ( \\\" \\\\n \\\" ) ; } ; Driver code ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static bool findPartition ( int [ ] arr , int n ) { int sum = 0 ; int i , j ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; bool [ , ] part = new bool [ sum \\/ 2 + 1 , n + 1 ] ; for ( i = 0 ; i <= n ; i ++ ) part [ 0 , i ] = true ; for ( i = 1 ; i <= sum \\/ 2 ; i ++ ) part [ i , 0 ] = false ; for ( i = 1 ; i <= sum \\/ 2 ; i ++ ) { for ( j = 1 ; j <= n ; j ++ ) { part [ i , j ] = part [ i , j - 1 ] ; if ( i >= arr [ j - 1 ] ) part [ i , j ] = part [ i , j - 1 ] || part [ i - arr [ j - 1 ] , j - 1 ] ; } } return part [ sum \\/ 2 , n ] ; } public static void Main ( ) { int [ ] arr = { 3 , 1 , 1 , 2 , 2 , 1 } ; int n = arr . Length ; if ( findPartition ( arr , n ) == true ) Console . Write ( \\\" Can \u2581 be \u2581 divided \\\" + \\\" \u2581 into \u2581 two \u2581 subsets \u2581 of \\\" + \\\" \u2581 equal \u2581 sum \\\" ) ; else Console . Write ( \\\" Can \u2581 not \u2581 be \u2581 \\\" + \\\" divided \u2581 into \u2581 two \u2581 subsets \\\" + \\\" \u2581 of \u2581 equal \u2581 sum \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"10 's Complement of a decimal number | Function to find 10 's complement ; Calculating total digits in num ; restore num ; calculate 10 's complement ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function complement ( $ num ) { $ i ; $ len = 0 ; $ comp ; $ temp = $ num ; while ( 1 ) { $ len ++ ; $ num = ( int ) ( $ num \\/ 10 ) ; if ( abs ( $ num ) == 0 ) break ; } $ num = $ temp ; $ comp = pow ( 10 , $ len ) - $ num ; return $ comp ; } echo complement ( 25 ) . \\\" \\n \\\" ; echo complement ( 456 ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count number of triplets ( a , b , c ) such that a ^ 2 + b ^ 2 = c ^ 2 and 1 <= a <= b <= c <= n | Java program to Find number of Triplets 1 <= a <= b <= c <= n , Such that a ^ 2 + b ^ 2 = c ^ 2 ; function to ind number of Triplets 1 <= a <= b <= c <= n , Such that a ^ 2 + b ^ 2 = c ^ 2 ; to store required answer ; run nested loops for first two numbers . ; third number ; check if third number is perfect square and less than n ; Driver code ; function call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class Solution { static int Triplets ( int n ) { int ans = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = i ; j <= n ; ++ j ) { int x = i * i + j * j ; int y = ( int ) Math . sqrt ( x ) ; if ( y * y == x && y <= n ) ++ ans ; } } return ans ; } public static void main ( String args [ ] ) { int n = 10 ; System . out . println ( Triplets ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"All about Bit Manipulation | Function to clear the ith bit of the given number N ; Create the mask for the ith bit unset ; Return the update value\\\"\\nSolution in C#:\",\"targets\":\"static int clearBit ( int num , int i ) { int mask = ~ ( 1 << i ) ; return num & mask ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check if the sum of digits of a number N divides it | Function to check if sum of digits of a number divides it ; Calculate sum of all of digits of N ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function isSumDivides ( N ) { var temp = N ; var sum = 0 ; while ( temp > 0 ) { sum += temp % 10 ; temp = parseInt ( temp \\/ 10 ) ; } if ( N % sum == 0 ) return 1 ; else return 0 ; } var N = 12 ; if ( isSumDivides ( N ) == 1 ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Abstraction of Binary Search | C ++ program for the above example ; Function to find X such that it is less than the target value and function is f ( x ) = x ^ 2 ; Initialise start and end ; Loop till start <= end ; Find the mid ; Check for the left half ; Store the result ; Reinitialize the start point ; Check for the right half ; Print the maximum value of x such that x ^ 2 is less than the targetValue ; Driver Code ; Given targetValue ; ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\\" bits \\/ stdc + + . h \\\"\\nusing namespace std ; void findX ( int targetValue ) { int start = 0 , end = targetValue ; int mid , result ; while ( start <= end ) { mid = start + ( end - start ) \\/ 2 ; if ( mid * mid <= targetValue ) { result = mid ; start = mid + 1 ; } else { end = mid - 1 ; } } cout << result << endl ; } int main ( ) { int targetValue = 81 ; findX ( targetValue ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program for subtraction of matrices | ; This function subtracts B [ ] [ ] from A [ ] [ ] , and stores the result in C [ ] [ ] ; To store result\\\"\\nSolution in C:\",\"targets\":\"#include \\n#define N 4\\nvoid subtract ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) { int i , j ; for ( i = 0 ; i < N ; i ++ ) for ( j = 0 ; j < N ; j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ; } int main ( ) { int A [ N ] [ N ] = { { 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 } } ; int B [ N ] [ N ] = { { 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 } } ; int C [ N ] [ N ] ; int i , j ; subtract ( A , B , C ) ; printf ( \\\" Result \u2581 matrix \u2581 is \u2581 \\n \\\" ) ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) printf ( \\\" % d \u2581 \\\" , C [ i ] [ j ] ) ; printf ( \\\" \\n \\\" ) ; } return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximum value of XOR among all triplets of an array | function to count maximum XOR value for a triplet ; set is used to avoid repetitions ; store all possible unique XOR value of pairs ; store maximum value ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function Maximum_xor_Triplet ( n , a ) { let s = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i ; j < n ; j ++ ) { s . add ( a [ i ] ^ a [ j ] ) ; } } let ans = 0 ; for ( let i of s . values ( ) ) { for ( let j = 0 ; j < n ; j ++ ) { ans = Math . max ( ans , i ^ a [ j ] ) ; } } document . write ( ans , \\\" \\\" ) ; } let a = [ 1 , 3 , 8 , 15 ] ; let n = a . length ; Maximum_xor_Triplet ( n , a ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle | Function to find the biggest reuleaux triangle ; the height or base or hypotenuse cannot be negative ; height of the reuleaux triangle ; area of the reuleaux triangle ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function Area ( $ l , $ b , $ h ) { if ( $ l < 0 or $ b < 0 or $ h < 0 ) return -1 ; $ x = ( $ l * $ b ) \\/ ( $ l + $ b ) ; $ A = 0.70477 * pow ( $ x , 2 ) ; return $ A ; } $ l = 5 ; $ b = 12 ; $ h = 13 ; echo Area ( $ l , $ b , $ h ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Longest substring such that no three consecutive characters are same | C ++ implementation of the approach ; Function to return the length of the longest substring such that no three consecutive characters are same ; If the length of the given string is less than 3 ; Initialize temporary and final ans to 2 as this is the minimum length of substring when length of the given string is greater than 2 ; Traverse the string from the third character to the last ; If no three consecutive characters are same then increment temporary count ; Else update the final ans and reset the temporary count ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int maxLenSubStr ( string & s ) { if ( s . length ( ) < 3 ) return s . length ( ) ; int temp = 2 ; int ans = 2 ; for ( int i = 2 ; i < s . length ( ) ; i ++ ) { if ( s [ i ] != s [ i - 1 ] s [ i ] != s [ i - 2 ] ) temp ++ ; else { ans = max ( temp , ans ) ; temp = 2 ; } } ans = max ( temp , ans ) ; return ans ; } int main ( ) { string s = \\\" baaabbabbb \\\" ; cout << maxLenSubStr ( s ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Largest palindromic number in an array | Function to check if n is palindrome ; Find the appropriate divisor to extract the leading digit ; If first and last digits are not same then return false ; Removing the leading and trailing digits from the number ; Reducing divisor by a factor of 2 as 2 digits are dropped ; Function to find the largest palindromic number ; If a palindrome larger than the currentMax is found ; Return the largest palindromic number from the array ; Driver Code ; print required answer\\\"\\nSolution in php:\",\"targets\":\"< ? php function isPalindrome ( $ n ) { $ divisor = 1 ; while ( ( int ) ( $ n \\/ $ divisor ) >= 10 ) $ divisor *= 10 ; while ( $ n != 0 ) { $ leading = ( int ) ( $ n \\/ $ divisor ) ; $ trailing = $ n % 10 ; if ( $ leading != $ trailing ) return false ; $ n = ( $ n % $ divisor ) \\/ 10 ; $ divisor = $ divisor \\/ 100 ; } return true ; } function largestPalindrome ( $ A , $ n ) { $ currentMax = -1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ A [ $ i ] > $ currentMax && isPalindrome ( $ A [ $ i ] ) ) $ currentMax = $ A [ $ i ] ; } return $ currentMax ; } $ A = array ( 1 , 232 , 54545 , 999991 ) ; $ n = sizeof ( $ A ) ; echo ( largestPalindrome ( $ A , $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximum height of triangular arrangement of array values | Javascript program to find the maximum height of Pyramidal Arrangement of array values ; Just checking whether ith level is possible or not if possible then we must have atleast ( i * ( i + 1 ) ) \\/ 2 elements in the array ; updating the result value each time ; otherwise we have exceeded n value ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function MaximumHeight ( a , n ) { let result = 1 ; for ( i = 1 ; i <= n ; ++ i ) { let y = ( i * ( i + 1 ) ) \\/ 2 ; if ( y < n ) result = i ; else break ; } return result ; } let arr = [ 40 , 100 , 20 , 30 ] ; let n = arr . length ; document . write ( MaximumHeight ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find all possible values of K such that the sum of first N numbers starting from K is G | C # program for the above approach ; Function to find the count the value of K such that sum of the first N numbers from K is G ; Stores the total count of K ; Iterate till square root of g ; If the number is factor of g ; If the second factor is not equal to first factor ; Check if two factors are odd or not ; If second factor is the same as the first factor then check if the first factor is odd or not ; Print the resultant count ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void findValuesOfK ( int g ) { int count = 0 ; for ( int i = 1 ; i * i <= g ; i ++ ) { if ( g % i == 0 ) { if ( i != g \\/ i ) { if ( i % 2 == 1 ) { count ++ ; } if ( ( g \\/ i ) % 2 == 1 ) { count ++ ; } } else if ( i % 2 == 1 ) { count ++ ; } } } Console . WriteLine ( count ) ; } public static void Main ( ) { int G = 125 ; findValuesOfK ( G ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Largest area possible after removal of a series of horizontal & vertical bars | Function to find the largest area when a series of horizontal & vertical bars are removed ; Stores all bars ; Insert horizontal bars ; Insert vertictal bars ; Remove horizontal separators from s1 ; Remove vertical separators from s2 ; Stores left out horizontal and vertical separators ; Sort both list in ascending order ; Find maximum difference of neighbors of list1 ; Find max difference of neighbors of list2 ; Print largest volume ; Driver code ; Given value of N & M ; Given arrays ; Function call to find the largest area when a series of horizontal & vertical bars are removed\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def largestArea ( N , M , H , V , h , v ) :\\n\\ts1 = set ( [ ] ) ;\\n\\ts2 = set ( [ ] ) ;\\n\\tfor i in range ( 1 , N + 2 ) :\\n\\t\\ts1 . add ( i ) ;\\n\\tfor i in range ( 1 , M + 2 ) :\\n\\t\\ts2 . add ( i ) ;\\n\\tfor i in range ( h ) :\\n\\t\\ts1 . remove ( H [ i ] ) ;\\n\\tfor i in range ( v ) :\\n\\t\\ts2 . remove ( V [ i ] ) ;\\n\\tlist1 = [ 0 ] * len ( s1 )\\n\\tlist2 = [ 0 ] * len ( s2 ) ;\\n\\ti = 0 ;\\n\\tfor it1 in s1 :\\n\\t\\tlist1 [ i ] = it1 ;\\n\\t\\ti += 1\\n\\ti = 0 ;\\n\\tfor it2 in s2 :\\n\\t\\tlist2 [ i ] = it2\\n\\t\\ti += 1\\n\\tlist1 . sort ( ) ;\\n\\tlist2 . sort ( ) ;\\n\\tmaxH = 0\\n\\tp1 = 0\\n\\tmaxV = 0\\n\\tp2 = 0 ;\\n\\tfor j in range ( len ( s1 ) ) :\\n\\t\\tmaxH = max ( maxH , list1 [ j ] - p1 ) ;\\n\\t\\tp1 = list1 [ j ] ;\\n\\tfor j in range ( len ( s2 ) ) :\\n\\t\\tmaxV = max ( maxV , list2 [ j ] - p2 ) ;\\n\\t\\tp2 = list2 [ j ] ;\\n\\tprint ( ( maxV * maxH ) )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tN = 3\\n\\tM = 3 ;\\n\\tH = [ 2 ]\\n\\tV = [ 2 ] ;\\n\\th = len ( H )\\n\\tv = len ( V ) ;\\n\\tlargestArea ( N , M , H , V , h , v ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Smallest subset with sum greater than all other elements | CPP program to find minimum number of elements such that their sum is greater than sum of remaining elements of the array . ; function to find minimum elements needed . ; calculating HALF of array sum ; sort the array in descending order . ; current sum greater than sum ; Driver function\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#include \\nusing namespace std ; int minElements ( int arr [ ] , int n ) { int halfSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) halfSum = halfSum + arr [ i ] ; halfSum = halfSum \\/ 2 ; sort ( arr , arr + n , greater < int > ( ) ) ; int res = 0 , curr_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { curr_sum += arr [ i ] ; res ++ ; if ( curr_sum > halfSum ) return res ; } return res ; } int main ( ) { int arr [ ] = { 3 , 1 , 7 , 1 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << minElements ( arr , n ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Alternate Primes till N | C # program to print all primes smaller than or equal to n using Naive approach . ; Function for checking number is prime or not ; if flag = 0 then number is prime and return 1 otherwise return 0 ; Function for printing alternate prime number ; counter is initialize with 0 ; looping through 2 to n - 1 ; function calling along with if condition ; if counter is multiple of 2 then only print prime number ; Driver code ; Function calling\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int prime ( int num ) { int i , flag = 0 ; for ( i = 2 ; i <= num \\/ 2 ; i ++ ) { if ( num % i == 0 ) { flag = 1 ; break ; } } if ( flag == 0 ) return 1 ; else return 0 ; } static void print_alternate_prime ( int n ) { int counter = 0 ; for ( int num = 2 ; num < n ; num ++ ) { if ( prime ( num ) == 1 ) { if ( counter % 2 == 0 ) Console . Write ( num + \\\" \u2581 \\\" ) ; counter ++ ; } } } public static void Main ( ) { int n = 15 ; Console . Write ( \\\" Following \u2581 are \u2581 the \u2581 alternate \u2581 \\\" + \\\" prime \u2581 number \u2581 smaller \u2581 than \u2581 \\\" + \\\" or \u2581 equal \u2581 to \u2581 \\\" + n + \\\" \\n \\\" ) ; print_alternate_prime ( n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Number of ways to arrange a word such that no vowels occur together | C ++ code for above approach ; Function to check if a character is vowel or consonent ; Function to calculate factorial of a number ; Calculating no of ways for arranging vowels ; Iterate the map and count the number of vowels and calculate no of ways to arrange vowels ; calculating no of ways to arrange the given word such that all vowels come together ; calculate no of ways to arrange vowels ; to store denominator of fraction ; count of consonents ; calculate the number of ways to arrange the word such that all vowels come together ; To calculate total number of permutations ; To store length of the given word ; denominator of fraction ; return total number of permutations of the given word ; Function to calculate number of permutations such that no vowels come together ; to store frequency of character ; count frequency of all characters ; calculate total number of permutations ; calculate total number of permutations such that all vowels come together ; substrat vwl_tgthr from total to get the result ; return the result ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#define ll long long int\\nusing namespace std ; bool isVowel ( char ch ) { if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) return true ; else return false ; } ll fact ( ll n ) { if ( n < 2 ) return 1 ; return n * fact ( n - 1 ) ; } ll only_vowels ( map < char , int > & freq ) { ll denom = 1 ; ll cnt_vwl = 0 ; for ( auto itr = freq . begin ( ) ; itr != freq . end ( ) ; itr ++ ) { if ( isVowel ( itr -> first ) ) { denom *= fact ( itr -> second ) ; cnt_vwl += itr -> second ; } } return fact ( cnt_vwl ) \\/ denom ; } ll all_vowels_together ( map < char , int > & freq ) { ll vow = only_vowels ( freq ) ; ll denom = 1 ; ll cnt_cnst = 0 ; for ( auto itr = freq . begin ( ) ; itr != freq . end ( ) ; itr ++ ) { if ( ! isVowel ( itr -> first ) ) { denom *= fact ( itr -> second ) ; cnt_cnst += itr -> second ; } } ll ans = fact ( cnt_cnst + 1 ) \\/ denom ; return ( ans * vow ) ; } ll total_permutations ( map < char , int > & freq ) { ll cnt = 0 ; ll denom = 1 ; for ( auto itr = freq . begin ( ) ; itr != freq . end ( ) ; itr ++ ) { denom *= fact ( itr -> second ) ; cnt += itr -> second ; } return fact ( cnt ) \\/ denom ; } ll no_vowels_together ( string & word ) { map < char , int > freq ; for ( int i = 0 ; i < word . size ( ) ; i ++ ) { char ch = tolower ( word [ i ] ) ; freq [ ch ] ++ ; } ll total = total_permutations ( freq ) ; ll vwl_tgthr = all_vowels_together ( freq ) ; ll res = total - vwl_tgthr ; return res ; } int main ( ) { string word = \\\" allahabad \\\" ; ll ans = no_vowels_together ( word ) ; cout << ans << endl ; word = \\\" geeksforgeeks \\\" ; ans = no_vowels_together ( word ) ; cout << ans << endl ; word = \\\" abcd \\\" ; ans = no_vowels_together ( word ) ; cout << ans << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Efficient program to print all prime factors of a given number | Program to print all prime factors ; A function to print all prime factors of a given number n ; Print the number of 2 s that divide n ; n must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; While i divides n , print i and divide n ; This condition is to handle the case when n is a prime number greater than 2 ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"# include \\n# include \\nvoid primeFactors ( int n ) { while ( n % 2 == 0 ) { printf ( \\\" % d \u2581 \\\" , 2 ) ; n = n \\/ 2 ; } for ( int i = 3 ; i <= sqrt ( n ) ; i = i + 2 ) { while ( n % i == 0 ) { printf ( \\\" % d \u2581 \\\" , i ) ; n = n \\/ i ; } } if ( n > 2 ) printf ( \\\" % d \u2581 \\\" , n ) ; } int main ( ) { int n = 315 ; primeFactors ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Maximum width of a binary tree | C program to calculate width of binary tree ; A binary tree node has data , pointer to left child and a pointer to right child ; A utility function to get height of a binary tree ; Function to get the maximum width of a binary tree ; Create an array that will store count of nodes at each level ; Fill the count array using preorder traversal ; Return the maximum value from count array ; A function that fills count array with count of nodes at every level of given binary tree ; Compute the \\\" height \\\" of a tree -- the number of nodes along the longest path from the root node down to the farthest leaf node . ; compute the height of each subtree ; use the larger one ; Helper function that allocates a new node with the given data and NULL left and right pointers . ; Return the maximum value from count array ; Driver program to test above functions ; Constructed bunary tree is : 1 \\/ \\\\ 2 3 \\/ \\\\ \\\\ 4 5 8 \\/ \\\\ 6 7\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nstruct node { int data ; struct node * left ; struct node * right ; } ; int height ( struct node * node ) ; struct node * newNode ( int data ) ; int getMax ( int arr [ ] , int n ) ; void getMaxWidthRecur ( struct node * root , int count [ ] , int level ) ; int getMaxWidth ( struct node * root ) { int width ; int h = height ( root ) ; int * count = ( int * ) calloc ( sizeof ( int ) , h ) ; int level = 0 ; getMaxWidthRecur ( root , count , level ) ; return getMax ( count , h ) ; } void getMaxWidthRecur ( struct node * root , int count [ ] , int level ) { if ( root ) { count [ level ] ++ ; getMaxWidthRecur ( root -> left , count , level + 1 ) ; getMaxWidthRecur ( root -> right , count , level + 1 ) ; } } int height ( struct node * node ) { if ( node == NULL ) return 0 ; else { int lHeight = height ( node -> left ) ; int rHeight = height ( node -> right ) ; return ( lHeight > rHeight ) ? ( lHeight + 1 ) : ( rHeight + 1 ) ; } } struct node * newNode ( int data ) { struct node * node = ( struct node * ) malloc ( sizeof ( struct node ) ) ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } int getMax ( int arr [ ] , int n ) { int max = arr [ 0 ] ; int i ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > max ) max = arr [ i ] ; } return max ; } int main ( ) { struct node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 8 ) ; root -> right -> right -> left = newNode ( 6 ) ; root -> right -> right -> right = newNode ( 7 ) ; printf ( \\\" Maximum \u2581 width \u2581 is \u2581 % d \u2581 \\n \\\" , getMaxWidth ( root ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Reverse words in a given string | C program for above approach : ; temp is for word boundary ; STEP 1 of the above algorithm ; This condition is to make sure that the string start with valid character ( not space ) only ; STEP 2 of the above algorithm\\\"\\nSolution in C:\",\"targets\":\"void reverseWords ( char * s ) { char * word_begin = NULL ; char * temp = s ; while ( * temp ) { if ( ( word_begin == NULL ) && ( * temp != ' \u2581 ' ) ) { word_begin = temp ; } if ( word_begin && ( ( * ( temp + 1 ) == ' \u2581 ' ) || ( * ( temp + 1 ) == ' \\\\0' ) ) ) { reverse ( word_begin , temp ) ; word_begin = NULL ; } temp ++ ; } reverse ( s , temp - 1 ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Bitwise AND of all the odd numbers from 1 to N | C ++ implementation of the approach ; Function to return the bitwise AND of all the odd integers from the range [ 1 , n ] ; Initialize result to 1 ; Starting from 3 , bitwise AND all the odd integers less than or equal to n ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int bitwiseAndOdd ( int n ) { int result = 1 ; for ( int i = 3 ; i <= n ; i = i + 2 ) { result = ( result & i ) ; } return result ; } int main ( ) { int n = 10 ; cout << bitwiseAndOdd ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count smaller elements on right side | ; An AVL tree node ; size of the tree rooted with this node ; A utility function to get maximum of two integers ; A utility function to get height of the tree rooted with N ; A utility function to size of the tree of rooted with N ; A utility function to get maximum of two integers ; Helper function that allocates a new node with the given key and NULL left and right pointers . ; New node is initially added at leaf ; A utility function to right rotate subtree rooted with y ; Perform rotation ; Update heights ; Update sizes ; Return new root ; A utility function to left rotate subtree rooted with x ; Perform rotation ; Update heights ; Update sizes ; Return new root ; Get Balance factor of node N ; Inserts a new key to the tree rotted with node . Also , updates * count to contain count of smaller elements for the new key ; 1. Perform the normal BST rotation ; UPDATE COUNT OF SMALLER ELEMENTS FOR KEY ; 2. Update height and size of this ancestor node ; 3. Get the balance factor of this ancestor node to check whether this node became unbalanced ; Left Left Case ; Right Right Case ; Left Right Case ; Right Left Case ; Return the ( unchanged ) node pointer ; The following function updates the countSmaller array to contain count of smaller elements on right side . ; Initialize all the counts in countSmaller array as 0 ; Starting from rightmost element , insert all elements one by one in an AVL tree and get the count of smaller elements ; Utility function that prints out an array on a line ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; #include \\n#include \\nstruct node { int key ; struct node * left ; struct node * right ; int height ; int size ; } ; int max ( int a , int b ) ; int height ( struct node * N ) { if ( N == NULL ) return 0 ; return N -> height ; } int size ( struct node * N ) { if ( N == NULL ) return 0 ; return N -> size ; } int max ( int a , int b ) { return ( a > b ) ? a : b ; } struct node * newNode ( int key ) { struct node * node = ( struct node * ) malloc ( sizeof ( struct node ) ) ; node -> key = key ; node -> left = NULL ; node -> right = NULL ; node -> height = 1 ; node -> size = 1 ; return ( node ) ; } struct node * rightRotate ( struct node * y ) { struct node * x = y -> left ; struct node * T2 = x -> right ; x -> right = y ; y -> left = T2 ; y -> height = max ( height ( y -> left ) , height ( y -> right ) ) + 1 ; x -> height = max ( height ( x -> left ) , height ( x -> right ) ) + 1 ; y -> size = size ( y -> left ) + size ( y -> right ) + 1 ; x -> size = size ( x -> left ) + size ( x -> right ) + 1 ; return x ; } struct node * leftRotate ( struct node * x ) { struct node * y = x -> right ; struct node * T2 = y -> left ; y -> left = x ; x -> right = T2 ; x -> height = max ( height ( x -> left ) , height ( x -> right ) ) + 1 ; y -> height = max ( height ( y -> left ) , height ( y -> right ) ) + 1 ; x -> size = size ( x -> left ) + size ( x -> right ) + 1 ; y -> size = size ( y -> left ) + size ( y -> right ) + 1 ; return y ; } int getBalance ( struct node * N ) { if ( N == NULL ) return 0 ; return height ( N -> left ) - height ( N -> right ) ; } struct node * insert ( struct node * node , int key , int * count ) { if ( node == NULL ) return ( newNode ( key ) ) ; if ( key < node -> key ) node -> left = insert ( node -> left , key , count ) ; else { node -> right = insert ( node -> right , key , count ) ; * count = * count + size ( node -> left ) + 1 ; } node -> height = max ( height ( node -> left ) , height ( node -> right ) ) + 1 ; node -> size = size ( node...\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Farthest distance of a Node from each Node of a Tree | Python3 program to implement the above approach ; Adjacency List to store the graph ; Stores the height of each node ; Stores the maximum distance of a node from its ancestors ; Function to add edge between two vertices ; Insert edge from u to v ; Insert edge from v to u ; Function to calculate height of each Node ; Iterate in the adjacency list of the current node ; Dfs for child node ; Calculate height of nodes ; Increase height ; Function to calculate the maximum distance of a node from its ancestor ; Iterate in the adjacency list of the current node ; Find two children with maximum heights ; Calculate the maximum distance with ancestor for every node ; Calculating for children ; Driver Code ; Calculate height of nodes of the tree ; Calculate the maximum distance with ancestors ; Print the maximum of the two distances from each node\\\"\\nHow can the above be solved in Python?\",\"targets\":\"maxN = 100001\\nadj = [ [ ] for i in range ( maxN ) ]\\nheight = [ 0 for i in range ( maxN ) ]\\ndist = [ 0 for i in range ( maxN ) ]\\ndef addEdge ( u , v ) :\\n\\tadj [ u ] . append ( v )\\n\\tadj [ v ] . append ( u )\\ndef dfs1 ( cur , par ) :\\n\\tfor u in adj [ cur ] :\\n\\t\\tif ( u != par ) :\\n\\t\\t\\tdfs1 ( u , cur )\\n\\t\\t\\theight [ cur ] = max ( height [ cur ] , height [ u ] )\\n\\theight [ cur ] += 1\\ndef dfs2 ( cur , par ) :\\n\\tmax1 = 0\\n\\tmax2 = 0\\n\\tfor u in adj [ cur ] :\\n\\t\\tif ( u != par ) :\\n\\t\\t\\tif ( height [ u ] >= max1 ) :\\n\\t\\t\\t\\tmax2 = max1\\n\\t\\t\\t\\tmax1 = height [ u ]\\n\\t\\t\\telif ( height [ u ] > max2 ) :\\n\\t\\t\\t\\tmax2 = height [ u ]\\n\\tsum = 0\\n\\tfor u in adj [ cur ] :\\n\\t\\tif ( u != par ) :\\n\\t\\t\\tsum = ( max2 if ( max1 == height [ u ] ) else max1 )\\n\\t\\t\\tif ( max1 == height [ u ] ) :\\n\\t\\t\\t\\tdist [ u ] = 1 + max ( 1 + max2 , dist [ cur ] )\\n\\t\\t\\telse :\\n\\t\\t\\t\\tdist [ u ] = 1 + max ( 1 + max1 , dist [ cur ] )\\n\\t\\t\\tdfs2 ( u , cur )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tn = 6\\n\\taddEdge ( 1 , 2 )\\n\\taddEdge ( 2 , 3 )\\n\\taddEdge ( 2 , 4 )\\n\\taddEdge ( 2 , 5 )\\n\\taddEdge ( 5 , 6 )\\n\\tdfs1 ( 1 , 0 )\\n\\tdfs2 ( 1 , 0 )\\n\\tfor i in range ( 1 , n + 1 ) :\\n\\t\\tprint ( max ( dist [ i ] , height [ i ] ) - 1 , end = ' \u2581 ' )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the sum of a Series ( 1 * 1 ) + ( 2 * 2 ) + ( 3 * 3 ) + ( 4 * 4 ) + ( 5 * 5 ) + ... + ( n * n ) | Java program to calculate the following series ; Function to calculate the following series ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int Series ( int n ) { int i ; int sums = 0 ; for ( i = 1 ; i <= n ; i ++ ) sums += ( i * i ) ; return sums ; } public static void main ( String [ ] args ) { int n = 3 ; int res = Series ( n ) ; System . out . println ( res ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count words in a given string | javascript program to count no of words from given input string . ; returns number of words in str ; word count ; Scan all characters one by one ; If next character is a separator , set the state as OUT ; If next character is not a word separator and state is OUT , then set the state as IN and increment word count ; Move to next character ; Driver program to test above functions\\\"\\nSolution in Javascript:\",\"targets\":\"var OUT = 0 ; var IN = 1 ; function countWords ( str ) { var state = OUT ; var wc = 0 ; var i = 0 ; while ( i < str . length ) { if ( str [ i ] == ' ' str [ i ] == ' ' str [ i ] == ' ' ) state = OUT ; else if ( state == OUT ) { state = IN ; ++ wc ; } ++ i ; } return wc ; } var str = \\\" \\\" ; document . write ( \\\" \\\" + countWords ( str ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Number of digits before the decimal point in the division of two numbers | Function to return the number of digits before the decimal in a \\/ b ; Return the required count of digits ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function countDigits ( a , b ) { return Math . floor ( ( Math . log ( Math . abs ( a ) ) \\/ Math . log ( 10 ) ) - ( Math . log ( Math . abs ( b ) ) \\/ Math . log ( 10 ) ) ) + 1 ; } var a = 100 ; var b = 10 ; document . write ( countDigits ( a , b ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Fibonomial coefficient and Fibonomial triangle | CPP Program to print Fibonomial Triangle of height n . ; Function to produce Fibonacci Series . ; 0 th and 1 st number of the series are 0 and 1 ; Add the previous 2 numbers in the series and store it ; Function to produce fibonomial coefficient ; Function to print Fibonomial Triangle . ; Finding the fibonacci series . ; to store triangle value . ; initialising the 0 th element of each row and diagonal element equal to 0. ; for each row . ; for each column . ; finding each element using recurrence relation . ; printing the Fibonomial Triangle . ; Driven Program\\\"\\nSolution in C++:\",\"targets\":\"#include \\n#define N 6\\nusing namespace std ; void fib ( int f [ ] , int n ) { int i ; f [ 0 ] = 0 ; f [ 1 ] = 1 ; for ( i = 2 ; i <= n ; i ++ ) f [ i ] = f [ i - 1 ] + f [ i - 2 ] ; } void fibcoef ( int fc [ ] [ N + 1 ] , int f [ ] , int n ) { for ( int i = 0 ; i <= n ; i ++ ) fc [ i ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { int k = j ; while ( k -- ) fc [ i ] [ j ] *= f [ k ] ; k = 1 ; while ( ( j + 1 ) != k ) fc [ i ] [ j ] \\/= f [ k ++ ] ; } } } void printFibonomialTriangle ( int n ) { int f [ N + 1 ] = { 0 } ; fib ( f , n ) ; int dp [ N + 1 ] [ N + 1 ] = { 0 } ; for ( int i = 0 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ i ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j < i ; j ++ ) dp [ i ] [ j ] = f [ i - j + 1 ] * dp [ i - 1 ] [ j - 1 ] + f [ j - 1 ] * dp [ i - 1 ] [ j ] ; } for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) cout << dp [ i ] [ j ] << \\\" \u2581 \\\" ; cout << endl ; } } int main ( ) { int n = 6 ; printFibonomialTriangle ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to convert Centimeters to Pixels | Function to convert centimeters to pixels ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def Conversion ( centi ) :\\n\\tpixels = ( 96 * centi ) \\/ 2.54\\n\\tprint ( round ( pixels , 2 ) )\\ncenti = 15\\nConversion ( centi )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Arc length from given Angle | C ++ program to calculate length of an arc ; function to calculate arc length ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; double arcLength ( double diameter , double angle ) { double pi = 22.0 \\/ 7.0 ; double arc ; if ( angle >= 360 ) { cout << \\\" Angle \u2581 cannot \\\" , \\\" \u2581 be \u2581 formed \\\" ; return 0 ; } else { arc = ( pi * diameter ) * ( angle \\/ 360.0 ) ; return arc ; } } int main ( ) { double diameter = 25.0 ; double angle = 45.0 ; double arc_len = arcLength ( diameter , angle ) ; cout << ( arc_len ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimum cost of purchasing at least X chocolates | Java program for above approach ; Function to calculate minimum cost of buying least X chocolates ; Base Case ; Include the i - th box ; Exclude the i - th box ; Return the minimum of the above two cases ; Driver Code ; Given array and value of X ; Store the size of the array ; Print the answer\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int findMinCost ( int [ ] [ ] arr , int X , int n , int i ) { if ( X <= 0 ) return 0 ; if ( i >= n ) return Integer . MAX_VALUE ; int inc = findMinCost ( arr , X - arr [ i ] [ 0 ] , n , i + 1 ) ; if ( inc != Integer . MAX_VALUE ) inc += arr [ i ] [ 1 ] ; int exc = findMinCost ( arr , X , n , i + 1 ) ; return Math . min ( inc , exc ) ; } public static void main ( String [ ] args ) { int [ ] [ ] arr = { { 4 , 3 } , { 3 , 2 } , { 2 , 4 } , { 1 , 3 } , { 4 , 2 } } ; int X = 7 ; int n = arr . length ; int ans = findMinCost ( arr , X , n , 0 ) ; if ( ans != Integer . MAX_VALUE ) System . out . println ( ans ) ; else System . out . println ( - 1 ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Pell Number | Iterative Pell Number Series in C ; calculate nth pell number ; driver function\\\"\\nSolution in C:\",\"targets\":\"#include \\nint pell ( int n ) { if ( n <= 2 ) return n ; int a = 1 ; int b = 2 ; int c , i ; for ( i = 3 ; i <= n ; i ++ ) { c = 2 * b + a ; a = b ; b = c ; } return b ; } int main ( ) { int n = 4 ; printf ( \\\" % d \\\" , pell ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Print path from root to all nodes in a Complete Binary Tree | Function to print path of all the nodes nth node represent as given node kth node represents as left and right node ; base condition if kth node value is greater then nth node then its means kth node is not valid so we not store it into the res simply we just return ; Storing node into res ; Print the path from root to node ; store left path of a tree So for left we will go node ( kThNode * 2 ) ; right path of a tree and for right we will go node ( kThNode * 2 + 1 ) ; Function to print path from root to all of the nodes ; res is for store the path from root to particulate node ; Print path from root to all node . third argument 1 because of we have to consider root node is 1 ; Given Node ; Print path from root to all node .\\\"\\nSolution in php:\",\"targets\":\"< ? php function printPath ( $ res , $ nThNode , $ kThNode ) { if ( $ kThNode > $ nThNode ) return ; array_push ( $ res , $ kThNode ) ; for ( $ i = 0 ; $ i < count ( $ res ) ; $ i ++ ) echo $ res [ $ i ] . \\\" \u2581 \\\" ; echo \\\" \\n \\\" ; printPath ( $ res , $ nThNode , $ kThNode * 2 ) ; printPath ( $ res , $ nThNode , $ kThNode * 2 + 1 ) ; } function printPathToCoverAllNodeUtil ( $ nThNode ) { $ res = array ( ) ; printPath ( $ res , $ nThNode , 1 ) ; } $ nThNode = 7 ; printPathToCoverAllNodeUtil ( $ nThNode ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count all possible groups of size 2 or 3 that have sum as multiple of 3 | C Program to count all possible groups of size 2 or 3 that have sum as multiple of 3 ; Returns count of all possible groups that can be formed from elements of a [ ] . ; Create an array C [ 3 ] to store counts of elements with remainder 0 , 1 and 2. c [ i ] would store count of elements with remainder i ; To store the result ; Count elements with remainder 0 , 1 and 2 ; Case 3. a : Count groups of size 2 from 0 remainder elements ; Case 3. b : Count groups of size 2 with one element with 1 remainder and other with 2 remainder ; Case 4. a : Count groups of size 3 with all 0 remainder elements ; Case 4. b : Count groups of size 3 with all 1 remainder elements ; Case 4. c : Count groups of size 3 with all 2 remainder elements ; Case 4. c : Count groups of size 3 with different remainders ; Return total count stored in res ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\nint findgroups ( int arr [ ] , int n ) { int c [ 3 ] = { 0 } , i ; int res = 0 ; for ( i = 0 ; i < n ; i ++ ) c [ arr [ i ] % 3 ] ++ ; res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ; res += c [ 1 ] * c [ 2 ] ; res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) \\/ 6 ; res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) \\/ 6 ; res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) \\/ 6 ) ; res += c [ 0 ] * c [ 1 ] * c [ 2 ] ; return res ; } int main ( ) { int arr [ ] = { 3 , 6 , 7 , 2 , 9 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Required \u2581 number \u2581 of \u2581 groups \u2581 are \u2581 % d \\n \\\" , findgroups ( arr , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find all strings that match specific pattern in a dictionary | Javascript program to print all the strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary ; Function to print all the strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary ; len is length of the pattern ; For each word in the dictionary ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function check ( pattern , word ) { if ( pattern . length != word . length ) return false ; let ch = new Array ( 128 ) ; for ( let i = 0 ; i < 128 ; i ++ ) { ch [ i ] = 0 ; } let Len = word . length ; for ( let i = 0 ; i < Len ; i ++ ) { if ( ch [ pattern [ i ] . charCodeAt ( 0 ) ] == 0 ) { ch [ pattern [ i ] . charCodeAt ( 0 ) ] = word [ i ] ; } else if ( ch [ pattern [ i ] . charCodeAt ( 0 ) ] != word [ i ] ) { return false ; } } return true ; } function findMatchedWords ( dict , pattern ) { let Len = pattern . length ; let result = \\\" \\\" ; for ( let word of dict . values ( ) ) { if ( check ( pattern , word ) ) { result = word + \\\" \\\" + result ; } } document . write ( result ) ; } let dict = new Set ( ) ; dict . add ( \\\" \\\" ) ; dict . add ( \\\" \\\" ) ; dict . add ( \\\" \\\" ) ; dict . add ( \\\" \\\" ) ; let pattern = \\\" \\\" ; findMatchedWords ( dict , pattern ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if an array has a majority element | Hashing based Java program to find if there is a majority element in input array . ; Returns true if there is a majority element in a [ ] ; Insert all elements in a hash table ; Check if frequency of any element is n \\/ 2 or more . ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; import java . lang . * ; import java . io . * ; class Gfg { static boolean isMajority ( int a [ ] , int n ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( mp . containsKey ( a [ i ] ) ) mp . put ( a [ i ] , mp . get ( a [ i ] ) + 1 ) ; else mp . put ( a [ i ] , 1 ) ; for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) if ( x . getValue ( ) >= n \\/ 2 ) return true ; return false ; } public static void main ( String [ ] args ) { int a [ ] = { 2 , 3 , 9 , 2 , 2 } ; int n = a . length ; if ( isMajority ( a , n ) ) System . out . println ( \\\" Yes \\\" ) ; else System . out . println ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if one string can be converted to another | Python3 implementation of the above approach . ; Function for find from Disjoset algorithm ; Function for the union from Disjoset algorithm ; Function to check if one string can be converted to another . ; All the characters are checked whether it 's either not replaced or replaced by a similar character using a map. ; To check if there are cycles . If yes , then they are not convertible . Else , they are convertible . ; Function to initialize parent array for union and find algorithm . ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"parent = [ 0 ] * 256\\ndef find ( x ) :\\n\\tif ( x != parent [ x ] ) :\\n\\t\\tparent [ x ] = find ( parent [ x ] )\\n\\t\\treturn parent [ x ]\\n\\treturn x\\ndef join ( x , y ) :\\n\\tpx = find ( x )\\n\\tpz = find ( y )\\n\\tif ( px != pz ) :\\n\\t\\tparent [ pz ] = px\\ndef convertible ( s1 , s2 ) :\\n\\tmp = dict ( )\\n\\tfor i in range ( len ( s1 ) ) :\\n\\t\\tif ( s1 [ i ] in mp ) :\\n\\t\\t\\tmp [ s1 [ i ] ] = s2 [ i ]\\n\\t\\telse :\\n\\t\\t\\tif s1 [ i ] in mp and mp [ s1 [ i ] ] != s2 [ i ] :\\n\\t\\t\\t\\treturn False\\n\\tfor it in mp :\\n\\t\\tif ( it == mp [ it ] ) :\\n\\t\\t\\tcontinue\\n\\t\\telse :\\n\\t\\t\\tif ( find ( ord ( it ) ) == find ( ord ( it ) ) ) :\\n\\t\\t\\t\\treturn False\\n\\t\\t\\telse :\\n\\t\\t\\t\\tjoin ( ord ( it ) , ord ( it ) )\\n\\treturn True\\ndef initialize ( ) :\\n\\tfor i in range ( 256 ) :\\n\\t\\tparent [ i ] = i\\ns1 = \\\" abbcaa \\\"\\ns2 = \\\" bccdbb \\\"\\ninitialize ( )\\nif ( convertible ( s1 , s2 ) ) :\\n\\tprint ( \\\" Yes \\\" )\\nelse :\\n\\tprint ( \\\" No \\\" )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Cutting a Rod | DP | A Naive recursive solution for Rod cutting problem ; A utility function to get the maximum of two integers ; Returns the best obtainable price for a rod of length n and price [ ] as prices of different pieces ; Recursively cut the rod in different pieces and compare different configurations ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import sys\\ndef max ( a , b ) :\\n\\treturn a if ( a > b ) else b\\ndef cutRod ( price , n ) :\\n\\tif ( n <= 0 ) :\\n\\t\\treturn 0\\n\\tmax_val = - sys . maxsize - 1\\n\\tfor i in range ( 0 , n ) :\\n\\t\\tmax_val = max ( max_val , price [ i ] + cutRod ( price , n - i - 1 ) )\\n\\treturn max_val\\narr = [ 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 ]\\nsize = len ( arr )\\nprint ( \\\" Maximum \u2581 Obtainable \u2581 Value \u2581 is \\\" , cutRod ( arr , size ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"How to print maximum number of A 's using given four keys | A recursive C program to print maximum number of A 's using following four keys ; A recursive function that returns the optimal length string for N keystrokes ; The optimal string length is N when N is smaller than 7 ; Initialize result ; TRY ALL POSSIBLE BREAK - POINTS For any keystroke N , we need to loop from N - 3 keystrokes back to 1 keystroke to find a breakpoint ' b ' after which we will have Ctrl - A , Ctrl - C and then only Ctrl - V all the way . ; If the breakpoint is s at b 'th keystroke then the optimal string would have length (n-b-1)*screen[b-1]; ; Driver program ; for the rest of the array we will rely on the previous entries to compute new ones\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint findoptimal ( int N ) { if ( N <= 6 ) return N ; int max = 0 ; int b ; for ( b = N - 3 ; b >= 1 ; b -- ) { int curr = ( N - b - 1 ) * findoptimal ( b ) ; if ( curr > max ) max = curr ; } return max ; } int main ( ) { int N ; for ( N = 1 ; N <= 20 ; N ++ ) printf ( \\\" Maximum \u2581 Number \u2581 of \u2581 A ' s \u2581 with \u2581 % d \u2581 keystrokes \u2581 is \u2581 % d \\n \\\" , N , findoptimal ( N ) ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Maximum width of a binary tree | C program to calculate width of binary tree ; A binary tree node has data , pointer to left child and a pointer to right child ; Function protoypes ; Function to get the maximum width of a binary tree ; Get width of each level and compare the width with maximum width so far ; Get width of a given level ; Compute the \\\" height \\\" of a tree -- the number of nodes along the longest path from the root node down to the farthest leaf node . ; compute the height of each subtree ; use the larger one ; Helper function that allocates a new node with the given data and NULL left and right pointers . ; Driver code ; Constructed binary tree is : 1 \\/ \\\\ 2 3 \\/ \\\\ \\\\ 4 5 8 \\/ \\\\ 6 7 ; Function call\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nstruct node { int data ; struct node * left ; struct node * right ; } ; int getWidth ( struct node * root , int level ) ; int height ( struct node * node ) ; struct node * newNode ( int data ) ; int getMaxWidth ( struct node * root ) { int maxWidth = 0 ; int width ; int h = height ( root ) ; int i ; for ( i = 1 ; i <= h ; i ++ ) { width = getWidth ( root , i ) ; if ( width > maxWidth ) maxWidth = width ; } return maxWidth ; } int getWidth ( struct node * root , int level ) { if ( root == NULL ) return 0 ; if ( level == 1 ) return 1 ; else if ( level > 1 ) return getWidth ( root -> left , level - 1 ) + getWidth ( root -> right , level - 1 ) ; } int height ( struct node * node ) { if ( node == NULL ) return 0 ; else { int lHeight = height ( node -> left ) ; int rHeight = height ( node -> right ) ; return ( lHeight > rHeight ) ? ( lHeight + 1 ) : ( rHeight + 1 ) ; } } struct node * newNode ( int data ) { struct node * node = ( struct node * ) malloc ( sizeof ( struct node ) ) ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } int main ( ) { struct node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 8 ) ; root -> right -> right -> left = newNode ( 6 ) ; root -> right -> right -> right = newNode ( 7 ) ; printf ( \\\" Maximum \u2581 width \u2581 is \u2581 % d \u2581 \\n \\\" , getMaxWidth ( root ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximum triplet sum in array | This function assumes that there are at least three elements in arr [ ] . ; sort the given array ; After sorting the array . Add last three element of the given array ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function maxTripletSum ( $ arr , $ n ) { sort ( $ arr ) ; return $ arr [ $ n - 1 ] + $ arr [ $ n - 2 ] + $ arr [ $ n - 3 ] ; } $ arr = array ( 1 , 0 , 8 , 6 , 4 , 2 ) ; $ n = count ( $ arr ) ; echo maxTripletSum ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Length of the longest subsegment which is UpDown after inserting atmost one integer | Java implementation of the approach ; Function to recursively fill the dp array ; If f ( i , state ) is already calculated then return the value ; Calculate f ( i , state ) according to the recurrence relation and store in dp [ ] [ ] ; Function that calls the resucrsive function to fill the dp array and then returns the result ; dp [ ] [ ] array for storing result of f ( i , 1 ) and f ( 1 , 2 ) ; Populating the array dp [ ] with - 1 ; Make sure that longest UD and DU sequence starting at each index is calculated ; Assume the answer to be - 1 This value will only increase ; y is the length of the longest UD sequence starting at i ; If length is even then add an integer and then a DU sequence starting at i + y ; If length is odd then add an integer and then a UD sequence starting at i + y ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int f ( int i , int state , int A [ ] , int dp [ ] [ ] , int N ) { if ( i >= N ) return 0 ; else if ( dp [ i ] [ state ] != - 1 ) { return dp [ i ] [ state ] ; } else { if ( i == N - 1 ) dp [ i ] [ state ] = 1 ; else if ( state == 1 && A [ i ] > A [ i + 1 ] ) dp [ i ] [ state ] = 1 ; else if ( state == 2 && A [ i ] < A [ i + 1 ] ) dp [ i ] [ state ] = 1 ; else if ( state == 1 && A [ i ] <= A [ i + 1 ] ) dp [ i ] [ state ] = 1 + f ( i + 1 , 2 , A , dp , N ) ; else if ( state == 2 && A [ i ] >= A [ i + 1 ] ) dp [ i ] [ state ] = 1 + f ( i + 1 , 1 , A , dp , N ) ; return dp [ i ] [ state ] ; } } static int maxLenSeq ( int A [ ] , int N ) { int i , j , tmp , y , ans ; int dp [ ] [ ] = new int [ 1000 ] [ 3 ] ; for ( i = 0 ; i < 1000 ; i ++ ) for ( j = 0 ; j < 3 ; j ++ ) dp [ i ] [ j ] = - 1 ; for ( i = 0 ; i < N ; i ++ ) { tmp = f ( i , 1 , A , dp , N ) ; tmp = f ( i , 2 , A , dp , N ) ; } ans = - 1 ; for ( i = 0 ; i < N ; i ++ ) { y = dp [ i ] [ 1 ] ; if ( i + y >= N ) ans = Math . max ( ans , dp [ i ] [ 1 ] + 1 ) ; else if ( y % 2 == 0 ) { ans = Math . max ( ans , dp [ i ] [ 1 ] + 1 + dp [ i + y ] [ 2 ] ) ; } else if ( y % 2 == 1 ) { ans = Math . max ( ans , dp [ i ] [ 1 ] + 1 + dp [ i + y ] [ 1 ] ) ; } } return ans ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 10 , 3 , 20 , 25 , 24 } ; int n = A . length ; System . out . println ( maxLenSeq ( A , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if a right | Java implementation of the approach ; Storing all the possible changes to make the triangle right - angled ; Function to check if the triangle is right - angled or not ; Function to check if the triangle can be transformed to right - angled ; Boolean variable to return true or false ; If it is already right - angled ; Applying the changes on the co - ordinates ; Applying on the first co - ordinate ; Applying on the second co - ordinate ; Applying on the third co - ordinate ; If can 't be transformed ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static int dx [ ] = { - 1 , 0 , 1 , 0 } ; static int dy [ ] = { 0 , 1 , 0 , - 1 } ; static boolean ifRight ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { int a = ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) ; int b = ( ( x1 - x3 ) * ( x1 - x3 ) ) + ( ( y1 - y3 ) * ( y1 - y3 ) ) ; int c = ( ( x2 - x3 ) * ( x2 - x3 ) ) + ( ( y2 - y3 ) * ( y2 - y3 ) ) ; if ( ( a == ( b + c ) && a != 0 && b != 0 && c != 0 ) || ( b == ( a + c ) && a != 0 && b != 0 && c != 0 ) || ( c == ( a + b ) && a != 0 && b != 0 && c != 0 ) ) { return true ; } return false ; } static void isValidCombination ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { int x , y ; boolean possible = false ; if ( ifRight ( x1 , y1 , x2 , y2 , x3 , y3 ) ) { System . out . print ( \\\" ALREADY \u2581 RIGHT \u2581 ANGLED \\\" ) ; return ; } else { for ( int i = 0 ; i < 4 ; i ++ ) { x = dx [ i ] + x1 ; y = dy [ i ] + y1 ; if ( ifRight ( x , y , x2 , y2 , x3 , y3 ) ) { System . out . print ( \\\" POSSIBLE \\\" ) ; return ; } x = dx [ i ] + x2 ; y = dy [ i ] + y2 ; if ( ifRight ( x1 , y1 , x , y , x3 , y3 ) ) { System . out . print ( \\\" POSSIBLE \\\" ) ; return ; } x = dx [ i ] + x3 ; y = dy [ i ] + y3 ; if ( ifRight ( x1 , y1 , x2 , y2 , x , y ) ) { System . out . print ( \\\" POSSIBLE \\\" ) ; return ; } } } if ( ! possible ) System . out . println ( \\\" NOT \u2581 POSSIBLE \\\" ) ; } public static void main ( String [ ] args ) { int x1 = - 49 , y1 = 0 ; int x2 = 0 , y2 = 50 ; int x3 = 0 , y3 = - 50 ; isValidCombination ( x1 , y1 , x2 , y2 , x3 , y3 ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum rotations required to get the same string | C ++ program to determine minimum number of rotations required to yield same string . ; Returns count of rotations to get the same string back . ; tmp is the concatenated string . ; substring from i index of original string size . ; if substring matches with original string then we will come out of the loop . ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int findRotations ( string str ) { string tmp = str + str ; int n = str . length ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { string substring = tmp . substr ( i , str . size ( ) ) ; if ( str == substring ) return i ; } return n ; } int main ( ) { string str = \\\" abc \\\" ; cout << findRotations ( str ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if all array elements can be reduced to 0 by repeatedly reducing pairs of consecutive elements by their minimum | Function to check if it is possible to convert the array ; Traverse the array range [ 1 , N - 1 ] ; If arr [ i ] < arr [ i - 1 ] ; Otherwise ; Decrement arr [ i ] by arr [ i - 1 ] ; If arr [ n - 1 ] is not equal to zero ; Otherwise ; Driver Code ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function checkPossible ( arr , n ) { for ( i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) { document . write ( \\\" \\\" ) ; return ; } else { arr [ i ] -= arr [ i - 1 ] ; arr [ i - 1 ] = 0 ; } } if ( arr [ n - 1 ] == 0 ) { document . write ( \\\" \\\" ) ; } else { document . write ( \\\" \\\" ) ; } } var arr = [ 2 , 3 , 3 , 4 , 2 ] ; var N = arr . length ; checkPossible ( arr , N ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program to find Normal and Trace of a matrix | C # program to find trace and normal of given matrix ; Returns Normal of a matrix of size n x n ; Returns trace of a matrix of size n x n ; Driven source\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int findNormal ( int [ , ] mat , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) sum += mat [ i , j ] * mat [ i , j ] ; return ( int ) Math . Sqrt ( sum ) ; } static int findTrace ( int [ , ] mat , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += mat [ i , i ] ; return sum ; } public static void Main ( ) { int [ , ] mat = { { 1 , 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 , 4 } , { 5 , 5 , 5 , 5 , 5 } , } ; Console . Write ( \\\" Trace \u2581 of \u2581 Matrix \u2581 = \u2581 \\\" + findTrace ( mat , 5 ) + \\\" \\n \\\" ) ; Console . Write ( \\\" Normal \u2581 of \u2581 Matrix \u2581 = \u2581 \\\" + findNormal ( mat , 5 ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Smallest power of 4 greater than or equal to N | Function to return the smallest power of 4 greater than or equal to n ; If n is itself is a power of 4 then return n ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function nextPowerOfFour ( n ) { let x = Math . floor ( Math . sqrt ( Math . sqrt ( n ) ) ) ; if ( Math . pow ( x , 4 ) == n ) return n ; else { x = x + 1 ; return Math . pow ( x , 4 ) ; } } let n = 122 ; document . write ( nextPowerOfFour ( n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Smallest Even number with N digits | C ++ implementation of the approach ; Function to return smallest even number with n digits ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int smallestEven ( int n ) { if ( n == 1 ) return 0 ; return pow ( 10 , n - 1 ) ; } int main ( ) { int n = 4 ; cout << smallestEven ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find consecutive 1 s of length >= n in binary representation of a number | Function to count the number of leading zeros ; Function to find the string of n consecutive 1 's ; Initialize position to return . ; Skip leading 0 's ; Set position after leading 0 's ; Count first group of 1 's. ; If length of consecutive 1 's is greater than or equal to n ; Not enough 1 's skip over to next group ; Update the position ; if no string is found ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function countLeadingZeros ( x ) { let y ; let n ; n = 32 ; y = x >> 16 ; if ( y != 0 ) { n = n - 16 ; x = y ; } y = x >> 8 ; if ( y != 0 ) { n = n - 8 ; x = y ; } y = x >> 4 ; if ( y != 0 ) { n = n - 4 ; x = y ; } y = x >> 2 ; if ( y != 0 ) { n = n - 2 ; x = y ; } y = x >> 1 ; if ( y != 0 ) return n - 2 ; return n - x ; } function FindStringof1s ( x , n ) { let k , p ; p = 0 ; while ( x != 0 ) { k = countLeadingZeros ( x ) ; x = x << k ; p = p + k ; k = countLeadingZeros ( ~ x ) ; if ( k >= n ) return p + 1 ; x = x << k ; p = p + k ; } return - 1 ; } let x = 35 ; let n = 2 ; document . write ( FindStringof1s ( x , n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Linear Search | Javascript code to linearly search x in arr [ ] . If x is present then return its location , otherwise return - 1 ; Driver code ; Function call\\\"\\nSolution in Javascript:\",\"targets\":\"function search ( arr , n , x ) { let i ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] == x ) return i ; return - 1 ; } let arr = [ 2 , 3 , 4 , 10 , 40 ] ; let x = 10 ; let n = arr . length ; let result = search ( arr , n , x ) ; ( result == - 1 ) ? document . write ( \\\" \\\" ) : document . write ( \\\" \\\" + result ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if two items can be selected from two different categories without exceeding price | C ++ implementation to check if two items can be selected from two different categories without exceeding the total price ; Function to check if two items can be selected from two different categories without exceeding the total price ; Loop to choose two different pairs using two nested loops ; Condition to check if the price of these two elements is less than S ; Driver Code ; Function Call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; string check ( int S , int prices [ ] , int type [ ] , int n ) { for ( int j = 0 ; j < n ; j ++ ) { for ( int k = j + 1 ; k < n ; k ++ ) { if ( ( type [ j ] == 0 && type [ k ] == 1 ) || ( type [ j ] == 1 && type [ k ] == 0 ) ) { if ( prices [ j ] + prices [ k ] <= S ) { return \\\" Yes \\\" ; } } } } return \\\" No \\\" ; } int main ( ) { int prices [ ] = { 3 , 8 , 6 , 5 } ; int type [ ] = { 0 , 1 , 1 , 0 } ; int S = 10 ; int n = 4 ; cout << check ( S , prices , type , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if a String contains any index with more than K active characters | Function to check if any index contains more than K active characters ; Store the last occurrence of each character in the map . ; Stores the active characters ; Insert the character ; If the size of set exceeds K ; Remove the character from set if i is the last index of the current character ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function checkString ( s , K ) { var n = s . length ; var mp = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( mp . has ( s [ i ] ) ) { mp . set ( s [ i ] , mp . get ( s [ i ] ) + 1 ) ; } else mp . set ( s [ i ] , 1 ) ; } var cnt = 0 , f = 0 ; var st = new Set ( ) ; for ( var i = 0 ; i < n ; i ++ ) { st . add ( s [ i ] ) ; if ( st . size > K ) { f = 1 ; break ; } if ( mp . get ( s [ i ] ) == i ) st . delete ( s [ i ] ) ; } return ( f == 1 ? \\\" \\\" : \\\" \\\" ) ; } var s = \\\" \\\" ; var k = 2 ; document . write ( checkString ( s , k ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Determine if a string has all Unique Characters | Javascript program to illustrate string with unique characters using brute force technique ; If at any time we encounter 2 same characters , return false ; If no duplicate characters encountered , return true ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function uniqueCharacters ( str ) { for ( let i = 0 ; i < str . length ; i ++ ) for ( let j = i + 1 ; j < str . length ; j ++ ) if ( str [ i ] == str [ j ] ) return false ; return true ; } let input = \\\" \\\" ; if ( uniqueCharacters ( input ) == true ) document . write ( \\\" \\\" + input + \\\" \\\" + \\\" \\\" ) ; else document . write ( \\\" \\\" + input + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find n | C program for nth nodes of inorder traversals ; A binary tree node has data , pointer to left child and a pointer to right child ; Helper function that allocates a new node with the given data and NULL left and right pointers . ; Given a binary tree , print its nth nodes of inorder ; first recur on left child ; when count = n then print element ; now recur on right child ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nstruct Node { int data ; struct Node * left ; struct Node * right ; } ; struct Node * newNode ( int data ) { struct Node * node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } void NthInorder ( struct Node * node , int n ) { static int count = 0 ; if ( node == NULL ) return ; if ( count <= n ) { NthInorder ( node -> left , n ) ; count ++ ; if ( count == n ) printf ( \\\" % d \u2581 \\\" , node -> data ) ; NthInorder ( node -> right , n ) ; } } int main ( ) { struct Node * root = newNode ( 10 ) ; root -> left = newNode ( 20 ) ; root -> right = newNode ( 30 ) ; root -> left -> left = newNode ( 40 ) ; root -> left -> right = newNode ( 50 ) ; int n = 4 ; NthInorder ( root , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Length of Longest Prime Subsequence in an Array | Python 3 program to find the length of Longest Prime Subsequence in an Array ; Function to create Sieve to check primes ; False here indicates that it is not prime ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p , set them to non - prime ; Function to find the longest subsequence which contain all prime numbers ; Precompute N primes ; Find the length of longest prime subsequence ; Driver code ; Function call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"N = 100005\\ndef SieveOfEratosthenes ( prime , p_size ) :\\n\\tprime [ 0 ] = False\\n\\tprime [ 1 ] = False\\n\\tp = 2\\n\\twhile p * p <= p_size :\\n\\t\\tif ( prime [ p ] ) :\\n\\t\\t\\tfor i in range ( p * 2 , p_size + 1 , p ) :\\n\\t\\t\\t\\tprime [ i ] = False\\n\\t\\tp += 1\\ndef longestPrimeSubsequence ( arr , n ) :\\n\\tprime = [ True ] * ( N + 1 )\\n\\tSieveOfEratosthenes ( prime , N )\\n\\tanswer = 0\\n\\tfor i in range ( n ) :\\n\\t\\tif ( prime [ arr [ i ] ] ) :\\n\\t\\t\\tanswer += 1\\n\\treturn answer\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ 3 , 4 , 11 , 2 , 9 , 21 ]\\n\\tn = len ( arr )\\n\\tprint ( longestPrimeSubsequence ( arr , n ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Print all possible combinations of r elements in a given array of size n | Java program to print all combination of size r in an array of size n ; The main function that prints all combinations of size r in arr [ ] of size n . This function mainly uses combinationUtil ( ) ; A temporary array to store all combination one by one ; Print all combination using temprary array ' data [ ] ' ; arr [ ] -- -> Input Array data [ ] -- -> Temporary array to store current combination start & end -- -> Staring and Ending indexes in arr [ ] index -- -> Current index in data [ ] r -- -> Size of a combination to be printed ; Current combination is ready to be printed , print it ; When no more elements are there to put in data [ ] ; current is included , put next at next location ; current is excluded , replace it with next ( Note that i + 1 is passed , but index is not changed ) ; Driver function to check for above function\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class Combination { static void printCombination ( int arr [ ] , int n , int r ) { int data [ ] = new int [ r ] ; combinationUtil ( arr , n , r , 0 , data , 0 ) ; } static void combinationUtil ( int arr [ ] , int n , int r , int index , int data [ ] , int i ) { if ( index == r ) { for ( int j = 0 ; j < r ; j ++ ) System . out . print ( data [ j ] + \\\" \u2581 \\\" ) ; System . out . println ( \\\" \\\" ) ; return ; } if ( i >= n ) return ; data [ index ] = arr [ i ] ; combinationUtil ( arr , n , r , index + 1 , data , i + 1 ) ; combinationUtil ( arr , n , r , index , data , i + 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int r = 3 ; int n = arr . length ; printCombination ( arr , n , r ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count numbers having 0 as a digit | Returns 1 if x has 0 , else 0 ; Traverse through all digits of x to check if it has 0. ; If current digit is 0 , return true ; Returns count of numbers from 1 to n with 0 as digit ; Initialize count of numbers having 0 as digit ; Traverse through all numbers and for every number check if it has 0. ; Driver program\\\"\\nSolution in Javascript:\",\"targets\":\"function has0 ( x ) { while ( x ) { if ( x % 10 == 0 ) return 1 ; x = Math . floor ( x \\/ 10 ) ; } return 0 ; } function getCount ( n ) { let count = 0 ; for ( let i = 1 ; i <= n ; i ++ ) count += has0 ( i ) ; return count ; } let n = 107 ; document . write ( \\\" \\\" + \\\" \\\" + n + \\\" \\\" + getCount ( n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Frequency Measuring Techniques for Competitive Programming | Python program to count frequencies of array items ; mark all array elements as not visited ; Traverse through array elements and count frequencies ; Skip this element if already processed ; count frequency ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def countFreq ( arr , n ) :\\n\\tvisited = [ False for i in range ( n ) ]\\n\\tfor i in range ( n ) :\\n\\t\\tif visited [ i ] == True :\\n\\t\\t\\tcontinue\\n\\t\\tcount = 1\\n\\t\\tfor j in range ( i + 1 , n ) :\\n\\t\\t\\tif arr [ i ] == arr [ j ] :\\n\\t\\t\\t\\tvisited [ j ] = True\\n\\t\\t\\t\\tcount += 1\\n\\t\\tprint ( arr [ i ] , count )\\na = [ 10 , 20 , 20 , 10 , 10 , 20 , 5 , 20 ]\\nn = len ( a )\\ncountFreq ( a , n )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Rearrange an array to minimize sum of product of consecutive pair elements | Python 3 program to sort an array such that sum of product of alternate element is minimum . ; create evenArr [ ] and oddArr [ ] ; sort main array in ascending order ; Put elements in oddArr [ ] and evenArr [ ] as per desired value . ; sort evenArr [ ] in descending order ; merge both sub - array and calculate minimum sum of product of alternate elements ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def minSum ( arr , n ) :\\n\\tevenArr = [ ]\\n\\toddArr = [ ]\\n\\tarr . sort ( )\\n\\tfor i in range ( n ) :\\n\\t\\tif ( i < n \\/\\/ 2 ) :\\n\\t\\t\\toddArr . append ( arr [ i ] )\\n\\t\\telse :\\n\\t\\t\\tevenArr . append ( arr [ i ] )\\n\\tevenArr . sort ( reverse = True )\\n\\ti = 0\\n\\tsum = 0\\n\\tfor j in range ( len ( evenArr ) ) :\\n\\t\\tarr [ i ] = evenArr [ j ]\\n\\t\\ti += 1\\n\\t\\tarr [ i ] = oddArr [ j ]\\n\\t\\ti += 1\\n\\t\\tsum += evenArr [ j ] * oddArr [ j ]\\n\\treturn sum\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 ]\\n\\tn = len ( arr )\\n\\tprint ( \\\" Minimum \u2581 required \u2581 sum \u2581 = \\\" , minSum ( arr , n ) )\\n\\tprint ( \\\" Sorted \u2581 array \u2581 in \u2581 required \u2581 format \u2581 : \u2581 \\\" , end = \\\" \\\" )\\n\\tfor i in range ( n ) :\\n\\t\\tprint ( arr [ i ] , end = \\\" \u2581 \\\" )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Smallest power of 2 greater than or equal to n | C ++ program to find smallest power of 2 greater than or equal to n ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; unsigned int nextPowerOf2 ( unsigned int n ) { unsigned int p = 1 ; if ( n && ! ( n & ( n - 1 ) ) ) return n ; while ( p < n ) p <<= 1 ; return p ; } int main ( ) { unsigned int n = 5 ; cout << nextPowerOf2 ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Given a HUGE number check if it 's a power of two. | returns 1 when str is power of 2 return 0 when str is not a power of 2 ; sum stores the intermediate dividend while dividing . ; if the input is \\\"1\\\" then return 0 because 2 ^ k = 1 where k >= 1 and here k = 0 ; Divide the number until it gets reduced to 1 if we are successfully able to reduce the number to 1 it means input string is power of two if in between an odd number appears at the end it means string is not divisible by two hence not a power of 2. ; if the last digit is odd then string is not divisible by 2 hence not a power of two return 0. ; divide the whole string by 2. i is used to track index in current number . j is used to track index for next iteration . ; if num < 2 then we have to take another digit to the right of A [ i ] to make it bigger than A [ i ] . E . g . 214 \\/ 2 -- > 107 ; if it 's not the first index. E.g 214 then we have to include 0. ; for eg . \\\"124\\\" we will not write 064 so if it is the first index just ignore ; After every division by 2 the length of string is changed . ; if the string reaches to 1 then the str is a power of 2. ; Driver code .\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function isPowerOf2 ( $ str ) { $ len_str = strlen ( $ str ) ; $ num = 0 ; if ( $ len_str == 1 && $ str [ $ len_str - 1 ] == '1' ) return 0 ; while ( $ len_str != 1 $ str [ $ len_str - 1 ] != '1' ) { if ( ord ( $ str [ $ len_str - 1 ] - '0' ) % 2 == 1 ) return 0 ; $ j = 0 ; for ( $ i = 0 ; $ i < $ len_str ; $ i ++ ) { $ num = $ num * 10 + ( ord ( $ str [ $ i ] ) - ord ( '0' ) ) ; if ( $ num < 2 ) { if ( $ i != 0 ) $ str [ $ j ++ ] = '0' ; continue ; } $ str [ $ j ++ ] = chr ( ( int ) ( $ num \\/ 2 ) + ord ( '0' ) ) ; $ num = ( $ num ) - ( int ) ( $ num \\/ 2 ) * 2 ; } $ len_str = $ j ; } return 1 ; } $ str1 = \\\"124684622466842024680246842024662202000002\\\" ; $ str2 = \\\"1\\\" ; $ str3 = \\\"128\\\" ; print ( isPowerOf2 ( $ str1 ) . \\\" \\\" . isPowerOf2 ( $ str2 ) . \\\" \\\" ? > ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Print string after removing all ( \u201c 10 \u201d or \u201c 01 \u201d ) from the binary string | Java program to print the final String after removing all the occurrences of \\\"10\\\" and \\\"01\\\" from the given binary String ; Function to print the final String after removing all the occurrences of \\\"10\\\" and \\\"01\\\" from the given binary String ; Variables to store the count of 1 ' s \u2581 and \u2581 0' s ; Variable left will store whether 0 ' s \u2581 or \u2581 1' s is left in the final String ; Length of the String ; For loop to count the occurrences of 1 ' s \u2581 and \u2581 0' s in the String ; To check if the count of 1 ' s \u2581 is \u2581 \u2581 greater \u2581 than \u2581 the \u2581 count \u2581 of \u2581 0' s or not . If x is greater , then those many 1 's are printed. ; Length of the final remaining String after removing all the occurrences ; Printing the final String ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void finalString ( String str ) { int x = 0 , y = 0 ; int left ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == '1' ) x ++ ; else y ++ ; } if ( x > y ) left = 1 ; else left = 0 ; int length = n - 2 * Math . min ( x , y ) ; for ( int i = 0 ; i < length ; i ++ ) { System . out . print ( left ) ; } } public static void main ( String [ ] args ) { String str = \\\"010110100100000\\\" ; finalString ( str ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Print characters having prime frequencies in order of occurrence | C # implementation of the approach ; Function to create Sieve to check primes ; false here indicates that it is not prime ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p , set them to non - prime ; Function to print the prime frequency characters in the order of their occurrence ; Function to create Sieve to check primes ; To store the frequency of each of the character of the string ; Initialize all elements of freq [ ] to 0 ; Update the frequency of each character ; Traverse str character by character ; If frequency of current character is prime ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int SIZE = 26 ; static void SieveOfEratosthenes ( bool [ ] prime , int p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i < p_size ; i += p ) prime [ i ] = false ; } } } static void printChar ( string str , int n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) prime [ i ] = true ; SieveOfEratosthenes ( prime , str . Length + 1 ) ; int [ ] freq = new int [ SIZE ] ; for ( int i = 0 ; i < SIZE ; i ++ ) freq [ i ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) freq [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ freq [ str [ i ] - ' a ' ] ] ) { Console . Write ( str [ i ] ) ; } } } public static void Main ( String [ ] args ) { String str = \\\" geeksforgeeks \\\" ; int n = str . Length ; printChar ( str , n ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Reduce all array elements to zero by performing given operations thrice | C # program for the above approach ; Function to reduce all array elements to zero ; If size of array is 1 ; First operation ; 2 nd Operation ; 3 rd Operation ; Otherwise ; 1 st Operation ; 2 nd Operation ; 3 rd Operation ; Driver Code ; Input ; Function call to make all array elements equal to 0\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void ConvertArray ( int [ ] arr , int N ) { if ( N == 1 ) { Console . WriteLine ( \\\" Operation \u2581 1 \u2581 : \u2581 \\\" + 1 + \\\" \u2581 \\\" + 1 ) ; Console . WriteLine ( \\\" Added \u2581 elements : \u2581 \\\" + - 1 * arr [ 0 ] ) ; Console . WriteLine ( ) ; Console . WriteLine ( \\\" Operation \u2581 2 \u2581 : \u2581 \\\" + 1 + \\\" \u2581 \\\" + 1 ) ; Console . WriteLine ( \\\" Added \u2581 elements : \u2581 \\\" + 1 * arr [ 0 ] ) ; Console . WriteLine ( ) ; Console . WriteLine ( \\\" Operation \u2581 3 \u2581 : \u2581 \\\" + 1 + \\\" \u2581 \\\" + 1 ) ; Console . WriteLine ( \\\" Added \u2581 elements : \u2581 \\\" + - 1 * arr [ 0 ] ) ; } else { Console . WriteLine ( \\\" Operation \u2581 1 \u2581 : \u2581 \\\" + 1 + \\\" \u2581 \\\" + N ) ; Console . Write ( \\\" Added \u2581 elements : \u2581 \\\" ) ; for ( int i = 0 ; i < N ; i ++ ) { Console . Write ( - 1 * arr [ i ] * N + \\\" \u2581 \\\" ) ; } Console . WriteLine ( ) ; Console . WriteLine ( ) ; Console . WriteLine ( \\\" Operation \u2581 2 \u2581 : \u2581 \\\" + 1 + \\\" \u2581 \\\" + ( N - 1 ) ) ; Console . Write ( \\\" Added \u2581 elements : \u2581 \\\" ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { Console . Write ( arr [ i ] * ( N - 1 ) + \\\" \u2581 \\\" ) ; } Console . WriteLine ( ) ; Console . WriteLine ( ) ; Console . WriteLine ( \\\" Operation \u2581 3 \u2581 : \u2581 \\\" + N + \\\" \u2581 \\\" + N ) ; Console . Write ( \\\" Added \u2581 elements : \u2581 \\\" ) ; Console . WriteLine ( arr [ N - 1 ] * ( N - 1 ) ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 1 , 3 , 2 , 4 } ; int N = arr . Length ; ConvertArray ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Largest number that divides x and is co | java program to find the Largest Coprime Divisor ; Recursive function to return gcd of a and b ; Everything divides 0 ; base case ; a is greater ; function to find largest coprime divisor ; divisor code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 b == 0 ) return 0 ; if ( a == b ) return a ; if ( a > b ) return gcd ( a - b , b ) ; return gcd ( a , b - a ) ; } static int cpFact ( int x , int y ) { while ( gcd ( x , y ) != 1 ) { x = x \\/ gcd ( x , y ) ; } return x ; } public static void main ( String [ ] args ) { int x = 15 ; int y = 3 ; System . out . println ( cpFact ( x , y ) ) ; x = 14 ; y = 28 ; System . out . println ( cpFact ( x , y ) ) ; x = 7 ; y = 3 ; System . out . println ( cpFact ( x , y ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Euler zigzag numbers ( Alternating Permutation ) | CPP program to find zigzag sequence ; Function to print first n zigzag numbers ; To store factorial and n 'th zig zag number ; Initialize factorial upto n ; Set first two zig zag numbers ; Print first two zig zag number ; Print the rest zig zag numbers ; Binomial ( n , k ) * a ( k ) * a ( n - k ) ; Store the value ; Print the number ; Driver code ; Function call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void ZigZag ( int n ) { long long fact [ n + 1 ] , zig [ n + 1 ] = { 0 } ; fact [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) fact [ i ] = fact [ i - 1 ] * i ; zig [ 0 ] = 1 ; zig [ 1 ] = 1 ; cout << \\\" zig \u2581 zag \u2581 numbers : \u2581 \\\" ; cout << zig [ 0 ] << \\\" \u2581 \\\" << zig [ 1 ] << \\\" \u2581 \\\" ; for ( int i = 2 ; i < n ; i ++ ) { long long sum = 0 ; for ( int k = 0 ; k <= i - 1 ; k ++ ) { sum += ( fact [ i - 1 ] \\/ ( fact [ i - 1 - k ] * fact [ k ] ) ) * zig [ k ] * zig [ i - 1 - k ] ; } zig [ i ] = sum \\/ 2 ; cout << sum \\/ 2 << \\\" \u2581 \\\" ; } } int main ( ) { int n = 10 ; ZigZag ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Josephus Problem | ( Iterative Solution ) | Iterative solution for Josephus Problem ; Function for finding the winning child . ; For finding out the removed chairs in each iteration ; Driver function to find the winning child\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; long long int find ( long long int n , long long int k ) { long long int sum = 0 , i ; for ( i = 2 ; i <= n ; i ++ ) sum = ( sum + k ) % i ; return sum + 1 ; } int main ( ) { int n = 14 , k = 2 ; cout << find ( n , k ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if a string has all characters with same frequency with one variation allowed | C # program to check if a string can be made valid by removing at most 1 character . ; Assuming only lower case characters ; To check a string S can be converted to a valid string by removing less than or equal to one character . ; freq [ ] : stores the frequency of each character of a string ; Find first character with non - zero frequency ; Find a character with frequency different from freq1 . ; If we find a third non - zero frequency or count of both frequencies become more than 1 , then return false ; } else If we find a third non - zero freq ; If counts of both frequencies is more than 1 ; Return true if we reach here ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; public class GFG { static int CHARS = 26 ; static bool isValidString ( String str ) { int [ ] freq = new int [ CHARS ] ; int i = 0 ; for ( i = 0 ; i < str . Length ; i ++ ) { freq [ str [ i ] - ' a ' ] ++ ; } int freq1 = 0 , count_freq1 = 0 ; for ( i = 0 ; i < CHARS ; i ++ ) { if ( freq [ i ] != 0 ) { freq1 = freq [ i ] ; count_freq1 = 1 ; break ; } } int j , freq2 = 0 , count_freq2 = 0 ; for ( j = i + 1 ; j < CHARS ; j ++ ) { if ( freq [ j ] != 0 ) { if ( freq [ j ] == freq1 ) { count_freq1 ++ ; } else { count_freq2 = 1 ; freq2 = freq [ j ] ; break ; } } } for ( int k = j + 1 ; k < CHARS ; k ++ ) { if ( freq [ k ] != 0 ) { if ( freq [ k ] == freq1 ) { count_freq1 ++ ; } if ( freq [ k ] == freq2 ) { count_freq2 ++ ; { return false ; } } if ( count_freq1 > 1 && count_freq2 > 1 ) { return false ; } } return true ; } public static void Main ( ) { String str = \\\" abcbc \\\" ; if ( isValidString ( str ) ) { Console . WriteLine ( \\\" YES \\\" ) ; } else { Console . WriteLine ( \\\" NO \\\" ) ; } } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Pascal 's Triangle | PHP program for Pascal ' s \u2581 Triangle \u2581 A \u2581 O ( n ^ 2 ) \u2581 time \u2581 and \u2581 O ( 1 ) \u2581 extra \u2581 space \u2581 method \u2581 for \u2581 Pascal ' s Triangle Pascal function ; used to represent C ( line , i ) ; The first value in a line is always 1 ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function printPascal ( $ n ) { for ( $ line = 1 ; $ line <= $ n ; $ line ++ ) { $ C = 1 ; for ( $ i = 1 ; $ i <= $ line ; $ i ++ ) { print ( $ C . \\\" \\\" ) ; $ C = $ C * ( $ line - $ i ) \\/ $ i ; } print ( \\\" \\n \\\" ) ; } } $ n = 5 ; printPascal ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Geometric mean ( Two Methods ) | Program to calculate the geometric mean of the given array elements . ; function to calculate geometric mean and return float value . ; declare product variable and initialize it to 1. ; Compute the product of all the elements in the array . ; compute geometric mean through formula pow ( product , 1 \\/ n ) and return the value to main function . ; Driver function\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . math . * ; class GFG { static float geometricMean ( int arr [ ] , int n ) { float product = 1 ; for ( int i = 0 ; i < n ; i ++ ) product = product * arr [ i ] ; float gm = ( float ) Math . pow ( product , ( float ) 1 \\/ n ) ; return gm ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } ; int n = arr . length ; System . out . println ( geometricMean ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximum length L such that the sum of all subarrays of length L is less than K | C ++ implementation of the approach ; Function to return the maximum sum in a subarray of size k ; k must be greater ; Compute sum of first window of size k ; Compute sums of remaining windows by removing first element of previous window and adding last element of current window . ; Function to return the length of subarray Sum of all the subarray of this length is less than or equal to K ; Binary search from l to r as all the array elements are positive so that the maximum subarray sum is monotonically increasing ; Check if the subarray sum is greater than K or not ; Update the maximum length ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int maxSum ( int arr [ ] , int n , int k ) { if ( n < k ) { return -1 ; } int res = 0 ; for ( int i = 0 ; i < k ; i ++ ) res += arr [ i ] ; int curr_sum = res ; for ( int i = k ; i < n ; i ++ ) { curr_sum += arr [ i ] - arr [ i - k ] ; res = max ( res , curr_sum ) ; } return res ; } int solve ( int arr [ ] , int n , int k ) { int max_len = 0 , l = 0 , r = n , m ; while ( l <= r ) { m = ( l + r ) \\/ 2 ; if ( maxSum ( arr , n , m ) > k ) r = m - 1 ; else { l = m + 1 ; max_len = m ; } } return max_len ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof ( arr ) \\/ sizeof ( int ) ; int k = 10 ; cout << solve ( arr , n , k ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Number of subsets with zero sum | Python3 implementation of above approach ; variable to store states of dp ; To find the number of subsets with sum equal to 0. Since S can be negative , we will maxSum to it to make it positive ; Base cases ; Returns the value if a state is already solved ; If the state is not visited , then continue ; Recurrence relation ; Returning the value ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import numpy as np\\nmaxSum = 100\\narrSize = 51\\ndp = np . zeros ( ( arrSize , maxSum ) ) ;\\nvisit = np . zeros ( ( arrSize , maxSum ) ) ;\\ndef SubsetCnt ( i , s , arr , n ) :\\n\\tif ( i == n ) :\\n\\t\\tif ( s == 0 ) :\\n\\t\\t\\treturn 1 ;\\n\\t\\telse :\\n\\t\\t\\treturn 0 ;\\n\\tif ( visit [ i ] [ s + arrSize ] ) :\\n\\t\\treturn dp [ i ] [ s + arrSize ] ;\\n\\tvisit [ i ] [ s + arrSize ] = 1 ;\\n\\tdp [ i ] [ s + arrSize ] = ( SubsetCnt ( i + 1 , s + arr [ i ] , arr , n ) + SubsetCnt ( i + 1 , s , arr , n ) ) ;\\n\\treturn dp [ i ] [ s + arrSize ] ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ 2 , 2 , 2 , - 4 , - 4 ] ;\\n\\tn = len ( arr ) ;\\n\\tprint ( SubsetCnt ( 0 , 0 , arr , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find and Count total factors of co | Java implementation of the above approach ; Function to return the count of numbers which are divisible by both A and B in the range [ 1 , N ] in constant time ; Compute the count of numbers divisible by A in the range [ 1 , N ] ; Compute the count of numbers divisible by B in the range [ 1 , N ] ; Adding the counts which are divisible by A and B ; The above value might contain repeated values which are divisible by both A and B . Therefore , the count of numbers which are divisible by both A and B are found ; The count computed above is subtracted to compute the final count ; Function to return the sum of numbers which are divisible by both A and B in the range [ 1 , N ] ; Set to store the numbers so that the numbers are not repeated ; For loop to find the numbers which are divisible by A and insert them into the set ; For loop to find the numbers which are divisible by A and insert them into the set ; For loop to iterate through the set and find the sum ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static int countOfNum ( int n , int a , int b ) { int cnt_of_a , cnt_of_b , cnt_of_ab , sum ; cnt_of_a = n \\/ a ; cnt_of_b = n \\/ b ; sum = cnt_of_b + cnt_of_a ; cnt_of_ab = n \\/ ( a * b ) ; sum = sum - cnt_of_ab ; return sum ; } static int sumOfNum ( int n , int a , int b ) { int i ; int sum = 0 ; Set < Integer > ans = new HashSet < Integer > ( ) ; for ( i = a ; i <= n ; i = i + a ) { ans . add ( i ) ; } for ( i = b ; i <= n ; i = i + b ) { ans . add ( i ) ; } for ( Integer it : ans ) { sum = sum + it ; } return sum ; } public static void main ( String [ ] args ) { int N = 88 ; int A = 11 ; int B = 8 ; int count = countOfNum ( N , A , B ) ; int sumofnum = sumOfNum ( N , A , B ) ; System . out . print ( sumofnum % count ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimize count of increments of each element of subarrays required to make Array non | Function to find the minimum number of operations required to make the array non - increasing ; Stores the count of required operations ; If arr [ i ] > arr [ i + 1 ] , no increments required . Otherwise , add their difference to the answer ; Return the result res ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function getMinOps ( arr ) { var res = 0 ; for ( i = 0 ; i < arr . length - 1 ; i ++ ) { res += Math . max ( arr [ i + 1 ] - arr [ i ] , 0 ) ; } return res ; } var arr = [ 1 , 3 , 4 , 1 , 2 ] ; document . write ( getMinOps ( arr ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximize [ length ( X ) \\/ 2 ^ ( XOR ( X , Y ) ) ] by choosing substrings X and Y from string A and B respectively | C ++ program for the above approach ; Function to find the length of the longest common substring of the string X and Y ; LCSuff [ i ] [ j ] stores the lengths of the longest common suffixes of substrings ; Itearate over strings A and B ; If first row or column ; If matching is found ; Otherwise , if matching is not found ; Finally , return the resultant maximum value LCS ; Driver Code ; Function Call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int LCSubStr ( char * A , char * B , int m , int n ) { int LCSuff [ m + 1 ] [ n + 1 ] ; int result = 0 ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) LCSuff [ i ] [ j ] = 0 ; else if ( A [ i - 1 ] == B [ j - 1 ] ) { LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1 ; result = max ( result , LCSuff [ i ] [ j ] ) ; } else LCSuff [ i ] [ j ] = 0 ; } } return result ; } int main ( ) { char A [ ] = \\\"0110\\\" ; char B [ ] = \\\"1101\\\" ; int M = strlen ( A ) ; int N = strlen ( B ) ; cout << LCSubStr ( A , B , M , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Split N powers of 2 into two subsets such that their difference of sum is minimum | Java program to find the minimum difference possible by splitting all powers of 2 up to N into two sets of equal size ; Store the largest ; Form two separate groups ; Initialize the sum for two groups as 0 ; Insert 2 ^ n in the first group ; Calculate the sum of least n \\/ 2 - 1 elements added to the first set ; Sum of remaining n \\/ 2 - 1 elements ; Min difference between the two groups ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . lang . Math ; class GFG { public static void MinDiff ( int n ) { int val = ( int ) Math . pow ( 2 , n ) ; int sep = n \\/ 2 ; int grp1 = 0 ; int grp2 = 0 ; grp1 = grp1 + val ; for ( int i = 1 ; i < sep ; i ++ ) grp1 = grp1 + ( int ) Math . pow ( 2 , i ) ; for ( int i = sep ; i < n ; i ++ ) grp2 = grp2 + ( int ) Math . pow ( 2 , i ) ; System . out . println ( Math . abs ( grp1 - grp2 ) ) ; } public static void main ( String args [ ] ) { int n = 4 ; MinDiff ( n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Write a program to calculate pow ( x , n ) | Function to calculate x raised to the power y in O ( logn )\\nHow can the above be solved in C?\",\"targets\":\"int power ( int x , unsigned int y ) { int temp ; if ( y == 0 ) return 1 ; temp = power ( x , y \\/ 2 ) ; if ( y % 2 == 0 ) return temp * temp ; else return x * temp * temp ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of ways to pair people | Function to find number of ways to pair people in party ; To store count of number of ways . ; Using the recurrence defined find count for different values of p . ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findWaysToPair ( $ p ) { $ dp = array ( ) ; $ dp [ 1 ] = 1 ; $ dp [ 2 ] = 2 ; for ( $ i = 3 ; $ i <= $ p ; $ i ++ ) { $ dp [ $ i ] = $ dp [ $ i - 1 ] + ( $ i - 1 ) * $ dp [ $ i - 2 ] ; } return $ dp [ $ p ] ; } $ p = 3 ; echo findWaysToPair ( $ p ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Probability of rain on N + 1 th day | Function to find the probability ; count 1 ; find probability ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function rainDayProbability ( a , n ) { let count = 0 , m ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 1 ) count ++ ; } m = count \\/ n ; return m ; } let a = [ 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 ] ; let n = a . length ; document . write ( rainDayProbability ( a , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if all occurrences of a character appear together | To indicate if one or more occurrences of ' c ' are seen or not . ; Traverse given string ; If current character is same as c , we first check if c is already seen . ; If this is very first appearance of c , we traverse all consecutive occurrences . ; To indicate that character is seen once . ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php $ oneSeen = false ; $ i = 0 ; $ n = strlen ( $ s ) ; while ( $ i < $ n ) { if ( $ s [ $ i ] == $ c ) { if ( $ oneSeen == true ) return false ; while ( $ i < $ n && $ s [ $ i ] == $ c ) $ i ++ ; $ oneSeen = true ; } else $ i ++ ; } return true ; } $ s = \\\"110029\\\" ; if ( checkIfAllTogether ( $ s , '1' ) ) echo ( \\\" Yes \\n \\\" ) ; else echo ( \\\" No \\n \\\" ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Permutation Coefficient | A O ( n ) time and O ( 1 ) extra space PHP solution to calculate the Permutation Coefficient ; Compute n ! and ( n - k ) ! ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function PermutationCoeff ( $ n , $ k ) { $ Fn = 1 ; $ Fk ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ Fn *= $ i ; if ( $ i == $ n - $ k ) $ Fk = $ Fn ; } $ coeff = $ Fn \\/ $ Fk ; return $ coeff ; } $ n = 10 ; $ k = 2 ; echo \\\" Value \u2581 of \u2581 P ( \\\" , $ n , \\\" , \u2581 \\\" , $ k , \\\" ) \\n \\t \\t is \u2581 \\\" , PermutationCoeff ( $ n , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the smallest missing number | C # program to find the smallest elements missing in a sorted array . ; function that returns smallest elements missing in a sorted array . ; Left half has all elements from 0 to mid ; Driver program to test the above function\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int findFirstMissing ( int [ ] array , int start , int end ) { if ( start > end ) return end + 1 ; if ( start != array [ start ] ) return start ; int mid = ( start + end ) \\/ 2 ; if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ; return findFirstMissing ( array , start , mid ) ; } public static void Main ( ) { int [ ] arr = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 10 } ; int n = arr . Length ; Console . Write ( \\\" smallest \u2581 Missing \u2581 element \u2581 is \u2581 : \u2581 \\\" + findFirstMissing ( arr , 0 , n - 1 ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Largest palindromic number in an array | Function to check if n is palindrome ; Find the appropriate divisor to extract the leading digit ; If first and last digits are not same then return false ; Removing the leading and trailing digits from the number ; Reducing divisor by a factor of 2 as 2 digits are dropped ; Function to find the largest palindromic number ; If a palindrome larger than the currentMax is found ; Return the largest palindromic number from the array ; Driver Code ; print required answer\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function isPalindrome ( $ n ) { $ divisor = 1 ; while ( ( int ) ( $ n \\/ $ divisor ) >= 10 ) $ divisor *= 10 ; while ( $ n != 0 ) { $ leading = ( int ) ( $ n \\/ $ divisor ) ; $ trailing = $ n % 10 ; if ( $ leading != $ trailing ) return false ; $ n = ( $ n % $ divisor ) \\/ 10 ; $ divisor = $ divisor \\/ 100 ; } return true ; } function largestPalindrome ( $ A , $ n ) { $ currentMax = -1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ A [ $ i ] > $ currentMax && isPalindrome ( $ A [ $ i ] ) ) $ currentMax = $ A [ $ i ] ; } return $ currentMax ; } $ A = array ( 1 , 232 , 54545 , 999991 ) ; $ n = sizeof ( $ A ) ; echo ( largestPalindrome ( $ A , $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if sum of digits of a number exceeds the product of digits of that number | Function to check if the sum of the digits of N is strictly greater than the product of the digits of N or not ; Stores the sum and the product of the digits of N ; Stores the last digit if N ; Increment the value of sumOfDigits ; Update the prodOfDigit ; Divide N by 10 ; Print the result ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def check ( n ) :\\n\\tsumOfDigit = 0\\n\\tprodOfDigit = 1\\n\\twhile n > 0 :\\n\\t\\trem = n % 10\\n\\t\\tsumOfDigit += rem\\n\\t\\tprodOfDigit *= rem\\n\\t\\tn = n \\/\\/ 10\\n\\tif sumOfDigit > prodOfDigit :\\n\\t\\tprint ( \\\" Yes \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\\nN = 1234\\ncheck ( N )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Numbers in range [ L , R ] such that the count of their divisors is both even and prime | C # implementation of the approach ; stores whether the number is prime or not ; stores the count of prime numbers less than or equal to the index ; create the sieve ; Create a boolean array \\\" prime [ 0 . . n ] \\\" and initialize all the entries as true . A value in prime [ i ] will finally be false if ' i ' is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; stores the prefix sum of number of primes less than or equal to ' i ' ; Driver code ; create the sieve ; ' l ' and ' r ' are the lower and upper bounds of the range ; get the value of count ; display the count\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int MAX = 1000000 ; static bool [ ] prime = new bool [ MAX + 1 ] ; static int [ ] sum = new int [ MAX + 1 ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i <= MAX ; i ++ ) prime [ i ] = true ; for ( int i = 0 ; i <= MAX ; i ++ ) sum [ i ] = 0 ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } for ( int i = 1 ; i <= MAX ; i ++ ) { if ( prime [ i ] == true ) sum [ i ] = 1 ; sum [ i ] += sum [ i - 1 ] ; } } public static void Main ( ) { SieveOfEratosthenes ( ) ; int l = 3 , r = 9 ; int c = ( sum [ r ] - sum [ l - 1 ] ) ; Console . WriteLine ( \\\" Count : \u2581 \\\" + c ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Wheel Factorization Algorithm | Java program to check if the given number is prime using Wheel Factorization Method ; Function to check if a given number x is prime or not ; The Wheel for checking prime number ; Base Case ; Check for the number taken as basis ; Check for Wheel Here i , acts as the layer of the wheel ; Check for the list of Sieve in arr [ ] ; If number is greater than sqrt ( N ) break ; Check if N is a multiple of prime number in the wheel ; If at any iteration isPrime is false , break from the loop ; Driver 's Code ; Function call for primality check\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void isPrime ( int N ) { boolean isPrime = true ; int [ ] arr = { 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 } ; if ( N < 2 ) { isPrime = false ; } if ( N % 2 == 0 N % 3 == 0 N % 5 == 0 ) { isPrime = false ; } for ( int i = 0 ; i < Math . sqrt ( N ) ; i += 30 ) { for ( int c : arr ) { if ( c > Math . sqrt ( N ) ) { break ; } else { if ( N % ( c + i ) == 0 ) { isPrime = false ; break ; } } if ( ! isPrime ) break ; } } if ( isPrime ) System . out . println ( \\\" Prime \u2581 Number \\\" ) ; else System . out . println ( \\\" Not \u2581 a \u2581 Prime \u2581 Number \\\" ) ; } public static void main ( String args [ ] ) { int N = 121 ; isPrime ( N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimize total time taken by two persons to visit N cities such that none of them meet | C ++ program for the above approach ; Function to find the minimum time to visit all the cities such that both the person never meets ; Initialize sum as 0 ; Find the maximum element ; Traverse the array ; Increment sum by arr [ i ] ; Print maximum of 2 * T and sum ; Driver Code ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void minimumTime ( int * arr , int n ) { int sum = 0 ; int T = * max_element ( arr , arr + n ) ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } cout << max ( 2 * T , sum ) ; } int main ( ) { int arr [ ] = { 2 , 8 , 3 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; minimumTime ( arr , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Reorder an array such that sum of left half is not equal to sum of right half | C program for the above approach ; A comparator function used by qsort ; Function to print the required reordering of array if possible ; Sort the array in increasing order ; If all elements are equal , then it is not possible ; Else print the sorted array arr [ ] ; Driver Code ; Given array ; Function call\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nint compare ( const void * a , const void * b ) { return ( * ( int * ) a - * ( int * ) b ) ; } void printArr ( int arr [ ] , int n ) { qsort ( arr , n , sizeof ( int ) , compare ) ; if ( arr [ 0 ] == arr [ n - 1 ] ) { printf ( \\\" No \\n \\\" ) ; } else { printf ( \\\" Yes \\n \\\" ) ; for ( int i = 0 ; i < n ; i ++ ) { printf ( \\\" % d \u2581 \\\" , arr [ i ] ) ; } } } int main ( ) { int arr [ ] = { 1 , 2 , 2 , 1 , 3 , 1 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printArr ( arr , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find the last two missing digits of the given phone number | Function to find the last two digits of the number and print the complete number ; Sum of the first eight digits of the number ; if sum < 10 , then the two digits are '0' and the value of sum ; if sum > 10 , then the two digits are the value of sum ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def findPhoneNumber ( n ) :\\n\\ttemp = n\\n\\tsum = 0\\n\\twhile ( temp != 0 ) :\\n\\t\\tsum += temp % 10\\n\\t\\ttemp = temp \\/\\/ 10\\n\\tif ( sum < 10 ) :\\n\\t\\tprint ( n , \\\"0\\\" , sum )\\n\\telse :\\n\\t\\tn = str ( n )\\n\\t\\tsum = str ( sum )\\n\\t\\tn += sum\\n\\t\\tprint ( n )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tn = 98765432\\n\\tfindPhoneNumber ( n )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find the value of f ( n ) \\/ f ( r ) * f ( n | Function to find value of given F ( n ) ; iterate over n ; calculate result ; return the result ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function calcFunction ( $ n , $ r ) { $ finalDenominator = 1 ; $ mx = max ( $ r , $ n - $ r ) ; for ( $ i = $ mx + 1 ; $ i <= $ n ; $ i ++ ) { $ denominator = pow ( $ i , $ i ) ; $ numerator = pow ( $ i - $ mx , $ i - $ mx ) ; $ finalDenominator = ( $ finalDenominator * $ denominator ) \\/ $ numerator ; } return $ finalDenominator ; } $ n = 6 ; $ r = 2 ; echo \\\"1 \\/ \\\" , calcFunction ( $ n , $ r ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Given a string and an integer k , find the kth sub | Java implementation of the approach ; Function to prints kth sub - string ; Total sub - strings possible ; If k is greater than total number of sub - strings ; To store number of sub - strings starting with ith character of the string ; Compute the values ; substring [ i - 1 ] is added to store the cumulative sum ; Binary search to find the starting index of the kth sub - string ; To store the ending index of the kth sub - string ; Print the sub - string ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static void Printksubstring ( String str , int n , int k ) { int total = ( n * ( n + 1 ) ) \\/ 2 ; if ( k > total ) { System . out . printf ( \\\"-1\\n\\\"); return ; } int substring [ ] = new int [ n + 1 ] ; substring [ 0 ] = 0 ; int temp = n ; for ( int i = 1 ; i <= n ; i ++ ) { substring [ i ] = substring [ i - 1 ] + temp ; temp -- ; } int l = 1 ; int h = n ; int start = 0 ; while ( l <= h ) { int m = ( l + h ) \\/ 2 ; if ( substring [ m ] > k ) { start = m ; h = m - 1 ; } else if ( substring [ m ] < k ) { l = m + 1 ; } else { start = m ; break ; } } int end = n - ( substring [ start ] - k ) ; for ( int i = start - 1 ; i < end ; i ++ ) { System . out . print ( str . charAt ( i ) ) ; } } public static void main ( String [ ] args ) { String str = \\\" abc \\\" ; int k = 4 ; int n = str . length ( ) ; Printksubstring ( str , n , k ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Majority Element | C ++ program to find Majority element in an array ; Function to find Majority element in an array it returns - 1 if there is no majority element ; sort the array in O ( nlogn ) ; increases the count if the same element occurs otherwise starts counting new element ; sets maximum count and stores maximum occured element so far if maximum count becomes greater than n \\/ 2 it breaks out setting the flag ; returns maximum occured element if there is no such element , returns - 1 ; Driver code ; Function calling\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int majorityElement ( int * arr , int n ) { sort ( arr , arr + n ) ; int count = 1 , max_ele = -1 , temp = arr [ 0 ] , ele , f = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( temp == arr [ i ] ) { count ++ ; } else { count = 1 ; temp = arr [ i ] ; } if ( max_ele < count ) { max_ele = count ; ele = arr [ i ] ; if ( max_ele > ( n \\/ 2 ) ) { f = 1 ; break ; } } } return ( f == 1 ? ele : -1 ) ; } int main ( ) { int arr [ ] = { 1 , 1 , 2 , 1 , 3 , 5 , 1 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << majorityElement ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Program to find parity | C program to find parity of an integer ; Function to get parity of number n . It returns 1 if n has odd parity , and returns 0 if n has even parity ; Driver program to test getParity ( )\\nHow can the above be solved in C?\",\"targets\":\"# include \\n# define bool int\\nbool getParity ( unsigned int n ) { bool parity = 0 ; while ( n ) { parity = ! parity ; n = n & ( n - 1 ) ; } return parity ; } int main ( ) { unsigned int n = 7 ; printf ( \\\" Parity \u2581 of \u2581 no \u2581 % d \u2581 = \u2581 % s \\\" , n , ( getParity ( n ) ? \\\" odd \\\" : \\\" even \\\" ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"How to print maximum number of A 's using given four keys | This function returns the optimal length string for N keystrokes ; The optimal string length is N when N is smaller than 7 ; An array to store result of subproblems ; To pick a breakpoint ; Initializing the optimal lengths array for uptil 6 input strokes ; Solve all subproblems in bottom manner ; Initialize length of optimal string for n keystrokes ; For any keystroke n , we need to loop from n - 3 keystrokes back to 1 keystroke to find a breakpoint ' b ' after which we will have ctrl - a , ctrl - c and then only ctrl - v all the way . ; If the breakpoint is at b 'th keystroke then the optimal string would have length (n-b-1)*screen[b-1]; ; Driver code ; for the rest of the array we will rely on the previous entries to compute new ones\\\"\\nSolution in Javascript:\",\"targets\":\"function findoptimal ( N ) { if ( N <= 6 ) return N ; let screen = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { screen [ i ] = 0 ; } let b ; let n ; for ( n = 1 ; n <= 6 ; n ++ ) screen [ n - 1 ] = n ; for ( n = 7 ; n <= N ; n ++ ) { screen [ n - 1 ] = 0 ; for ( b = n - 3 ; b >= 1 ; b -- ) { let curr = ( n - b - 1 ) * screen [ b - 1 ] ; if ( curr > screen [ n - 1 ] ) screen [ n - 1 ] = curr ; } } return screen [ N - 1 ] ; } let N ; for ( N = 1 ; N <= 20 ; N ++ ) document . write ( \\\" \\\" + N + \\\" \\\" + findoptimal ( N ) + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Rearrange the string to maximize the number of palindromic substrings | C # program to rearrange the string such to maximize the number of palindromic substrings ; Function to return the newString ; length of string ; hashing array ; iterate and count ; resulting string ; form the resulting string ; number of times character appears ; append to resulting string ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static String newString ( string s ) { int l = s . Length ; int [ ] freq = new int [ 26 ] ; for ( int i = 0 ; i < l ; i ++ ) { freq [ s [ i ] - ' a ' ] += 1 ; } string ans = \\\" \\\" ; for ( int i = 0 ; i < 26 ; i ++ ) { for ( int j = 0 ; j < freq [ i ] ; j ++ ) { ans += ( char ) ( 97 + i ) ; } } return ans ; } public static void Main ( ) { string s = \\\" aabab \\\" ; Console . Write ( newString ( s ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to reach a score using 1 and 2 with no consecutive 2 s | A simple recursive implementation for counting ways to reach a score using 1 and 2 with consecutive 2 allowed ; base case ; For cases n > 2 ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def CountWays ( n ) :\\n\\tif n == 0 :\\n\\t\\treturn 1\\n\\tif n == 1 :\\n\\t\\treturn 1\\n\\tif n == 2 :\\n\\t\\treturn 1 + 1\\n\\treturn CountWays ( n - 1 ) + CountWays ( n - 3 )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tn = 5\\n\\tprint ( CountWays ( n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find the total number of composite factor for a given number | Function to return the count of prime factors of n ; Initialise array with 0 ; Stored i value into an array ; Every non - zero value at a [ i ] denotes that i is a factor of n ; Find if i is prime ; If i is a factor of n and i is not prime ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def composite_factors ( n ) :\\n\\tcount = 0 ;\\n\\ta = [ 0 ] * ( n + 1 ) ;\\n\\tfor i in range ( 1 , n + 1 ) :\\n\\t\\tif ( n % i == 0 ) :\\n\\t\\t\\ta [ i ] = i ;\\n\\tfor i in range ( 2 , n + 1 ) :\\n\\t\\tj = 2 ;\\n\\t\\tp = 1 ;\\n\\t\\twhile ( j < a [ i ] ) :\\n\\t\\t\\tif ( a [ i ] % j == 0 ) :\\n\\t\\t\\t\\tp = 0 ;\\n\\t\\t\\t\\tbreak ;\\n\\t\\t\\tj += 1 ;\\n\\t\\tif ( p == 0 and a [ i ] != 0 ) :\\n\\t\\t\\tcount += 1 ;\\n\\treturn count ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tn = 100 ;\\n\\tprint ( composite_factors ( n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Print all strings from given array that can be typed using keys from a single row of a QWERTY keyboard | C ++ program to implement the above approach ; Function to print all strings that can be typed using keys of a single row in a QWERTY Keyboard ; Stores row number of all possible character of the strings ; Traverse the array ; If current string is not an empty string ; Sets true \\/ false if a string can be typed using keys of a single row or not ; Stores row number of the first character of current string ; Stores length of word ; Traverse current string ; If current character can 't be typed using keys of rowNum only ; Update flag ; If current string can be typed using keys from rowNum only ; Print the string ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void findWordsSameRow ( vector < string > & arr ) { unordered_map < char , int > mp { { ' q ' , 1 } , { ' w ' , 1 } , { ' e ' , 1 } , { ' r ' , 1 } , { ' t ' , 1 } , { ' y ' , 1 } , { ' u ' , 1 } , { ' o ' , 1 } , { ' p ' , 1 } , { ' i ' , 1 } , { ' a ' , 2 } , { ' s ' , 2 } , { ' d ' , 2 } , { ' f ' , 2 } , { ' g ' , 2 } , { ' h ' , 2 } , { ' j ' , 2 } , { ' k ' , 2 } , { ' l ' , 2 } , { ' z ' , 3 } , { ' x ' , 3 } , { ' c ' , 3 } , { ' v ' , 3 } , { ' b ' , 3 } , { ' n ' , 3 } , { ' m ' , 3 } } ; for ( auto word : arr ) { if ( ! word . empty ( ) ) { bool flag = true ; int rowNum = mp [ tolower ( word [ 0 ] ) ] ; int M = word . length ( ) ; for ( int i = 1 ; i < M ; i ++ ) { if ( mp [ tolower ( word [ i ] ) ] != rowNum ) { flag = false ; break ; } } if ( flag ) { cout << word << \\\" \u2581 \\\" ; } } } } int main ( ) { vector < string > words = { \\\" Yeti \\\" , \\\" Had \\\" , \\\" GFG \\\" , \\\" comment \\\" } ; findWordsSameRow ( words ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count of pairs having each element equal to index of the other from an Array | Function to print the count of pair ; Iterate over all the elements of the array ; Increment the count ; Print the result ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function countPairs ( N , arr ) { let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( i == arr [ arr [ i ] - 1 ] - 1 ) { count ++ ; } } document . write ( count \\/ 2 ) ; } let arr = [ 2 , 1 , 4 , 3 ] ; let N = arr . length ; countPairs ( N , arr ) ; let arr = [ 2 , 1 , 4 , 3 ] ; let N = arr . length ; countPairs ( N , arr ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sum of elements in an array having composite frequency | Python3 program to find sum of elements in an array having composite frequency ; Function to create Sieve to check primes ; If composite [ p ] is not changed , then it is a prime ; Update all multiples of p , set them to composite ; Function to return the sum of elements in an array having composite frequency ; Map is used to store element frequencies ; To store sum ; Traverse the map using iterators ; Count the number of elements having composite frequencies ; Driver code ; Function call\\\"\\nSolution in Python:\",\"targets\":\"N = 100005\\ndef SieveOfEratosthenes ( composite ) :\\n\\tfor p in range ( 2 , N ) :\\n\\t\\tif p * p > N :\\n\\t\\t\\tbreak\\n\\t\\tif ( composite [ p ] == False ) :\\n\\t\\t\\tfor i in range ( 2 * p , N , p ) :\\n\\t\\t\\t\\tcomposite [ i ] = True\\ndef sumOfElements ( arr , n ) :\\n\\tcomposite = [ False ] * N\\n\\tSieveOfEratosthenes ( composite )\\n\\tm = dict ( ) ;\\n\\tfor i in range ( n ) :\\n\\t\\tm [ arr [ i ] ] = m . get ( arr [ i ] , 0 ) + 1\\n\\tsum = 0\\n\\tfor it in m :\\n\\t\\tif ( composite [ m [ it ] ] ) :\\n\\t\\t\\tsum += ( it )\\n\\treturn sum\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 1 , 2 , 1 , 1 , 1 , 3 , 3 , 2 , 4 ]\\n\\tn = len ( arr )\\n\\tprint ( sumOfElements ( arr , n ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count of subsets having sum of min and max element less than K | C ++ program to print count of subsets S such that min ( S ) + max ( S ) < K ; Function that return the count of subset such that min ( S ) + max ( S ) < K ; Sorting the array ; ans stores total number of subsets ; add all possible subsets between i and j ; Decrease the sum ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int get_subset_count ( int arr [ ] , int K , int N ) { sort ( arr , arr + N ) ; int left , right ; left = 0 ; right = N - 1 ; int ans = 0 ; while ( left <= right ) { if ( arr [ left ] + arr [ right ] < K ) { ans += 1 << ( right - left ) ; left ++ ; } else { right -- ; } } return ans ; } int main ( ) { int arr [ ] = { 2 , 4 , 5 , 7 } ; int K = 8 ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << get_subset_count ( arr , K , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to check if N is a Pentagonal Number | Function to determine if N is pentagonal or not . ; Substitute values of i in the formula . ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function isPentagonal ( int $ N ) { $ i = 1 ; $ M ; do { $ M = ( 3 * $ i * $ i - $ i ) \\/ 2 ; $ i += 1 ; } while ( $ M < $ N ) ; return ( $ M == $ N ) ; } $ N = 12 ; if ( isPentagonal ( $ N ) ) echo $ N , \\\" \u2581 is \u2581 pentagonal \u2581 \\\" ; else echo $ N , \\\" \u2581 is \u2581 not \u2581 pentagonal \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Recursive program to replace all occurrences of pi with 3.14 in a given string | A simple recursive approach to replace all pi in a given function with \\\"3.14\\\" . Firstly function is declared we don 't need any helper function one function is enough ; Base case if s is empty or length of s is 1 return the s ; If the 0 th and 1 st element of s are p and i we have to handle them for rest we have to call recursion it will give the result ; Smalloutput is a variable used to store recursion result ; And we have to add the recursion result with the first part we handled and return the answer ; If 1 st & 2 nd element aren 't \\\"p\\\" & \\\"i\\\", then keep 1st index as it is & call recursion for rest of the string. ; Driver code ; Function call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function replacePi ( s ) { if ( s . length == 0 s . length == 1 ) return s ; if ( s [ 0 ] == ' ' && s [ 1 ] == ' ' ) { let smallOutput = replacePi ( s . substr ( 2 ) ) ; return \\\" \\\" + smallOutput ; } else { return s [ 0 ] + replacePi ( s . substr ( 1 ) ) ; } } let s = \\\" \\\" ; let result = replacePi ( s ) ; document . write ( result ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimize maximum difference between adjacent elements possible by removing a single array element | Function to find maximum difference between adjacent array elements ; Store the maximum difference ; Traverse the array ; Update maximum difference ; Function to calculate the minimum of maximum difference between adjacent array elements possible by removing a single array element ; Stores the required minimum ; Stores the updated array ; Skip the i - th element ; Update MinValue ; return MinValue ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function maxAdjacentDifference ( A ) { let diff = 0 ; for ( let i = 1 ; i < A . length ; i ++ ) { diff = Math . max ( diff , A [ i ] - A [ i - 1 ] ) ; } return diff ; } function MinimumValue ( arr , N ) { let MinValue = Number . MAX_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { let new_arr = [ ] ; for ( let j = 0 ; j < N ; j ++ ) { if ( i == j ) continue ; new_arr . push ( arr [ j ] ) ; } MinValue = Math . min ( MinValue , maxAdjacentDifference ( new_arr ) ) ; } return MinValue ; } let arr = [ 1 , 3 , 7 , 8 ] ; let N = arr . length ; document . write ( MinimumValue ( arr , N ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Print indices of array elements whose removal makes the sum of odd and even | C # program to implement the above approach ; Function to find indices of array elements whose removal makes the sum of odd and even indexed array elements equal ; Stores size of array ; Store prefix sum of odd index array elements ; Store prefix sum of even index array elements ; Update even [ 0 ] ; Traverse the given array ; Update odd [ i ] ; Update even [ i ] ; If the current index is an even number ; Update even [ i ] ; If the current index is an odd number ; Update odd [ i ] ; Check if at least one index found or not that satisfies the condition ; Store odd indices sum by removing 0 - th index ; Store even indices sum by removing 0 - th index ; If p and q are equal ; Traverse the array arr [ ] ; If i is an even number ; Update p by removing the i - th element ; Update q by removing the i - th element ; Update q by removing the i - th element ; Update p by removing the i - th element ; If odd index values sum is equal to even index values sum ; Set the find variable ; Print the current index ; If no index found ; Print not possible ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void removeIndicesToMakeSumEqual ( int [ ] arr ) { int N = arr . Length ; int [ ] odd = new int [ N ] ; int [ ] even = new int [ N ] ; even [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { odd [ i ] = odd [ i - 1 ] ; even [ i ] = even [ i - 1 ] ; if ( i % 2 == 0 ) { even [ i ] += arr [ i ] ; } else { odd [ i ] += arr [ i ] ; } } bool find = false ; int p = odd [ N - 1 ] ; int q = even [ N - 1 ] - arr [ 0 ] ; if ( p == q ) { Console . Write ( \\\"0 \u2581 \\\" ) ; find = true ; } for ( int i = 1 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { p = even [ N - 1 ] - even [ i - 1 ] - arr [ i ] + odd [ i - 1 ] ; q = odd [ N - 1 ] - odd [ i - 1 ] + even [ i - 1 ] ; } else { q = odd [ N - 1 ] - odd [ i - 1 ] - arr [ i ] + even [ i - 1 ] ; p = even [ N - 1 ] - even [ i - 1 ] + odd [ i - 1 ] ; } if ( p == q ) { find = true ; Console . Write ( i + \\\" \u2581 \\\" ) ; } } if ( ! find ) { Console . Write ( - 1 ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 1 , 6 , 2 } ; removeIndicesToMakeSumEqual ( arr ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"How to swap two numbers without using a temporary variable ? | C program to implement the above approach ; Swap function ; Driver code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nvoid swap ( int * xp , int * yp ) { * xp = * xp ^ * yp ; * yp = * xp ^ * yp ; * xp = * xp ^ * yp ; } int main ( ) { int x = 10 ; swap ( & x , & x ) ; printf ( \\\" After \u2581 swap ( & x , \u2581 & x ) : \u2581 x \u2581 = \u2581 % d \\\" , x ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Elements that occurred only once in the array | C ++ implementation of above approach ; Function to find the elements that appeared only once in the array ; Sort the array ; Check for first element ; Check for all the elements if it is different its adjacent elements ; Check for the last element ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void occurredOnce ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; if ( arr [ 0 ] != arr [ 1 ] ) cout << arr [ 0 ] << \\\" \u2581 \\\" ; for ( int i = 1 ; i < n - 1 ; i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i - 1 ] ) cout << arr [ i ] << \\\" \u2581 \\\" ; if ( arr [ n - 2 ] != arr [ n - 1 ] ) cout << arr [ n - 1 ] << \\\" \u2581 \\\" ; } int main ( ) { int arr [ ] = { 7 , 7 , 8 , 8 , 9 , 1 , 1 , 4 , 2 , 2 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; occurredOnce ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"gOOGLE cASE of a given sentence | PHP program to convert a sentence to gOOGLE cASE . ; empty strings ; convert input to upper case ; checki if character is not a space and adding it to $w ; converting first character to lower case and subsequent initial letter of another word to lower case ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function convert ( $ str ) { $ w = \\\" \\\" ; $ z = \\\" \\\" ; $ str = strtoupper ( $ str ) . \\\" \u2581 \\\" ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) { $ ch = $ str [ $ i ] ; if ( $ ch != ' \u2581 ' ) $ w = $ w . $ ch ; else { $ z = $ z . strtolower ( $ w [ 0 ] ) . substr ( $ w , 1 ) . \\\" \u2581 \\\" ; $ w = \\\" \\\" ; } } return $ z ; } $ str = \\\" I \u2581 got \u2581 intern \u2581 at \u2581 geeksforgeeks \\\" ; echo ( convert ( $ str ) ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Euler 's criterion (Check if square root under modulo p exists) | A Simple C # program to check if square root of a number under modulo p exists or not ; Returns true if square root of n under modulo p exists ; One by one check all numbers from 2 to p - 1 ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static bool squareRootExists ( int n , int p ) { n = n % p ; for ( int x = 2 ; x < p ; x ++ ) if ( ( x * x ) % p == n ) return true ; return false ; } public static void Main ( ) { int p = 7 ; int n = 2 ; if ( squareRootExists ( n , p ) ) Console . WriteLine ( \\\" Yes \\\" ) ; else Console . WriteLine ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"Longest Arithmetic Progression | DP | The function returns true if there exist three elements in AP Assumption : set [ 0. . n - 1 ] is sorted . The code strictly implements the algorithm provided in the reference . ; One by fix every element as middle element ; Initialize i and k for the current j ; Find if there exist i and k that form AP with j as middle element\\nHow can the above be solved in C?\",\"targets\":\"bool arithmeticThree ( int set [ ] , int n ) { for ( int j = 1 ; j < n - 1 ; j ++ ) { int i = j - 1 , k = j + 1 ; while ( i >= 0 && k <= n - 1 ) { if ( set [ i ] + set [ k ] == 2 * set [ j ] ) return true ; ( set [ i ] + set [ k ] < 2 * set [ j ] ) ? k ++ : i -- ; } } return false ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if a given Binary Tree is Heap | C ++ program to checks if a binary tree is max heap or not ; Tree node structure ; To add a new node ; Driver code ; Function call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; } ; struct Node * newNode ( int k ) { struct Node * node = new Node ; node -> data = k ; node -> right = node -> left = NULL ; return node ; } bool isHeap ( Node * root ) { queue < Node * > q ; q . push ( root ) ; bool nullish = false ; while ( ! q . empty ( ) ) { Node * temp = q . front ( ) ; q . pop ( ) ; if ( temp -> left ) { if ( nullish temp -> left -> data > = temp -> data ) { return false ; } q . push ( temp -> left ) ; } else { nullish = true ; } if ( temp -> right ) { if ( nullish temp -> right -> data > = temp -> data ) { return false ; } q . push ( temp -> right ) ; } else { nullish = true ; } } return true ; } int main ( ) { struct Node * root = NULL ; root = newNode ( 10 ) ; root -> left = newNode ( 9 ) ; root -> right = newNode ( 8 ) ; root -> left -> left = newNode ( 7 ) ; root -> left -> right = newNode ( 6 ) ; root -> right -> left = newNode ( 5 ) ; root -> right -> right = newNode ( 4 ) ; root -> left -> left -> left = newNode ( 3 ) ; root -> left -> left -> right = newNode ( 2 ) ; root -> left -> right -> left = newNode ( 1 ) ; if ( isHeap ( root ) ) cout << \\\" Given \u2581 binary \u2581 tree \u2581 is \u2581 a \u2581 Heap \\n \\\" ; else cout << \\\" Given \u2581 binary \u2581 tree \u2581 is \u2581 not \u2581 a \u2581 Heap \\n \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if a String contains any index with more than K active characters | Java program to implement the above approach ; Function to check if any index contains more than K active characters ; Store the last occurrence of each character in the map . ; Stores the active characters ; Insert the character ; If the size of set exceeds K ; Remove the character from set if i is the last index of the current character ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static String checkString ( String s , int K ) { int n = s . length ( ) ; Map < Character , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mp . put ( s . charAt ( i ) , i ) ; } int cnt = 0 , f = 0 ; Set < Character > st = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { st . add ( s . charAt ( i ) ) ; if ( st . size ( ) > K ) { f = 1 ; break ; } if ( mp . get ( s . charAt ( i ) ) == i ) st . remove ( s . charAt ( i ) ) ; } return ( f == 1 ? \\\" Yes \\\" : \\\" No \\\" ) ; } public static void main ( String [ ] args ) { String s = \\\" aabbcdca \\\" ; int k = 2 ; System . out . println ( checkString ( s , k ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find Corners of Rectangle using mid points | C ++ program to find corner points of a rectangle using given length and middle points . ; Structure to represent a co - ordinate point ; This function receives two points and length of the side of rectangle and prints the 4 corner points of the rectangle ; horizontal rectangle ; vertical rectangle ; slanted rectangle ; calculate slope of the side ; calculate displacements along axes ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; struct Point { float x , y ; Point ( ) { x = y = 0 ; } Point ( float a , float b ) { x = a , y = b ; } } ; void printCorners ( Point p , Point q , float l ) { Point a , b , c , d ; if ( p . x == q . x ) { a . x = p . x - ( l \\/ 2.0 ) ; a . y = p . y ; d . x = p . x + ( l \\/ 2.0 ) ; d . y = p . y ; b . x = q . x - ( l \\/ 2.0 ) ; b . y = q . y ; c . x = q . x + ( l \\/ 2.0 ) ; c . y = q . y ; } else if ( p . y == q . y ) { a . y = p . y - ( l \\/ 2.0 ) ; a . x = p . x ; d . y = p . y + ( l \\/ 2.0 ) ; d . x = p . x ; b . y = q . y - ( l \\/ 2.0 ) ; b . x = q . x ; c . y = q . y + ( l \\/ 2.0 ) ; c . x = q . x ; } else { float m = ( p . x - q . x ) \\/ float ( q . y - p . y ) ; float dx = ( l \\/ sqrt ( 1 + ( m * m ) ) ) * 0.5 ; float dy = m * dx ; a . x = p . x - dx ; a . y = p . y - dy ; d . x = p . x + dx ; d . y = p . y + dy ; b . x = q . x - dx ; b . y = q . y - dy ; c . x = q . x + dx ; c . y = q . y + dy ; } cout << a . x << \\\" , \u2581 \\\" << a . y << \\\" \u2581 n \\\" << b . x << \\\" , \u2581 \\\" << b . y << \\\" n \\\" ; << c . x << \\\" , \u2581 \\\" << c . y << \\\" \u2581 n \\\" << d . x << \\\" , \u2581 \\\" << d . y << \\\" nn \\\" ; } int main ( ) { Point p1 ( 1 , 0 ) , q1 ( 1 , 2 ) ; printCorners ( p1 , q1 , 2 ) ; Point p ( 1 , 1 ) , q ( -1 , -1 ) ; printCorners ( p , q , 2 * sqrt ( 2 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"String containing first letter of every word in a given string with spaces | An efficient Python3 implementation of above approach ; we are splitting the input based on spaces ( s ) + : this regular expression will handle scenarios where we have words separated by multiple spaces ; charAt ( 0 ) will pick only the first character from the string and append to buffer ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"charBuffer = [ ]\\ndef processWords ( input ) :\\n\\ts = input . split ( \\\" \u2581 \\\" )\\n\\tfor values in s :\\n\\t\\tcharBuffer . append ( values [ 0 ] )\\n\\treturn charBuffer\\nif __name__ == ' _ _ main _ _ ' :\\n\\tinput = \\\" geeks \u2581 for \u2581 geeks \\\"\\n\\tprint ( * processWords ( input ) , sep = \\\" \\\" )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Add two numbers without using arithmetic operators |\\\"\\nSolution in C#:\",\"targets\":\"static int Add ( int x , int y ) { if ( y == 0 ) return x ; else return Add ( x ^ y , ( x & y ) << 1 ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Lagrange 's Interpolation | C # program for implementation of Lagrange 's Interpolation ; To represent a data point corresponding to x and y = f ( x ) ; function to interpolate the given data points using Lagrange 's formula xi corresponds to the new data point whose value is to be obtained n represents the number of known data points ; double result = 0 ; Initialize result ; Compute individual terms of above formula ; Add current term to result ; Driver code ; creating an array of 4 known data points ; Using the interpolate function to obtain a data point corresponding to x = 3\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { class Data { public int x , y ; public Data ( int x , int y ) { this . x = x ; this . y = y ; } } ; static double interpolate ( Data [ ] f , int xi , int n ) { for ( int i = 0 ; i < n ; i ++ ) { double term = f [ i ] . y ; for ( int j = 0 ; j < n ; j ++ ) { if ( j != i ) term = term * ( xi - f [ j ] . x ) \\/ ( f [ i ] . x - f [ j ] . x ) ; } result += term ; } return result ; } public static void Main ( String [ ] args ) { Data [ ] f = { new Data ( 0 , 2 ) , new Data ( 1 , 3 ) , new Data ( 2 , 12 ) , new Data ( 5 , 147 ) } ; Console . Write ( \\\" Value \u2581 of \u2581 f ( 3 ) \u2581 is \u2581 : \u2581 \\\" + ( int ) interpolate ( f , 3 , 4 ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Probability of A winning the match when individual probabilities of hitting the target given | Function to return the probability of A winning ; p and q store the values of fractions a \\/ b and c \\/ d ; To store the winning probability of A ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function getProbability ( a , b , c , d ) { var p = a \\/ b ; var q = c \\/ d ; var ans = p * ( 1 \\/ ( 1 - ( 1 - q ) * ( 1 - p ) ) ) ; return ans ; } var a = 1 , b = 2 , c = 10 , d = 11 ; document . write ( getProbability ( a , b , c , d ) . toFixed ( 5 ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Philaland Coin | TCS Mockvita 2020 | Python3 implementation to find the minimum number of denominations required for any number ; Function to find the minimum number of denomminations required ; Driver Code ; Function call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"from math import log2 , floor\\ndef findMinDenomin ( n ) :\\n\\treturn log2 ( n ) + 1\\nif __name__ == ' _ _ main _ _ ' :\\n\\tn = 10\\n\\tprint ( floor ( findMinDenomin ( n ) ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Maximize Bitwise AND of first element with complement of remaining elements for any permutation of given Array | Function to maximize the value for the given function and the array elements ; Vector array to maintain which bit is set for which integer in the given array by saving index of that integer ; Check if j - th bit is set for i - th integer ; Push the index of that integer in setBit [ j ] ; Find the element having highest significant set bit unset in other elements ; Place that integer at 0 - th index ; Store the maximum AND value ; Return the answer ; Driver Code ; Function call\\\"\\nSolution in Python:\",\"targets\":\"def functionMax ( arr , n ) :\\n\\tsetBit = [ [ ] for i in range ( 32 ) ]\\n\\tfor i in range ( n ) :\\n\\t\\tfor j in range ( 32 ) :\\n\\t\\t\\tif ( arr [ i ] & ( 1 << j ) ) :\\n\\t\\t\\t\\tsetBit [ j ] . append ( i )\\n\\ti = 31\\n\\twhile ( i >= 0 ) :\\n\\t\\tif ( len ( setBit [ i ] ) == 1 ) :\\n\\t\\t\\ttemp = arr [ 0 ]\\n\\t\\t\\tarr [ 0 ] = arr [ setBit [ i ] [ 0 ] ]\\n\\t\\t\\tarr [ setBit [ i ] [ 0 ] ] = temp\\n\\t\\t\\tbreak\\n\\t\\ti -= 1\\n\\tmaxAnd = arr [ 0 ]\\n\\tfor i in range ( 1 , n , 1 ) :\\n\\t\\tmaxAnd = ( maxAnd & ( ~ arr [ i ] ) )\\n\\treturn maxAnd\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 1 , 2 , 4 , 8 , 16 ]\\n\\tn = len ( arr )\\n\\tprint ( functionMax ( arr , n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Squares of numbers with repeated single digits | Set 1 ( 3 , 6 and 9 ) | Function to find the square of 333. . .333 , 666. . .666 and 999. . .999 ; if the number is 333. . .333 ; if the number is 666. . .666 ; if the number is 999. . .999 ; variable for hold result ; find the no of digit ; add size - 1 time a in result ; add one time b in result ; add size - 1 time c in result ; add one time d in result ; return result ; Drivers code ; find square of 33. .33 ; find square of 66. .66 ; find square of 66. .66\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function find_Square_369 ( num ) { let a , b , c , d ; if ( num [ 0 ] == ' ' ) { a = ' ' ; b = ' ' ; c = ' ' ; d = ' ' ; } else if ( num [ 0 ] == ' ' ) { a = ' ' ; b = ' ' ; c = ' ' ; d = ' ' ; } else { a = ' ' ; b = ' ' ; c = ' ' ; d = ' ' ; } let result = \\\" \\\" ; let size = num . length ; for ( let i = 1 ; i < size ; i ++ ) result += a ; result += b ; for ( let i = 1 ; i < size ; i ++ ) result += c ; result += d ; return result ; } let num_3 , num_6 , num_9 ; num_3 = \\\" \\\" ; num_6 = \\\" \\\" ; num_9 = \\\" \\\" ; let result = \\\" \\\" ; result = find_Square_369 ( num_3 ) ; document . write ( \\\" \\\" + num_3 + \\\" \\\" + result + \\\" \\\" ) ; result = find_Square_369 ( num_6 ) ; document . write ( \\\" \\\" + num_9 + \\\" \\\" + result + \\\" \\\" ) ; result = find_Square_369 ( num_9 ) ; document . write ( \\\" \\\" + num_9 + \\\" \\\" + result + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum operations to make sum of neighbouring elements <= X | Function to return the minimum number of operations required ; To store total operations required ; First make all elements equal to x which are currenctly greater ; Left scan the array ; Update the current element such that neighbouring sum is < x ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function MinOperations ( n , x , arr ) { let total = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( arr [ i ] > x ) { let difference = arr [ i ] - x ; total = total + difference ; arr [ i ] = x ; } } for ( let i = 1 ; i < n ; ++ i ) { let LeftNeigbouringSum = arr [ i ] + arr [ i - 1 ] ; if ( LeftNeigbouringSum > x ) { let current_diff = LeftNeigbouringSum - x ; arr [ i ] = Math . max ( 0 , arr [ i ] - current_diff ) ; total = total + current_diff ; } } return total ; } let X = 1 ; let arr = [ 1 , 6 , 1 , 2 , 0 , 4 ] ; let N = arr . length ; document . write ( MinOperations ( N , X , arr ) + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Queries to find the count of vowels in the substrings of the given string | C ++ implementation of the approach ; Function that returns true if ch is a vowel ; pre [ i ] will store the count of vowels in the substring str [ 0. . . i ] ; Fill the pre [ ] array ; If current character is a vowel ; If its a consonant ; For every query ; Find the count of vowels for the current query ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; #define N 2\\nbool isVowel ( char ch ) { return ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) ; } void performQueries ( string str , int len , int queries [ ] [ N ] , int q ) { int pre [ len ] ; if ( isVowel ( str [ 0 ] ) ) pre [ 0 ] = 1 ; else pre [ 0 ] = 0 ; for ( int i = 1 ; i < len ; i ++ ) { if ( isVowel ( str [ i ] ) ) pre [ i ] = 1 + pre [ i - 1 ] ; else pre [ i ] = pre [ i - 1 ] ; } for ( int i = 0 ; i < q ; i ++ ) { if ( queries [ i ] [ 0 ] == 0 ) { cout << pre [ queries [ i ] [ 1 ] ] << \\\" \\n \\\" ; } else { cout << ( pre [ queries [ i ] [ 1 ] ] - pre [ queries [ i ] [ 0 ] - 1 ] ) << \\\" \\n \\\" ; } } } int main ( ) { string str = \\\" geeksforgeeks \\\" ; int len = str . length ( ) ; int queries [ ] [ N ] = { { 1 , 3 } , { 2 , 4 } , { 1 , 9 } } ; int q = ( sizeof ( queries ) \\/ sizeof ( queries [ 0 ] ) ) ; performQueries ( str , len , queries , q ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count pairs with given sum | Set 2 | Function to return the count of pairs from arr with the given sum ; To store the count of pairs ; Sort the given array ; Take two pointers ; If sum is greater ; If sum is lesser ; If sum is equal ; Find the frequency of arr [ i ] ; Find the frequency of arr [ j ] ; If arr [ i ] and arr [ j ] are same then remove the extra number counted ; Return the required answer ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def pairs_count ( arr , n , sum ) :\\n\\tans = 0\\n\\tarr = sorted ( arr )\\n\\ti , j = 0 , n - 1\\n\\twhile ( i < j ) :\\n\\t\\tif ( arr [ i ] + arr [ j ] < sum ) :\\n\\t\\t\\ti += 1\\n\\t\\telif ( arr [ i ] + arr [ j ] > sum ) :\\n\\t\\t\\tj -= 1\\n\\t\\telse :\\n\\t\\t\\tx = arr [ i ]\\n\\t\\t\\txx = i\\n\\t\\t\\twhile ( i < j and arr [ i ] == x ) :\\n\\t\\t\\t\\ti += 1\\n\\t\\t\\ty = arr [ j ]\\n\\t\\t\\tyy = j\\n\\t\\t\\twhile ( j >= i and arr [ j ] == y ) :\\n\\t\\t\\t\\tj -= 1\\n\\t\\t\\tif ( x == y ) :\\n\\t\\t\\t\\ttemp = i - xx + yy - j - 1\\n\\t\\t\\t\\tans += ( temp * ( temp + 1 ) ) \\/\\/ 2\\n\\t\\t\\telse :\\n\\t\\t\\t\\tans += ( i - xx ) * ( yy - j )\\n\\treturn ans\\narr = [ 1 , 5 , 7 , 5 , - 1 ]\\nn = len ( arr )\\nsum = 6\\nprint ( pairs_count ( arr , n , sum ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if two strings are same ignoring their cases | ; Function to compare two strings ignoring their cases ; Convert to lowercase using transform ( ) function and :: tolower in STL ; Comparing both using inbuilt function ; if strings are equal , return true otherwise false ; Function to print the same or not same if strings are equal or not equal ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool equalIgnoreCase ( string str1 , string str2 ) { int i = 0 ; transform ( str1 . begin ( ) , str1 . end ( ) , str1 . begin ( ) , :: tolower ) ; transform ( str2 . begin ( ) , str2 . end ( ) , str2 . begin ( ) , :: tolower ) ; int x = str1 . compare ( str2 ) ; if ( x != 0 ) return false ; else return true ; } void equalIgnoreCaseUtil ( string str1 , string str2 ) { bool res = equalIgnoreCase ( str1 , str2 ) ; if ( res == true ) cout << \\\" Same \\\" << endl ; else cout << \\\" Not \u2581 Same \\\" << endl ; } int main ( ) { string str1 , str2 ; str1 = \\\" Geeks \\\" ; str2 = \\\" geeks \\\" ; equalIgnoreCaseUtil ( str1 , str2 ) ; str1 = \\\" Geek \\\" ; str2 = \\\" geeksforgeeks \\\" ; equalIgnoreCaseUtil ( str1 , str2 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if any pair of consecutive 1 s can be separated by at most M 0 s by circular rotation of a Binary String | Function to check if any pair of consecutive 1 s can be separated by at most M 0 s by circular rotation of string S ; Stores the indices of all 1 s ; Store the number of pairs separated by at least M 0 s ; Traverse the string ; Store the current index ; Traverse the array containing indices ; If the number of 0 s > M , then increment cnt by 1 ; Increment cnt ; Check if at least M '0' s lie between the first and last occurrence of '1' ; Increment cnt ; If the value of cnt <= 1 , then rotation of string is possible ; Otherwise ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function rotateString ( n , m , s ) { var v = [ ] ; var cnt = 0 ; var i ; for ( i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) { v . push ( i ) ; } } for ( i = 1 ; i < v . length ; i ++ ) { if ( ( v [ i ] - v [ i - 1 ] - 1 ) > m ) { cnt ++ ; } } if ( v . length >= 2 && ( n - ( v [ v . length - 1 ] - v [ 0 ] ) - 1 ) > m ) { cnt ++ ; } if ( cnt <= 1 ) { document . write ( \\\" \\\" ) ; } else { document . write ( \\\" \\\" ) ; } } var S = \\\" \\\" ; var M = 1 ; var N = S . length ; rotateString ( N , M , S ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find the kth element in the series generated by the given N ranges | C ++ implementation of the approach ; Function to return the kth element of the required series ; To store the number of integers that lie upto the ith index ; Compute the number of integers ; Stores the index , lying from 1 to n , ; Using binary search , find the index in which the kth element will lie ; Find the position of the kth element in the interval in which it lies ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int getKthElement ( int n , int k , int L [ ] , int R [ ] ) { int l = 1 ; int h = n ; int total [ n + 1 ] ; total [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { total [ i + 1 ] = total [ i ] + ( R [ i ] - L [ i ] ) + 1 ; } int index = -1 ; while ( l <= h ) { int m = ( l + h ) \\/ 2 ; if ( total [ m ] > k ) { index = m ; h = m - 1 ; } else if ( total [ m ] < k ) l = m + 1 ; else { index = m ; break ; } } l = L [ index - 1 ] ; h = R [ index - 1 ] ; int x = k - total [ index - 1 ] ; while ( l <= h ) { int m = ( l + h ) \\/ 2 ; if ( ( m - L [ index - 1 ] ) + 1 == x ) { return m ; } else if ( ( m - L [ index - 1 ] ) + 1 > x ) h = m - 1 ; else l = m + 1 ; } } int main ( ) { int L [ ] = { 1 , 8 , 21 } ; int R [ ] = { 4 , 10 , 23 } ; int n = sizeof ( L ) \\/ sizeof ( int ) ; int k = 6 ; cout << getKthElement ( n , k , L , R ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Place first N natural numbers at indices not equal to their values in an array | C ++ program for the above approach ; Function to place first N natural numbers in an array such that none of the values are equal to its indices ; Stores the required array ; Place N at the first position ; Iterate the range [ 1 , N ) ; Append elements to the sequence ; Print the sequence ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void generatepermutation ( int N ) { vector < int > answer ; answer . push_back ( N ) ; for ( int i = 1 ; i < N ; i ++ ) { answer . push_back ( i ) ; } for ( int i : answer ) cout << i << \\\" \u2581 \\\" ; } int main ( ) { int N = 4 ; generatepermutation ( N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to check if a matrix is symmetric | Fills transpose of mat [ N ] [ N ] in tr [ N ] [ N ] ; Returns true if mat [ N ] [ N ] is symmetric , else false ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php for ( $ i = 0 ; $ i < $ N ; $ i ++ ) for ( $ j = 0 ; $ j < $ N ; $ j ++ ) if ( $ mat [ $ i ] [ $ j ] != $ tr [ $ i ] [ $ j ] ) return false ; return true ; } function isSymmetric ( $ mat , $ N ) { $ tr = array ( array ( ) ) ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) for ( $ j = 0 ; $ j < $ N ; $ j ++ ) $ tr [ $ i ] [ $ j ] = $ mat [ $ j ] [ $ i ] ; $ mat = array ( array ( 1 , 3 , 5 ) , array ( 3 , 2 , 4 ) , array ( 5 , 4 , 1 ) ) ; if ( isSymmetric ( $ mat , 3 ) ) echo \\\" Yes \\\" ; else echo \\\" No \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Tetranacci Numbers | Function to print the N - th tetranacci number ; base cases ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function printTetra ( $ n ) { $ dp = array_fill ( 0 , $ n + 5 , 0 ) ; $ dp [ 0 ] = 0 ; $ dp [ 1 ] = $ dp [ 2 ] = 1 ; $ dp [ 3 ] = 2 ; for ( $ i = 4 ; $ i <= $ n ; $ i ++ ) $ dp [ $ i ] = $ dp [ $ i - 1 ] + $ dp [ $ i - 2 ] + $ dp [ $ i - 3 ] + $ dp [ $ i - 4 ] ; echo $ dp [ $ n ] ; } $ n = 10 ; printTetra ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Add two numbers without using arithmetic operators | C Program to add two numbers without using arithmetic operator ; Iterate till there is no carry ; carry now contains common set bits of x and y ; Sum of bits of x and y where at least one of the bits is not set ; Carry is shifted by one so that adding it to x gives the required sum ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint Add ( int x , int y ) { while ( y != 0 ) { int carry = x & y ; x = x ^ y ; y = carry << 1 ; } return x ; } int main ( ) { printf ( \\\" % d \\\" , Add ( 15 , 32 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Nearest prime less than given number n | array to store all primes less than 10 ^ 6 ; Utility function of Sieve of Sundaram ; In general Sieve of Sundaram , produces primes smaller than ( 2 * x + 2 ) for a number given number x ; This array is used to separate numbers of the form i + j + 2 ij from others where 1 <= i <= j ; eliminate indexes which does not produce primes ; Since 2 is a prime number ; Remaining primes are of the form 2 * i + 1 such that marked [ i ] is false . ; modified binary search to find nearest prime less than N ; base condition is , if we are reaching at left corner or right corner of primes [ ] array then return that corner element because before or after that we don 't have any prime number in primes array ; now if n is itself a prime so it will be present in primes array and here we have to find nearest prime less than n so we will return primes [ mid - 1 ] ; now if primes [ mid ] < n and primes [ mid + 1 ] > n that mean we reached at nearest prime ; Driver program to run the case\\\"\\nSolution in Javascript:\",\"targets\":\"var primes = [ ] ; var MAX = 1000000 ; function Sieve ( ) { let n = MAX ; let nNew = parseInt ( Math . sqrt ( n ) ) ; var marked = new Array ( n \\/ 2 + 500 ) . fill ( 0 ) ; for ( let i = 1 ; i <= parseInt ( ( nNew - 1 ) \\/ 2 ) ; i ++ ) for ( let j = ( i * ( i + 1 ) ) << 1 ; j <= parseInt ( n \\/ 2 ) ; j = j + 2 * i + 1 ) marked [ j ] = 1 ; primes . push ( 2 ) ; for ( let i = 1 ; i <= parseInt ( n \\/ 2 ) ; i ++ ) if ( marked [ i ] == 0 ) primes . push ( 2 * i + 1 ) ; } function binarySearch ( left , right , n ) { if ( left <= right ) { let mid = parseInt ( ( left + right ) \\/ 2 ) ; if ( mid == 0 mid == primes . length - 1 ) return primes [ mid ] ; if ( primes [ mid ] == n ) return primes [ mid - 1 ] ; if ( primes [ mid ] < n && primes [ mid + 1 ] > n ) return primes [ mid ] ; if ( n < primes [ mid ] ) return binarySearch ( left , mid - 1 , n ) ; else return binarySearch ( mid + 1 , right , n ) ; } return 0 ; } Sieve ( ) ; let n = 17 ; document . write ( binarySearch ( 0 , primes . length - 1 , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"Distance between a point and a Plane in 3 D | C program to find the Perpendicular ( shortest ) distance between a point and a Plane in 3 D . ; Function to find distance ; Driver Code ; Function call\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nvoid shortest_distance ( float x1 , float y1 , float z1 , float a , float b , float c , float d ) { d = fabs ( ( a * x1 + b * y1 + c * z1 + d ) ) ; float e = sqrt ( a * a + b * b + c * c ) ; printf ( \\\" Perpendicular \u2581 distance \u2581 is \u2581 % f \\\" , d \\/ e ) ; return ; } int main ( ) { float x1 = 4 ; float y1 = -4 ; float z1 = 3 ; float a = 2 ; float b = -2 ; float c = 5 ; float d = 8 ; shortest_distance ( x1 , y1 , z1 , a , b , c , d ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Frugal Number | Finding primes upto entered number ; Finding primes by Sieve of Eratosthenes method ; If prime [ i ] is not changed , then it is prime ; Update all multiples of p ; Forming array of the prime numbers found ; Returns number of digits in n ; Checking whether a number is Frugal or not ; Finding number of digits in prime factorization of the number ; Exponent for current factor ; Counting number of times this prime factor divides ( Finding exponent ) ; Finding number of digits in the exponent Avoiding exponents of value 1 ; Checking condition for frugal number ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function primes ( $ n ) { $ prime = array ( ) ; for ( $ i = 0 ; $ i < $ n + 1 ; $ i ++ ) $ prime [ $ i ] = true ; for ( $ i = 2 ; $ i * $ i <= $ n ; $ i ++ ) { if ( $ prime [ $ i ] == true ) { for ( $ j = $ i * 2 ; $ j <= $ n ; $ j += $ i ) $ prime [ $ j ] = false ; } } $ arr = array ( ) ; for ( $ i = 2 ; $ i < $ n ; $ i ++ ) if ( $ prime [ $ i ] ) array_push ( $ arr , $ i ) ; return $ arr ; } function countDigits ( $ n ) { $ temp = $ n ; $ c = 0 ; while ( $ temp != 0 ) { $ temp = intval ( $ temp \\/ 10 ) ; $ c ++ ; } return $ c ; } function frugal ( $ n ) { $ r = primes ( $ n ) ; $ t = $ n ; $ s = 0 ; for ( $ i = 0 ; $ i < count ( $ r ) ; $ i ++ ) { if ( $ t % $ r [ $ i ] == 0 ) { $ k = 0 ; while ( $ t % $ r [ $ i ] == 0 ) { $ t = intval ( $ t \\/ $ r [ $ i ] ) ; $ k ++ ; } if ( $ k == 1 ) $ s = $ s + countDigits ( $ r [ $ i ] ) ; else if ( $ k != 1 ) $ s = $ s + countDigits ( $ r [ $ i ] ) + countDigits ( $ k ) ; } } return ( countDigits ( $ n ) > $ s && $ s != 0 ) ; } $ n = 343 ; if ( frugal ( $ n ) ) echo ( \\\" A \u2581 Frugal \u2581 number \\n \\\" ) ; else echo ( \\\" Not \u2581 a \u2581 frugal \u2581 number \\n \\\" ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count maximum possible pairs from an array having sum K | C ++ program for the above approach ; Function to find the maximum number of pairs with a sum K such that same element can 't be used twice ; Initialize a hashm ; Store the final result ; Iterate over the array nums [ ] ; Decrement its frequency in m and increment the result by 1 ; Increment its frequency by 1 if it is already present in m . Otherwise , set its frequency to 1 ; Print the result ; Driver Code ; Function Call\\\"\\nSolution in C++:\",\"targets\":\"#include \\n#include \\nusing namespace std ; void maxPairs ( vector < int > nums , int k ) { map < int , int > m ; int result = 0 ; for ( auto i : nums ) { if ( m . find ( i ) != m . end ( ) && m [ i ] > 0 ) { m [ i ] = m [ i ] - 1 ; result ++ ; } else { m [ k - i ] = m [ k - i ] + 1 ; } } cout << result ; } int main ( ) { vector < int > arr = { 1 , 2 , 3 , 4 } ; int K = 5 ; maxPairs ( arr , K ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Fibonacci Cube Graph | CPP code to find vertices in a fibonacci cube graph of order n ; function to find fibonacci number ; function for finding number of vertices in fibonacci cube graph ; return fibonacci number for f ( n + 2 ) ; driver program\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int fib ( int n ) { if ( n <= 1 ) return n ; return fib ( n - 1 ) + fib ( n - 2 ) ; } int findVertices ( int n ) { return fib ( n + 2 ) ; } int main ( ) { int n = 3 ; cout << findVertices ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Sum of prime numbers without odd prime digits | Python3 program for above approach ; Find all prime numbers ; Store all prime numbers ; Function to check if a digit is odd prime or not ; Function to find sum ; To store required answer ; Get all prime numbers ; Traverse through all the prime numbers ; Flag stores 1 if a number does not contain any odd primes ; Find all digits of a number ; If number does not contain any odd primes ; Return the required answer ; Driver code ; Function call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"MAX = 100005\\ndef addPrimes ( ) :\\n\\tn = MAX\\n\\tprime = [ True for i in range ( n + 1 ) ]\\n\\tfor p in range ( 2 , n + 1 ) :\\n\\t\\tif p * p > n :\\n\\t\\t\\tbreak\\n\\t\\tif ( prime [ p ] == True ) :\\n\\t\\t\\tfor i in range ( 2 * p , n + 1 , p ) :\\n\\t\\t\\t\\tprime [ i ] = False\\n\\tans = [ ]\\n\\tfor p in range ( 2 , n + 1 ) :\\n\\t\\tif ( prime [ p ] ) :\\n\\t\\t\\tans . append ( p )\\n\\treturn ans\\ndef is_prime ( n ) :\\n\\tif n in [ 3 , 5 , 7 ] :\\n\\t\\treturn True\\n\\treturn False\\ndef find_Sum ( n ) :\\n\\tSum = 0\\n\\tv = addPrimes ( )\\n\\tfor i in range ( len ( v ) ) :\\n\\t\\tflag = 1\\n\\t\\ta = v [ i ]\\n\\t\\twhile ( a != 0 ) :\\n\\t\\t\\td = a % 10 ;\\n\\t\\t\\ta = a \\/\\/ 10 ;\\n\\t\\t\\tif ( is_prime ( d ) ) :\\n\\t\\t\\t\\tflag = 0\\n\\t\\t\\t\\tbreak\\n\\t\\tif ( flag == 1 ) :\\n\\t\\t\\tn -= 1\\n\\t\\t\\tSum = Sum + v [ i ]\\n\\t\\tif n == 0 :\\n\\t\\t\\tbreak\\n\\treturn Sum\\nn = 7\\nprint ( find_Sum ( n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Invert the Kth most significant bit of N | C # implementation of the approach ; Function to convert decimal number n to its binary representation stored as an array [ ] arr ; Function to convert the number represented as a binary array [ ] arr into its decimal equivalent ; Function to return the updated integer after flipping the kth bit ; Number of bits in n ; Find the binary representation of n ; The number of bits in n are less than k ; Flip the kth bit ; Return the decimal equivalent of the number ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void decBinary ( int [ ] arr , int n ) { int k = ( int ) ( Math . Log ( n ) \\/ Math . Log ( 2 ) ) ; while ( n > 0 ) { arr [ k -- ] = n % 2 ; n \\/= 2 ; } } static int binaryDec ( int [ ] arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) ans += arr [ i ] << ( n - i - 1 ) ; return ans ; } static int getNum ( int n , int k ) { int l = ( int ) ( Math . Log ( n ) \\/ Math . Log ( 2 ) ) + 1 ; int [ ] a = new int [ l ] ; decBinary ( a , n ) ; if ( k > l ) return n ; a [ k - 1 ] = ( a [ k - 1 ] == 0 ) ? 1 : 0 ; return binaryDec ( a , l ) ; } public static void Main ( String [ ] args ) { int n = 56 ; int k = 2 ; Console . WriteLine ( getNum ( n , k ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all elements between k1 ' th \u2581 and \u2581 k2' th smallest elements | C ++ implementation of above approach ; Driver code ; decreasing value by 1 because we want min heapifying k times and it starts from 0 so we have to decrease it 1 time ; Step 1 : Do extract minimum k1 times ( This step takes O ( K1 Log n ) time ) ; Step 2 : Do extract minimum k2 k1 1 times and sum all extracted elements . ( This step takes O ( ( K2 k1 ) * Log n ) time )\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int n = 7 ; void minheapify ( int a [ ] , int index ) { int small = index ; int l = 2 * index + 1 ; int r = 2 * index + 2 ; if ( l < n && a [ l ] < a [ small ] ) small = l ; if ( r < n && a [ r ] < a [ small ] ) small = r ; if ( small != index ) { swap ( a [ small ] , a [ index ] ) ; minheapify ( a , small ) ; } } int main ( ) { int i = 0 ; int k1 = 3 ; int k2 = 6 ; int a [ ] = { 20 , 8 , 22 , 4 , 12 , 10 , 14 } ; int ans = 0 ; for ( i = ( n \\/ 2 ) - 1 ; i >= 0 ; i -- ) { minheapify ( a , i ) ; } k1 -- ; k2 -- ; for ( i = 0 ; i <= k1 ; i ++ ) { a [ 0 ] = a [ n - 1 ] ; n -- ; minheapify ( a , 0 ) ; } for ( i = k1 + 1 ; i < k2 ; i ++ ) { ans += a [ 0 ] ; a [ 0 ] = a [ n - 1 ] ; n -- ; minheapify ( a , 0 ) ; } cout << ans ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all the prime divisors of a number | Python 3 program to find sum of prime divisors of N ; Function to check if the number is prime or not . ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; function to find sum of prime divisors of N ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"N = 1000005\\ndef isPrime ( n ) :\\n\\tif n <= 1 :\\n\\t\\treturn False\\n\\tif n <= 3 :\\n\\t\\treturn True\\n\\tif n % 2 == 0 or n % 3 == 0 :\\n\\t\\treturn False\\n\\ti = 5\\n\\twhile i * i <= n :\\n\\t\\tif ( n % i == 0 or n % ( i + 2 ) == 0 ) :\\n\\t\\t\\treturn False\\n\\t\\ti = i + 6\\n\\treturn True\\ndef SumOfPrimeDivisors ( n ) :\\n\\tsum = 0\\n\\tfor i in range ( 1 , n + 1 ) :\\n\\t\\tif n % i == 0 :\\n\\t\\t\\tif isPrime ( i ) :\\n\\t\\t\\t\\tsum += i\\n\\treturn sum\\nn = 60\\nprint ( \\\" Sum \u2581 of \u2581 prime \u2581 divisors \u2581 of \u2581 60 \u2581 is \u2581 \\\" + str ( SumOfPrimeDivisors ( n ) ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find Corners of Rectangle using mid points | Structure to represent a co - ordinate point ; This function receives two points and length of the side of rectangle and prints the 4 corner points of the rectangle ; horizontal rectangle ; vertical rectangle ; slanted rectangle ; calculate slope of the side ; calculate displacements along axes ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"class Point { constructor ( a , b ) { this . x = a ; this . y = b ; } } function printCorners ( p , q , l ) { let a = new Point ( ) , b = new Point ( ) , c = new Point ( ) , d = new Point ( ) ; if ( p . x == q . x ) { a . x = ( p . x - ( l \\/ 2.0 ) ) ; a . y = p . y ; d . x = ( p . x + ( l \\/ 2.0 ) ) ; d . y = p . y ; b . x = ( q . x - ( l \\/ 2.0 ) ) ; b . y = q . y ; c . x = ( q . x + ( l \\/ 2.0 ) ) ; c . y = q . y ; } else if ( p . y == q . y ) { a . y = ( p . y - ( l \\/ 2.0 ) ) ; a . x = p . x ; d . y = ( p . y + ( l \\/ 2.0 ) ) ; d . x = p . x ; b . y = ( q . y - ( l \\/ 2.0 ) ) ; b . x = q . x ; c . y = ( q . y + ( l \\/ 2.0 ) ) ; c . x = q . x ; } else { let m = ( p . x - q . x ) \\/ ( q . y - p . y ) ; let dx = ( ( l \\/ Math . sqrt ( 1 + ( m * m ) ) ) * 0.5 ) ; let dy = m * dx ; a . x = p . x - dx ; a . y = p . y - dy ; d . x = p . x + dx ; d . y = p . y + dy ; b . x = q . x - dx ; b . y = q . y - dy ; c . x = q . x + dx ; c . y = q . y + dy ; } document . write ( a . x + \\\" \\\" + a . y + \\\" \\\" + b . x + \\\" \\\" + b . y + \\\" \\\" + c . x + \\\" \\\" + c . y + \\\" \\\" + d . x + \\\" \\\" + d . y + \\\" \\\" ) ; } let p1 = new Point ( 1 , 0 ) , q1 = new Point ( 1 , 2 ) ; printCorners ( p1 , q1 , 2 ) ; let p = new Point ( 1 , 1 ) , q = new Point ( - 1 , - 1 ) ; printCorners ( p , q , ( 2 * Math . sqrt ( 2 ) ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count minimum character replacements required such that given string satisfies the given conditions | C # program for the above approach ; Function that finds the minimum count of steps required to make the string special ; Stores the frequency of the left & right half of string ; Find frequency of left half ; Find frequency of left half ; Make all characters equal to character c ; Case 1 : For s [ i ] < s [ j ] ; Subtract all the characters on left side that are <= d ; Adding all characters on the right side that same as d ; Find minimum value of count ; Similarly for Case 2 : s [ i ] > s [ j ] ; Return the minimum changes ; Driver Code ; Given string S ; Function Call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { public static int minChange ( String s , int n ) { int [ ] L = new int [ 26 ] ; int [ ] R = new int [ 26 ] ; for ( int i = 0 ; i < n \\/ 2 ; i ++ ) { char ch = s [ i ] ; L [ ch - ' a ' ] ++ ; } for ( int i = n \\/ 2 ; i < n ; i ++ ) { char ch = s [ i ] ; R [ ch - ' a ' ] ++ ; } int count = n ; for ( char ch = ' a ' ; ch <= ' z ' ; ch ++ ) { count = Math . Min ( count , n - L [ ch - ' a ' ] - R [ ch - ' a ' ] ) ; } int change = n \\/ 2 ; for ( int d = 0 ; d + 1 < 26 ; d ++ ) { change -= L [ d ] ; change += R [ d ] ; count = Math . Min ( count , change ) ; } change = n \\/ 2 ; for ( int d = 0 ; d + 1 < 26 ; d ++ ) { change -= R [ d ] ; change += L [ d ] ; count = Math . Min ( change , count ) ; } return count ; } public static void Main ( String [ ] args ) { String S = \\\" aababc \\\" ; int N = S . Length ; Console . WriteLine ( minChange ( S , N ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sum of numbers from 1 to N which are divisible by 3 or 4 | Function to calculate the sum of numbers divisible by 3 or 4 ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function sum ( $ N ) { $ S1 ; $ S2 ; $ S3 ; $ S1 = ( ( $ N \\/ 3 ) ) * ( 2 * 3 + ( $ N \\/ 3 - 1 ) * 3 ) \\/ 2 ; $ S2 = ( ( $ N \\/ 4 ) ) * ( 2 * 4 + ( $ N \\/ 4 - 1 ) * 4 ) \\/ 2 ; $ S3 = ( ( $ N \\/ 12 ) ) * ( 2 * 12 + ( $ N \\/ 12 - 1 ) * 12 ) \\/ 2 ; return $ S1 + $ S2 - $ S3 ; } $ N = 20 ; echo sum ( 12 ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find extra element in the second array | Function to return the extra element in B [ ] ; To store the result ; Find the XOR of all the element of array A [ ] and array B [ ] ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function extraElement ( A , B , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) ans ^= A [ i ] ; for ( let i = 0 ; i < n + 1 ; i ++ ) ans ^= B [ i ] ; return ans ; } let A = [ 10 , 15 , 5 ] ; let B = [ 10 , 100 , 15 , 5 ] ; let n = A . length ; document . write ( extraElement ( A , B , n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all subsequences of a number | Returns numeric value of a subsequence of s . The subsequence to be picked is decided using bit pattern of num ( We pick all those digits for which there is a set bit in num ) ; Initialize the result ; till n != 0 ; if i - th bit is set then add this number ; right shift i ; function to find combined sum of all individual subsequence sum ; length of String ; stores the combined ; 2 ^ n - 1 subsequences ; loop for all subsequences ; returns the combined sum ; Driver function\\\"\\nSolution in Javascript:\",\"targets\":\"function findSubSequence ( s , num ) { let res = 0 ; let i = 0 ; while ( num > 0 ) { if ( ( num & 1 ) == 1 ) res += s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; i ++ ; num = num >> 1 ; } return res ; } function combinedSum ( s ) { let n = s . length ; let c_sum = 0 ; let range = ( 1 << n ) - 1 ; for ( let i = 0 ; i <= range ; i ++ ) c_sum += findSubSequence ( s , i ) ; return c_sum ; } let s = \\\" \\\" ; document . write ( combinedSum ( s ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count number of distinct substrings of a given length | Python3 implementation of above approach ; Function to find the required count ; Variable to the hash ; Finding hash of substring ( 0 , l - 1 ) using random number x ; Computing x ^ ( l - 1 ) ; Unordered set to add hash values ; Generating all possible hash values ; Print the result ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"x = 26\\nmod = 3001\\ndef CntSubstr ( s , l ) :\\n\\thash = 0 ;\\n\\tfor i in range ( l ) :\\n\\t\\thash = ( hash * x + ( ord ( s [ i ] ) - 97 ) ) % mod ;\\n\\tpow_l = 1 ;\\n\\tfor i in range ( l - 1 ) :\\n\\t\\tpow_l = ( pow_l * x ) % mod ;\\n\\tresult = set ( ) ;\\n\\tresult . add ( hash ) ;\\n\\tfor i in range ( l , len ( s ) ) :\\n\\t\\thash = ( ( hash - pow_l * ( ord ( s [ i - l ] ) - 97 ) + 2 * mod ) * x + ( ord ( s [ i ] ) - 97 ) ) % mod ;\\n\\t\\tresult . add ( hash ) ;\\n\\tprint ( len ( result ) ) ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\ts = \\\" abcba \\\" ;\\n\\tl = 2 ;\\n\\tCntSubstr ( s , l ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Smallest String consisting of a String S exactly K times as a Substring | C ++ Program to implement the above approach ; KMP algorithm ; Function to return the required string ; Finding the longest proper prefix which is also suffix ; ans string ; Update ans appending the substring K - 1 times ; Append the original string ; Returning min length string which contain exactly k substring of given string ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int * kmp ( string & s ) { int n = s . size ( ) ; int * lps = new int [ n ] ; lps [ 0 ] = 0 ; int i = 1 , len = 0 ; while ( i < n ) { if ( s [ i ] == s [ len ] ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = lps [ len - 1 ] ; } else { lps [ i ] = 0 ; i ++ ; } } } return lps ; } string findString ( string & s , int k ) { int n = s . length ( ) ; int * lps = kmp ( s ) ; string ans = \\\" \\\" ; string suff = s . substr ( 0 , n - lps [ n - 1 ] ) ; for ( int i = 0 ; i < k - 1 ; ++ i ) { ans += suff ; } ans += s ; return ans ; } int main ( ) { int k = 3 ; string s = \\\" geeksforgeeks \\\" ; cout << findString ( s , k ) << endl ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count N | Function to count N - length strings consisting of vowels only sorted lexicographically ; Stores count of strings consisting of vowels sorted lexicographically of all possible lengths ; Initialize DP [ 1 ] [ 1 ] ; Traverse the matrix row - wise ; Base Case ; Return the result ; Driver Code ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function findNumberOfStrings ( n ) { let DP = new Array ( n + 1 ) ; for ( var i = 0 ; i < DP . length ; i ++ ) { DP [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < DP . length ; i ++ ) { for ( var j = 0 ; j < DP . length ; j ++ ) { DP [ i ] [ j ] = 0 ; } } DP [ 1 ] [ 1 ] = 1 ; for ( let i = 1 ; i < n + 1 ; i ++ ) { for ( let j = 1 ; j < 6 ; j ++ ) { if ( i == 1 ) { DP [ i ] [ j ] = DP [ i ] [ j - 1 ] + 1 ; } else { DP [ i ] [ j ] = DP [ i ] [ j - 1 ] + DP [ i - 1 ] [ j ] ; } } } return DP [ n ] [ 5 ] ; } let N = 2 ; document . write ( findNumberOfStrings ( N ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximize count of elements that can be selected having minimum difference between their sum and K | Java implementation of the above approach ; Function to count maximum number of elements that can be selected ; Sorting the array ; Traverse the array ; Add the current element to the sum ; If sum exceeds k ; Increment count ; Returning the count ; Driver code ; Function call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . Arrays ; public class GFG { static int CountMaximum ( int arr [ ] , int n , int k ) { Arrays . sort ( arr ) ; int sum = 0 , count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( sum > k ) break ; count ++ ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 30 , 30 , 10 , 10 } ; int n = 4 ; int k = 50 ; System . out . println ( CountMaximum ( arr , n , k ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Convert a given Binary Tree to Doubly Linked List | Set 2 | A simple inorder traversal based program to convert a Binary Tree to DLL ; A tree node ; A utility function to create a new tree node ; Standard Inorder traversal of tree ; Changes left pointers to work as previous pointers in converted DLL The function simply does inorder traversal of Binary Tree and updates left pointer using previously visited node ; Changes right pointers to work as next pointers in converted DLL ; Find the right most node in BT or last node in DLL ; Start from the rightmost node , traverse back using left pointers . While traversing , change right pointer of nodes . ; The leftmost node is head of linked list , return it ; The main function that converts BST to DLL and returns head of DLL ; Set the previous pointer ; Set the next pointer and return head of DLL ; Traverses the DLL from left tor right ; Driver code ; Let us create the tree shown in above diagram\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; class node { public : int data ; node * left , * right ; } ; node * newNode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = Node -> right = NULL ; return ( Node ) ; } void inorder ( node * root ) { if ( root != NULL ) { inorder ( root -> left ) ; cout << \\\" \\t \\\" << root -> data ; inorder ( root -> right ) ; } } void fixPrevPtr ( node * root ) { static node * pre = NULL ; if ( root != NULL ) { fixPrevPtr ( root -> left ) ; root -> left = pre ; pre = root ; fixPrevPtr ( root -> right ) ; } } node * fixNextPtr ( node * root ) { node * prev = NULL ; while ( root && root -> right != NULL ) root = root -> right ; while ( root && root -> left != NULL ) { prev = root ; root = root -> left ; root -> right = prev ; } return ( root ) ; } node * BTToDLL ( node * root ) { fixPrevPtr ( root ) ; return fixNextPtr ( root ) ; } void printList ( node * root ) { while ( root != NULL ) { cout << \\\" \\t \\\" << root -> data ; root = root -> right ; } } int main ( void ) { node * root = newNode ( 10 ) ; root -> left = newNode ( 12 ) ; root -> right = newNode ( 15 ) ; root -> left -> left = newNode ( 25 ) ; root -> left -> right = newNode ( 30 ) ; root -> right -> left = newNode ( 36 ) ; cout << \\\" Inorder Tree Traversal \\\" ; inorder ( root ) ; node * head = BTToDLL ( root ) ; cout << \\\" DLL Traversal \\\" printList ( head ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find Nth term of the series 0 , 2 , 4 , 8 , 12 , 18. . . | Calculate Nth term of series ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function nthTerm ( $ N ) { return ( int ) ( ( $ N + $ N * ( $ N - 1 ) ) \\/ 2 ) ; } $ N = 5 ; echo nthTerm ( $ N ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find a Fixed Point ( Value equal to index ) in a given array | C program to check fixed point in an array using binary search ; low + ( high - low ) \\/ 2 ; ; Return - 1 if there is no Fixed Point ; Driver program to check above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\nint binarySearch ( int arr [ ] , int low , int high ) { if ( high >= low ) { int mid = ( low + high ) \\/ 2 ; if ( mid == arr [ mid ] ) return mid ; if ( mid > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high ) ; else return binarySearch ( arr , low , ( mid - 1 ) ) ; } return -1 ; } int main ( ) { int arr [ 10 ] = { -10 , -1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Fixed \u2581 Point \u2581 is \u2581 % d \\\" , binarySearch ( arr , 0 , n - 1 ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count minimum swap to make string palindrome | Function to Count minimum swap ; Counter to count minimum swap ; A loop which run in half string from starting ; Left pointer ; Right pointer ; A loop which run from right pointer to left pointer ; if both char same then break the loop if not same then we have to move right pointer to one step left ; it denotes both pointer at same position and we don 't have sufficient char to make palindrome string ; Driver Code ; Length of string ; Function calling\\\"\\nSolution in Python:\",\"targets\":\"def CountSwap ( s , n ) :\\n\\ts = list ( s )\\n\\tcount = 0\\n\\tans = True\\n\\tfor i in range ( n \\/\\/ 2 ) :\\n\\t\\tleft = i\\n\\t\\tright = n - left - 1\\n\\t\\twhile left < right :\\n\\t\\t\\tif s [ left ] == s [ right ] :\\n\\t\\t\\t\\tbreak\\n\\t\\t\\telse :\\n\\t\\t\\t\\tright -= 1\\n\\t\\tif left == right :\\n\\t\\t\\tans = False\\n\\t\\t\\tbreak\\n\\t\\telse :\\n\\t\\t\\tfor j in range ( right , n - left - 1 ) :\\n\\t\\t\\t\\t( s [ j ] , s [ j + 1 ] ) = ( s [ j + 1 ] , s [ j ] )\\n\\t\\t\\t\\tcount += 1\\n\\tif ans :\\n\\t\\treturn ( count )\\n\\telse :\\n\\t\\treturn - 1\\ns = ' geeksfgeeks '\\nn = len ( s )\\nans1 = CountSwap ( s , n )\\nans2 = CountSwap ( s [ : : - 1 ] , n )\\nprint ( max ( ans1 , ans2 ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Maximize sum by choosing elements from different section of a matrix | Python3 program for the above approach ; Function to find the maximum value ; Dp table ; Fill the dp in bottom up manner ; Maximum of the three sections ; Maximum of the first section ; Maximum of the second section ; Maximum of the third section ; If we choose element from section 1 , we cannot have selection from same section in adjacent rows ; Print the maximum sum ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import numpy as np\\nn = 6 ; m = 6 ;\\ndef maxSum ( arr ) :\\n\\tdp = np . zeros ( ( n + 1 , 3 ) ) ;\\n\\tfor i in range ( n ) :\\n\\t\\tm1 = 0 ; m2 = 0 ; m3 = 0 ;\\n\\t\\tfor j in range ( m ) :\\n\\t\\t\\tif ( ( j \\/\\/ ( m \\/\\/ 3 ) ) == 0 ) :\\n\\t\\t\\t\\tm1 = max ( m1 , arr [ i ] [ j ] ) ;\\n\\t\\t\\telif ( ( j \\/\\/ ( m \\/\\/ 3 ) ) == 1 ) :\\n\\t\\t\\t\\tm2 = max ( m2 , arr [ i ] [ j ] ) ;\\n\\t\\t\\telif ( ( j \\/\\/ ( m \\/\\/ 3 ) ) == 2 ) :\\n\\t\\t\\t\\tm3 = max ( m3 , arr [ i ] [ j ] ) ;\\n\\t\\tdp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 1 ] , dp [ i ] [ 2 ] ) + m1 ;\\n\\t\\tdp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 2 ] ) + m2 ;\\n\\t\\tdp [ i + 1 ] [ 2 ] = max ( dp [ i ] [ 1 ] , dp [ i ] [ 0 ] ) + m3 ;\\n\\tprint ( max ( max ( dp [ n ] [ 0 ] , dp [ n ] [ 1 ] ) , dp [ n ] [ 2 ] ) ) ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ [ 1 , 3 , 5 , 2 , 4 , 6 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 1 , 3 , 5 , 2 , 4 , 6 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 1 , 3 , 5 , 2 , 4 , 6 ] ] ;\\n\\tmaxSum ( arr ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check horizontal and vertical symmetry in binary matrix | C ++ program to find if a matrix is symmetric . ; Initializing as both horizontal and vertical symmetric . ; Checking for Horizontal Symmetry . We compare first row with last row , second row with second last row and so on . ; Checking each cell of a column . ; check if every cell is identical ; Checking for Vertical Symmetry . We compare first column with last column , second xolumn with second last column and so on . ; Checking each cell of a row . ; check if every cell is identical ; Driven Program\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#define MAX 1000\\nusing namespace std ; void checkHV ( int arr [ ] [ MAX ] , int N , int M ) { bool horizontal = true , vertical = true ; for ( int i = 0 , k = N - 1 ; i < N \\/ 2 ; i ++ , k -- ) { for ( int j = 0 ; j < M ; j ++ ) { if ( arr [ i ] [ j ] != arr [ k ] [ j ] ) { horizontal = false ; break ; } } } for ( int i = 0 , k = M - 1 ; i < M \\/ 2 ; i ++ , k -- ) { for ( int j = 0 ; j < N ; j ++ ) { if ( arr [ i ] [ j ] != arr [ k ] [ j ] ) { vertical = false ; break ; } } } if ( ! horizontal && ! vertical ) cout << \\\" NO \\n \\\" ; else if ( horizontal && ! vertical ) cout << \\\" HORIZONTAL \\n \\\" ; else if ( vertical && ! horizontal ) cout << \\\" VERTICAL \\n \\\" ; else cout << \\\" BOTH \\n \\\" ; } int main ( ) { int mat [ MAX ] [ MAX ] = { { 1 , 0 , 1 } , { 0 , 0 , 0 } , { 1 , 0 , 1 } } ; checkHV ( mat , 3 , 3 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Add two numbers without using arithmetic operators | C Program to add two numbers without using arithmetic operator ; Iterate till there is no carry ; carry now contains common set bits of x and y ; Sum of bits of x and y where at least one of the bits is not set ; Carry is shifted by one so that adding it to x gives the required sum ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\nint Add ( int x , int y ) { while ( y != 0 ) { int carry = x & y ; x = x ^ y ; y = carry << 1 ; } return x ; } int main ( ) { printf ( \\\" % d \\\" , Add ( 15 , 32 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Length of smallest subarray to be removed to make sum of remaining elements divisible by K | Function to find the length of the smallest subarray to be removed such that sum of elements is divisible by K ; Stores the remainder of each arr [ i ] when divided by K ; Stores total sum of elements ; K has been added to each arr [ i ] to handle - ve integers ; Update the total sum ; Remainder when total_sum is divided by K ; If given array is already divisible by K ; Stores curr_remainder and the most recent index at which curr_remainder has occurred ; Stores required answer ; Add current element to curr_sum and take mod ; Update current remainder index ; If mod already exists in map the subarray exists ; If not possible ; Print the result ; Given array arr [ ] ; Size of array ; Given K ; Function Call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function removeSmallestSubarray ( arr , n , k ) { let mod_arr = new Array ( n ) ; let total_sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { mod_arr [ i ] = ( arr [ i ] + k ) % k ; total_sum += arr [ i ] ; } let target_remainder = total_sum % k ; if ( target_remainder == 0 ) { document . write ( \\\" \\\" ) ; return ; } let map1 = new Map ( ) ; map1 . set ( 0 , - 1 ) ; let curr_remainder = 0 ; let res = Number . MAX_SAFE_INTEGER ; for ( let i = 0 ; i < n ; i ++ ) { curr_remainder = ( curr_remainder + arr [ i ] + k ) % k ; map1 . set ( curr_remainder , i ) ; let mod = ( curr_remainder - target_remainder + k ) % k ; if ( map1 . has ( mod ) ) res = Math . min ( res , i - map1 . get ( mod ) ) ; } if ( res == Number . MAX_SAFE_INTEGER res == n ) { res = - 1 ; } document . write ( res ) ; } let arr = [ 3 , 1 , 4 , 2 ] ; let N = arr . length ; let K = 6 ; removeSmallestSubarray ( arr , N , K ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Perimeter and Area of Varignon 's Parallelogram | C program to find the perimeter and area ; Function to find the perimeter ; Function to find the area ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\nfloat per ( float a , float b ) { return ( a + b ) ; } float area ( float s ) { return ( s \\/ 2 ) ; } int main ( ) { float a = 7 , b = 8 , s = 10 ; printf ( \\\" % f \\n \\\" , per ( a , b ) ) ; printf ( \\\" % f \\\" , area ( s ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Sort the matrix column | Java program for the above approach ; Function to find the transpose of the matrix mat [ ] ; Stores the transpose of matrix mat [ ] [ ] ; Traverse each row of the matrix ; Traverse each column of the matrix ; Transpose matrix elements ; Function to sort the given matrix in row wise manner ; Traverse the row ; Row - Wise Sorting ; Function to print the matrix in column wise sorted manner ; Function call to find transpose of the the matrix mat [ ] [ ] ; Sorting the matrix row - wise ; Calculate transpose of B [ ] [ ] ; Print the matrix mat [ ] [ ] ; Driver Code ; Input ; Function call to print the matrix in column wise sorted manner\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; import java . util . Arrays ; class GFG { static int [ ] [ ] transpose ( int [ ] [ ] mat , int row , int col ) { int [ ] [ ] tr = new int [ col ] [ row ] ; for ( int i = 0 ; i < row ; i ++ ) { for ( int j = 0 ; j < col ; j ++ ) { tr [ j ] [ i ] = mat [ i ] [ j ] ; } } return tr ; } static void RowWiseSort ( int [ ] [ ] B ) { for ( int i = 0 ; i < ( int ) B . length ; i ++ ) { Arrays . sort ( B [ i ] ) ; } } static void sortCol ( int [ ] [ ] mat , int N , int M ) { int [ ] [ ] B = transpose ( mat , N , M ) ; RowWiseSort ( B ) ; mat = transpose ( B , M , N ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { System . out . print ( mat [ i ] [ j ] + \\\" \u2581 \\\" ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int [ ] [ ] mat = { { 1 , 6 , 10 } , { 8 , 5 , 9 } , { 9 , 4 , 15 } , { 7 , 3 , 60 } } ; int N = mat . length ; int M = mat [ 0 ] . length ; sortCol ( mat , N , M ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Icosikaioctagon or Icosioctagon Number | C program for above approach ; Finding the nth icosikaioctagonal Number ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nint icosikaioctagonalNum ( int n ) { return ( 26 * n * n - 24 * n ) \\/ 2 ; } int main ( ) { int n = 3 ; printf ( \\\"3rd \u2581 icosikaioctagonal \u2581 Number \u2581 is \u2581 = \u2581 % d \\\" , icosikaioctagonalNum ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Sum of the multiples of two numbers below N | C ++ program to find the sum of all the integers below N which are multiples of either A or B ; Function to return the sum of all the integers below N which are multiples of either A or B ; If i is a multiple of a or b ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int findSum ( int n , int a , int b ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( i % a == 0 i % b == 0 ) sum += i ; return sum ; } int main ( ) { int n = 10 , a = 3 , b = 5 ; cout << findSum ( n , a , b ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Add 1 to a given number | ; Driver program to test above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint addOne ( int x ) { return ( - ( ~ x ) ) ; } int main ( ) { printf ( \\\" % d \\\" , addOne ( 13 ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Merge K sorted arrays | Set 3 ( Using Divide and Conquer Approach ) | C ++ program to merge K sorted arrays ; Function to perform merge operation ; to store the starting point of left and right array ; To store the size of left and right array ; array to temporarily store left and right array ; storing data in left array ; storing data in right array ; to store the current index of temporary left and right array ; to store the current index for output array ; two pointer merge for two sorted arrays ; Code to drive merge - sort and create recursion tree ; base step to initialize the output array before performing merge operation ; To sort left half ; To sort right half ; Merge the left and right half ; Driver Function ; input 2D - array ; Number of arrays ; Output array ; Print merged array\\\"\\nSolution in C++:\",\"targets\":\"#include \\n#define n 4\\nusing namespace std ; void merge ( int l , int r , int * output ) { int l_in = l * n , r_in = ( ( l + r ) \\/ 2 + 1 ) * n ; int l_c = ( ( l + r ) \\/ 2 - l + 1 ) * n ; int r_c = ( r - ( l + r ) \\/ 2 ) * n ; int l_arr [ l_c ] , r_arr [ r_c ] ; for ( int i = 0 ; i < l_c ; i ++ ) l_arr [ i ] = output [ l_in + i ] ; for ( int i = 0 ; i < r_c ; i ++ ) r_arr [ i ] = output [ r_in + i ] ; int l_curr = 0 , r_curr = 0 ; int in = l_in ; while ( l_curr + r_curr < l_c + r_c ) { if ( r_curr == r_c || ( l_curr != l_c && l_arr [ l_curr ] < r_arr [ r_curr ] ) ) output [ in ] = l_arr [ l_curr ] , l_curr ++ , in ++ ; else output [ in ] = r_arr [ r_curr ] , r_curr ++ , in ++ ; } } void divide ( int l , int r , int * output , int arr [ ] [ n ] ) { if ( l == r ) { for ( int i = 0 ; i < n ; i ++ ) output [ l * n + i ] = arr [ l ] [ i ] ; return ; } divide ( l , ( l + r ) \\/ 2 , output , arr ) ; divide ( ( l + r ) \\/ 2 + 1 , r , output , arr ) ; merge ( l , r , output ) ; } int main ( ) { int arr [ ] [ n ] = { { 5 , 7 , 15 , 18 } , { 1 , 8 , 9 , 17 } , { 1 , 4 , 7 , 7 } } ; int k = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int * output = new int [ n * k ] ; divide ( 0 , k - 1 , output , arr ) ; for ( int i = 0 ; i < n * k ; i ++ ) cout << output [ i ] << \\\" \u2581 \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find the direction from given string | Function to find the final direction ; if count is positive that implies resultant is clockwise direction ; if count is negative that implies resultant is anti - clockwise direction ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def findDirection ( s ) :\\n\\tcount = 0\\n\\td = \\\" \\\"\\n\\tfor i in range ( len ( s ) ) :\\n\\t\\tif ( s [ i ] == ' L ' ) :\\n\\t\\t\\tcount -= 1\\n\\t\\telse :\\n\\t\\t\\tif ( s [ i ] == ' R ' ) :\\n\\t\\t\\t\\tcount += 1\\n\\tif ( count > 0 ) :\\n\\t\\tif ( count % 4 == 0 ) :\\n\\t\\t\\td = \\\" N \\\"\\n\\t\\telif ( count % 4 == 10 ) :\\n\\t\\t\\td = \\\" E \\\"\\n\\t\\telif ( count % 4 == 2 ) :\\n\\t\\t\\td = \\\" S \\\"\\n\\t\\telif ( count % 4 == 3 ) :\\n\\t\\t\\td = \\\" W \\\"\\n\\tif ( count < 0 ) :\\n\\t\\tcount *= - 1\\n\\t\\tif ( count % 4 == 0 ) :\\n\\t\\t\\td = \\\" N \\\"\\n\\t\\telif ( count % 4 == 1 ) :\\n\\t\\t\\td = \\\" W \\\"\\n\\t\\telif ( count % 4 == 2 ) :\\n\\t\\t\\td = \\\" S \\\"\\n\\t\\telif ( count % 4 == 3 ) :\\n\\t\\t\\td = \\\" E \\\"\\n\\treturn d\\nif __name__ == ' _ _ main _ _ ' :\\n\\ts = \\\" LLRLRRL \\\"\\n\\tprint ( findDirection ( s ) )\\n\\ts = \\\" LL \\\"\\n\\tprint ( findDirection ( s ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Average of even numbers till a given even number | Program to find average of even numbers till a given even number . ; Function to calculate the average of even numbers ; driver function\\\"\\nSolution in C:\",\"targets\":\"#include \\nint averageEven ( int n ) { if ( n % 2 != 0 ) { printf ( \\\" Invalid \u2581 Input \\\" ) ; return -1 ; } return ( n + 2 ) \\/ 2 ; } int main ( ) { int n = 16 ; printf ( \\\" % d \\\" , averageEven ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count subarrays having an equal count of 0 s and 1 s segregated | C # program for the above approach ; Function to count subarrays having equal count of 0 s and 1 s with all 0 s and all 1 s grouped together ; Stores the count of subarrays ; If current element is different from the next array element ; Increment count ; Count the frequency of 1 s and 0 s ; Increment count ; Print the final count ; Driver Code ; Function Call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void countSubarrays ( int [ ] A , int N ) { int ans = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] != A [ i + 1 ] ) { ans ++ ; for ( int j = i - 1 , k = i + 2 ; j >= 0 && k < N && A [ j ] == A [ i ] && A [ k ] == A [ i + 1 ] ; j -- , k ++ ) { ans ++ ; } } } Console . Write ( ans + \\\" \\n \\\" ) ; } public static void Main ( ) { int [ ] A = { 1 , 1 , 0 , 0 , 1 , 0 } ; int N = A . Length ; countSubarrays ( A , N ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimum increment operations to make the array in increasing order | Java program to find minimum moves required to make the array in increasing order ; function to find minimum moves required to make the array in increasing order ; to store answer ; iterate over an array ; non - increasing order ; add moves to answer ; increase the element ; return required answer ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int MinimumMoves ( int a [ ] , int n , int x ) { int ans = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] <= a [ i - 1 ] ) { int p = ( a [ i - 1 ] - a [ i ] ) \\/ x + 1 ; ans += p ; a [ i ] += p * x ; } } return ans ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 3 , 3 , 2 } ; int x = 2 ; int n = arr . length ; System . out . println ( MinimumMoves ( arr , n , x ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum rotations required to get the same string | Returns count of rotations to get the same string back . ; tmp is the concatenated string . ; substring from i index of original string size . ; if substring matches with original string then we will come out of the loop . ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findRotations ( $ str ) { $ tmp = ( $ str + $ str ) ; $ n = strlen ( $ str ) ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ substring = $ tmp . substr ( $ i , strlen ( $ str ) ) ; if ( $ str == $ substring ) return $ i ; } return $ n ; } $ str = \\\" abc \\\" ; echo findRotations ( $ str ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Dynamic Programming | High | A DP based C ++ program to find maximum tasks . ; Returns the maximum among the 2 numbers ; Returns maximum amount of task that can be done till day n ; An array task_dp that stores the maximum task done ; If n = 0 , no solution exists ; If n = 1 , high effort task on that day will be the solution ; Fill the entire array determining which task to choose on day i ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint max ( int x , int y ) { return ( x > y ? x : y ) ; } int maxTasks ( int high [ ] , int low [ ] , int n ) { int task_dp [ n + 1 ] ; task_dp [ 0 ] = 0 ; task_dp [ 1 ] = high [ 0 ] ; for ( int i = 2 ; i <= n ; i ++ ) task_dp [ i ] = max ( high [ i - 1 ] + task_dp [ i - 2 ] , low [ i - 1 ] + task_dp [ i - 1 ] ) ; return task_dp [ n ] ; } int main ( ) { int n = 5 ; int high [ ] = { 3 , 6 , 8 , 7 , 6 } ; int low [ ] = { 1 , 5 , 4 , 5 , 3 } ; printf ( \\\" % d \\\" , maxTasks ( high , low , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum substring removals required to make all remaining characters of a string same | C ++ program to implement the above approach ; Function to count minimum operations required to make all characters equal by repeatedly removing substring ; Remove consecutive duplicate characters from str ; Stores length of the string ; Stores frequency of each distinct characters of the string str ; Iterate over all the characters of the string str ; Update frequency of str [ i ] ; Decrementing the frequency of the string str [ 0 ] ; Decrementing the frequency of the string str [ N - 1 ] ; Stores the required count ; Iterate over all characters of the string str ; Update ans ; Driver Code ; Given string\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void minOperationNeeded ( string str ) { str = string ( str . begin ( ) , unique ( str . begin ( ) , str . end ( ) ) ) ; int N = str . length ( ) ; int res [ 256 ] = { 0 } ; for ( int i = 0 ; i < N ; ++ i ) { res [ str [ i ] ] += 1 ; } res [ str [ 0 ] ] -= 1 ; res [ str [ N - 1 ] ] -= 1 ; int ans = INT_MAX ; for ( int i = 0 ; i < N ; ++ i ) { ans = min ( ans , res [ str [ i ] ] ) ; } cout << ( ans + 1 ) << endl ; } int main ( ) { string str = \\\" ABCDABCDABCDA \\\" ; minOperationNeeded ( str ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Split array into K subsets to maximize their sum of maximums and minimums | C ++ Program to implement the above approach ; Function that prints the maximum sum possible ; Find elements in each group ; Sort all elements in non - descending order ; Add K largest elements ; For sum of minimum elements from each subset ; Printing the maximum sum ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void maximumSum ( int arr [ ] , int n , int k ) { int elt = n \\/ k ; int sum = 0 ; sort ( arr , arr + n ) ; int count = 0 ; int i = n - 1 ; while ( count < k ) { sum += arr [ i ] ; i -- ; count ++ ; } count = 0 ; i = 0 ; while ( count < k ) { sum += arr [ i ] ; i += elt - 1 ; count ++ ; } cout << sum << \\\" \\n \\\" ; } int main ( ) { int Arr [ ] = { 1 , 13 , 7 , 17 , 6 , 5 } ; int K = 2 ; int size = sizeof ( Arr ) \\/ sizeof ( Arr [ 0 ] ) ; maximumSum ( Arr , size , K ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Program to find equation of a plane passing through 3 points | C program to find equation of a plane passing through given 3 points . ; Function to find equation of plane . ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nvoid equation_plane ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 , float x3 , float y3 , float z3 ) { float a1 = x2 - x1 ; float b1 = y2 - y1 ; float c1 = z2 - z1 ; float a2 = x3 - x1 ; float b2 = y3 - y1 ; float c2 = z3 - z1 ; float a = b1 * c2 - b2 * c1 ; float b = a2 * c1 - a1 * c2 ; float c = a1 * b2 - b1 * a2 ; float d = ( - a * x1 - b * y1 - c * z1 ) ; printf ( \\\" equation \u2581 of \u2581 plane \u2581 is \u2581 % .2f \u2581 x \u2581 + \u2581 % .2f \\\" \\\" \u2581 y \u2581 + \u2581 % .2f \u2581 z \u2581 + \u2581 % .2f \u2581 = \u2581 0 . \\\" , a , b , c , d ) ; return ; } int main ( ) { float x1 = -1 ; float y1 = 2 ; float z1 = 1 ; float x2 = 0 ; float y2 = -3 ; float z2 = 2 ; float x3 = 1 ; float y3 = 1 ; float z3 = -4 ; equation_plane ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count of N digit Numbers whose sum of every K consecutive digits is equal | C # program for the above approach ; Function to count the number of N - digit numbers such that sum of every k consecutive digits are equal ; Range of numbers ; Extract digits of the number ; Store the sum of first K digits ; Check for every k - consecutive digits ; If sum is not equal then break the loop ; Increment the count if it satisfy the given condition ; Driver Code ; Given N and K ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int countDigitSum ( int N , int K ) { int l = ( int ) Math . Pow ( 10 , N - 1 ) , r = ( int ) Math . Pow ( 10 , N ) - 1 ; int count = 0 ; for ( int i = l ; i <= r ; i ++ ) { int num = i ; int [ ] digits = new int [ N ] ; for ( int j = N - 1 ; j >= 0 ; j -- ) { digits [ j ] = num % 10 ; num \\/= 10 ; } int sum = 0 , flag = 0 ; for ( int j = 0 ; j < K ; j ++ ) sum += digits [ j ] ; for ( int j = 1 ; j < N - K + 1 ; j ++ ) { int curr_sum = 0 ; for ( int m = j ; m < j + K ; m ++ ) { curr_sum += digits [ m ] ; } if ( sum != curr_sum ) { flag = 1 ; break ; } } if ( flag == 0 ) { count ++ ; } } return count ; } public static void Main ( ) { int N = 2 , K = 1 ; Console . Write ( countDigitSum ( N , K ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find a N | C # program to find N digit number such that it is not divisible by any of its digits ; Function that print the answer ; if n == 1 then it is not possible ; loop to n - 1 times ; print 4 as last digit of the number ; Driver code ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void findTheNumber ( int n ) { if ( n == 1 ) { Console . Write ( \\\" Impossible \\\" + \\\" \\n \\\" ) ; return ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { Console . Write ( \\\"5\\\" ) ; } Console . Write ( \\\"4\\\" ) ; } public static void Main ( String [ ] args ) { int n = 12 ; findTheNumber ( n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find the smallest number whose sum of digits is N | C # program to find the smallest number whose sum of digits is also N ; Function to find the smallest number whose sum of digits is also N ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void smallestNumber ( int N ) { Console . WriteLine ( ( N % 9 + 1 ) * Math . Pow ( 10 , ( N \\/ 9 ) ) - 1 ) ; } public static void Main ( ) { int N = 10 ; smallestNumber ( N ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Same Number Of Set Bits As N | returns number of set bits in a number ; function ; __builtin_popcount function that count set bits in n ; Iterate from n - 1 to 1 ; check if the number of set bits equals to temp increment count ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function __builtin_popcount ( $ n ) { $ t = 0 ; while ( $ n > 0 ) { $ d = $ n % 2 ; $ n = intval ( $ n \\/ 2 ) ; if ( $ d == 1 ) $ t ++ ; } return $ t ; } function smallerNumsWithSameSetBits ( $ n ) { $ temp = __builtin_popcount ( $ n ) ; $ count = 0 ; for ( $ i = $ n - 1 ; $ i > 0 ; $ i -- ) { if ( $ temp == __builtin_popcount ( $ i ) ) $ count ++ ; } return $ count ; } $ n = 4 ; echo ( smallerNumsWithSameSetBits ( $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Number of subarrays with GCD equal to 1 | C ++ implementation of the approach ; Function to return the required count ; To store the final answer ; To store the GCD starting from index ' i ' ; Loop to find the gcd of each subarray from arr [ i ] to arr [ i ... n - 1 ] ; Increment the count if curr_gcd = 1 ; Return the final answer ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int cntSubArr ( int * arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int curr_gcd = 0 ; for ( int j = i ; j < n ; j ++ ) { curr_gcd = __gcd ( curr_gcd , arr [ j ] ) ; ans += ( curr_gcd == 1 ) ; } } return ans ; } int main ( ) { int arr [ ] = { 1 , 1 , 1 } ; int n = sizeof ( arr ) \\/ sizeof ( int ) ; cout << cntSubArr ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count distinct occurrences as a subsequence | Java program to count number of times S appears as a subsequence in T ; T can 't appear as a subsequence in S ; mat [ i ] [ j ] stores the count of occurrences of T ( 1. . i ) in S ( 1. . j ) . ; Initializing first column with all 0 s . An emptystring can 't have another string as suhsequence ; Initializing first row with all 1 s . An empty string is subsequence of all . ; Fill mat [ ] [ ] in bottom up manner ; If last characters don 't match, then value is same as the value without last character in S. ; Else value is obtained considering two cases . a ) All substrings without last character in S b ) All substrings without last characters in both . ; uncomment this to print matrix mat for ( int i = 1 ; i <= m ; i ++ , cout << endl ) for ( int j = 1 ; j <= n ; j ++ ) System . out . println ( mat [ i ] [ j ] + \\\" \u2581 \\\" ) ; ; Driver code to check above method\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int findSubsequenceCount ( String S , String T ) { int m = T . length ( ) ; int n = S . length ( ) ; if ( m > n ) return 0 ; int mat [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ; for ( int i = 1 ; i <= m ; i ++ ) mat [ i ] [ 0 ] = 0 ; for ( int j = 0 ; j <= n ; j ++ ) mat [ 0 ] [ j ] = 1 ; for ( int i = 1 ; i <= m ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( T . charAt ( i - 1 ) != S . charAt ( j - 1 ) ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ; else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ; } } return mat [ m ] [ n ] ; } public static void main ( String [ ] args ) { String T = \\\" ge \\\" ; String S = \\\" geeksforgeeks \\\" ; System . out . println ( findSubsequenceCount ( S , T ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Print all subsequences of a string | Iterative Method | Java program to print all Subsequences of a String in iterative manner ; Function to find subsequence ; Check if jth bit in binary is 1 ; If jth bit is 1 , include it in subsequence ; Function to print all subsequences ; Map to store subsequence lexicographically by length ; Total number of non - empty subsequence in String is 2 ^ len - 1 ; i = 0 , corresponds to empty subsequence ; Subsequence for binary pattern i ; Storing sub in map ; it . first is length of Subsequence it . second is set < String > ; ii is iterator of type set < String > ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . SortedMap ; import java . util . TreeMap ; class Graph { static String subsequence ( String s , int binary , int len ) { String sub = \\\" \\\" ; for ( int j = 0 ; j < len ; j ++ ) if ( ( binary & ( 1 << j ) ) != 0 ) sub += s . charAt ( j ) ; return sub ; } static void possibleSubsequences ( String s ) { SortedMap < Integer , HashSet < String > > sorted_subsequence = new TreeMap < Integer , HashSet < String > > ( ) ; int len = s . length ( ) ; int limit = ( int ) Math . pow ( 2 , len ) ; for ( int i = 1 ; i <= limit - 1 ; i ++ ) { String sub = subsequence ( s , i , len ) ; if ( ! sorted_subsequence . containsKey ( sub . length ( ) ) ) sorted_subsequence . put ( sub . length ( ) , new HashSet < > ( ) ) ; sorted_subsequence . get ( sub . length ( ) ) . add ( sub ) ; } for ( Map . Entry < Integer , HashSet < String > > it : sorted_subsequence . entrySet ( ) ) { System . out . println ( \\\" Subsequences \u2581 of \u2581 length \u2581 = \u2581 \\\" + it . getKey ( ) + \\\" \u2581 are : \\\" ) ; for ( String ii : it . getValue ( ) ) System . out . print ( ii + \\\" \u2581 \\\" ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { String s = \\\" aabc \\\" ; possibleSubsequences ( s ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Smallest element in an array that is repeated exactly ' k ' times . | finds the smallest number in arr [ ] that is repeated k times ; Sort the array ; Find the first element with exactly k occurrences . ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function findDuplicate ( $ arr , $ n , $ k ) { sort ( $ arr ) ; $ i = 0 ; while ( $ i < $ n ) { $ j ; $ count = 1 ; for ( $ j = $ i + 1 ; $ j < $ n && $ arr [ $ j ] == $ arr [ $ i ] ; $ j ++ ) $ count ++ ; if ( $ count == $ k ) return $ arr [ $ i ] ; $ i = $ j ; } return -1 ; } $ arr = array ( 2 , 2 , 1 , 3 , 1 ) ; $ k = 2 ; $ n = sizeof ( $ arr ) ; echo ( findDuplicate ( $ arr , $ n , $ k ) ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Pell Number | Iterative Pell Number Series in C ; calculate nth pell number ; driver function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint pell ( int n ) { if ( n <= 2 ) return n ; int a = 1 ; int b = 2 ; int c , i ; for ( i = 3 ; i <= n ; i ++ ) { c = 2 * b + a ; a = b ; b = c ; } return b ; } int main ( ) { int n = 4 ; printf ( \\\" % d \\\" , pell ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find all missing numbers from a given sorted array | C # program for the above approach ; Function to find the missing elements ; Initialize an array with zero of size equals to the maximum element in the array ; Make b [ i ] = 1 if i is present in the array ; If the element is present make b [ arr [ i ] ] = 1 ; Print the indices where b [ i ] = 0 ; Driver Code ; Given array [ ] arr ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void printMissingElements ( int [ ] arr , int N ) { int [ ] b = new int [ arr [ N - 1 ] + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { b [ arr [ i ] ] = 1 ; } for ( int i = arr [ 0 ] ; i <= arr [ N - 1 ] ; i ++ ) { if ( b [ i ] == 0 ) { Console . Write ( i + \\\" \u2581 \\\" ) ; } } } public static void Main ( String [ ] args ) { int [ ] arr = { 6 , 7 , 10 , 11 , 13 } ; int N = arr . Length ; printMissingElements ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"k | PHP program to find k - th prime factor using Sieve Of Eratosthenes . This program is efficient when we have a range of numbers . ; Using SieveOfEratosthenes to find smallest prime factor of all the numbers . For example , if MAX is 10 , s [ 2 ] = s [ 4 ] = s [ 6 ] = s [ 10 ] = 2 s [ 3 ] = s [ 9 ] = 3 s [ 5 ] = 5 s [ 7 ] = 7 ; Create a boolean array \\\" prime [ 0 . . MAX ] \\\" and initialize all entries in it as false . ; Initializing smallest factor equal to 2 for all the even numbers ; For odd numbers less then equal to n ; s ( i ) for a prime is the number itself ; For all multiples of current prime number ; i is the smallest prime factor for number \\\" i * j \\\" . ; Function to generate prime factors and return its k - th prime factor . s [ i ] stores least prime factor of i . ; Keep dividing n by least prime factor while either n is not 1 or count of prime factors is not k . ; To keep track of count of prime factors ; Divide n to find next prime factor ; s [ i ] is going to store prime factor of i .\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ MAX = 10001 ; function sieveOfEratosthenes ( & $ s ) { global $ MAX ; $ prime = array_fill ( 0 , $ MAX + 1 , false ) ; for ( $ i = 2 ; $ i <= $ MAX ; $ i += 2 ) $ s [ $ i ] = 2 ; for ( $ i = 3 ; $ i <= $ MAX ; $ i += 2 ) { if ( $ prime [ $ i ] == false ) { $ s [ $ i ] = $ i ; for ( $ j = $ i ; $ j * $ i <= $ MAX ; $ j += 2 ) { if ( $ prime [ $ i * $ j ] == false ) { $ prime [ $ i * $ j ] = true ; $ s [ $ i * $ j ] = $ i ; } } } } } function kPrimeFactor ( $ n , $ k , $ s ) { while ( $ n > 1 ) { if ( $ k == 1 ) return $ s [ $ n ] ; $ k -- ; $ n = ( int ) ( $ n \\/ $ s [ $ n ] ) ; } return -1 ; } $ s = array_fill ( 0 , $ MAX + 1 , -1 ) ; sieveOfEratosthenes ( $ s ) ; $ n = 12 ; $ k = 3 ; print ( kPrimeFactor ( $ n , $ k , $ s ) . \\\" \\\" ) ; $ n = 14 ; $ k = 3 ; print ( kPrimeFactor ( $ n , $ k , $ s ) ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Measure one litre using two vessels and infinite water supply | Sample run of the Algo for V1 with capacity 3 and V2 with capacity 7 1. Fill V1 : V1 = 3 , V2 = 0 2. Transfer from V1 to V2 , and fill V1 : V1 = 3 , V2 = 3 2. Transfer from V1 to V2 , and fill V1 : V1 = 3 , V2 = 6 3. Transfer from V1 to V2 , and empty V2 : V1 = 2 , V2 = 0 4. Transfer from V1 to V2 , and fill V1 : V1 = 3 , V2 = 2 5. Transfer from V1 to V2 , and fill V1 : V1 = 3 , V2 = 5 6. Transfer from V1 to V2 , and empty V2 : V1 = 1 , V2 = 0 7. Stop as V1 now contains 1 litre . Note that V2 was made empty in steps 3 and 6 because it became full ; A utility function to get GCD of two numbers ; Class to represent a Vessel ; A vessel has capacity , and current amount of water in it ; Constructor : initializes capacity as given , and current as 0 ; The main function to fill one litre in this vessel . Capacity of V2 must be greater than this vessel and two capacities must be coprime ; solution exists iff a and b are co - prime ; fill A ( smaller vessel ) ; Transfer water from V1 to V2 and reduce current of V1 by the amount equal to transferred water ; Finally , there will be 1 litre in vessel 1 ; Fills vessel with given amount and returns the amount of water transferred to it . If the vessel becomes full , then the vessel is made empty ; If the vessel can accommodate the given amount ; If the vessel cannot accommodate the given amount , then store the amount of water transferred ; Since the vessel becomes full , make the vessel empty so that it can be filled again ; Driver program to test above function ; a must be smaller than b ; Create two vessels of capacities a and b ; Get 1 litre in first vessel\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int gcd ( int a , int b ) { return b > 0 ? gcd ( b , a % b ) : a ; } static class Vessel { int capacity , current ; public Vessel ( int capacity ) { this . capacity = capacity ; current = 0 ; } void makeOneLitre ( Vessel V2 ) { if ( gcd ( capacity , V2 . capacity ) != 1 ) return ; while ( current != 1 ) { if ( current == 0 ) current = capacity ; System . out . print ( \\\" Vessel \u2581 1 : \u2581 \\\" + current + \\\" \u2581 Vessel \u2581 2 : \u2581 \\\" + V2 . current + \\\"\\n\\\"); current = current - V2 . transfer ( current ) ; } System . out . print ( \\\" Vessel \u2581 1 : \u2581 \\\" + current + \\\" \u2581 Vessel \u2581 2 : \u2581 \\\" + V2 . current + \\\"\\n\\\"); } int transfer ( int amount ) { if ( current + amount < capacity ) { current += amount ; return amount ; } int transferred = capacity - current ; current = 0 ; return transferred ; } } public static void main ( String [ ] args ) { int a = 3 , b = 7 ; Vessel V1 = new Vessel ( a ) ; Vessel V2 = new Vessel ( b ) ; V1 . makeOneLitre ( V2 ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count all possible groups of size 2 or 3 that have sum as multiple of 3 | Java Program to count all possible groups of size 2 or 3 that have sum as multiple of 3 ; Returns count of all possible groups that can be formed from elements of a [ ] . ; Create an array C [ 3 ] to store counts of elements with remainder 0 , 1 and 2. c [ i ] would store count of elements with remainder i ; To store the result ; Count elements with remainder 0 , 1 and 2 ; Case 3. a : Count groups of size 2 from 0 remainder elements ; Case 3. b : Count groups of size 2 with one element with 1 remainder and other with 2 remainder ; Case 4. a : Count groups of size 3 with all 0 remainder elements ; Case 4. b : Count groups of size 3 with all 1 remainder elements ; Case 4. c : Count groups of size 3 with all 2 remainder elements ; Case 4. c : Count groups of size 3 with different remainders ; Return total count stored in res ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"class FindGroups { int findgroups ( int arr [ ] , int n ) { int c [ ] = new int [ ] { 0 , 0 , 0 } ; int i ; int res = 0 ; for ( i = 0 ; i < n ; i ++ ) c [ arr [ i ] % 3 ] ++ ; res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ; res += c [ 1 ] * c [ 2 ] ; res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) \\/ 6 ; res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) \\/ 6 ; res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) \\/ 6 ) ; res += c [ 0 ] * c [ 1 ] * c [ 2 ] ; return res ; } public static void main ( String [ ] args ) { FindGroups groups = new FindGroups ( ) ; int arr [ ] = { 3 , 6 , 7 , 2 , 9 } ; int n = arr . length ; System . out . println ( \\\" Required \u2581 number \u2581 of \u2581 groups \u2581 are \u2581 \\\" + groups . findgroups ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Section formula for 3 D | Function to find the section of the line ; Applying section formula ; Printing result ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function section ( $ x1 , $ x2 , $ y1 , $ y2 , $ z1 , $ z2 , $ m , $ n ) { $ x = ( ( $ m * $ x2 ) + ( $ n * $ x1 ) ) \\/ ( $ m + $ n ) ; $ y = ( ( $ m * $ y2 ) + ( $ n * $ y1 ) ) \\/ ( $ m + $ n ) ; $ z = ( ( $ m * $ z2 ) + ( $ n * $ z1 ) ) \\/ ( $ m + $ n ) ; echo \\\" ( \\\" . $ x . \\\" , \\\" ; \u2581 echo \u2581 $ y \u2581 . \u2581 \\\" , \\\" ; \u2581 echo \u2581 $ z \u2581 . \u2581 \\\" ) \\\" \u2581 . \\\" \\\" } $ x1 = 2 ; $ x2 = 4 ; $ y1 = -1 ; $ y2 = 3 ; $ z1 = 4 ; $ z2 = 2 ; $ m = 2 ; $ n = 3 ; section ( $ x1 , $ x2 , $ y1 , $ y2 , $ z1 , $ z2 , $ m , $ n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count minimum number of moves to front or end to sort an array | Java program for the above approach ; Function that counts the minimum moves required to covert arr [ ] to brr [ ] ; Base Case ; If arr [ i ] < arr [ j ] ; Include the current element ; Otherwise , excluding the current element ; Function that counts the minimum moves required to sort the array ; If both the arrays are equal ; No moves required ; Otherwise ; Print minimum operations required ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; import java . io . * ; import java . lang . Math ; class GFG { static int minOperations ( int arr1 [ ] , int arr2 [ ] , int i , int j ) { if ( arr1 . equals ( arr2 ) ) return 0 ; if ( i >= arr1 . length j >= arr2 . length ) return 0 ; if ( arr1 [ i ] < arr2 [ j ] ) return 1 + minOperations ( arr1 , arr2 , i + 1 , j + 1 ) ; return Math . max ( minOperations ( arr1 , arr2 , i , j + 1 ) , minOperations ( arr1 , arr2 , i + 1 , j ) ) ; } static void minOperationsUtil ( int [ ] arr ) { int brr [ ] = new int [ arr . length ] ; for ( int i = 0 ; i < arr . length ; i ++ ) brr [ i ] = arr [ i ] ; Arrays . sort ( brr ) ; if ( arr . equals ( brr ) ) System . out . print ( \\\"0\\\" ) ; else System . out . println ( minOperations ( arr , brr , 0 , 0 ) ) ; } public static void main ( final String [ ] args ) { int arr [ ] = { 4 , 7 , 2 , 3 , 9 } ; minOperationsUtil ( arr ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Smallest Palindrome after replacement | Java program to get lexicographically smallest palindrome string ; Utility method to check str is possible palindrome after ignoring ; If both left and right character are not dot and they are not equal also , then it is not possible to make this string a palindrome ; Returns lexicographically smallest palindrome string , if possible ; loop through character of string ; if one of character is dot , replace dot with other character ; if both character are dot , then replace them with smallest character ' a ' ; return the result ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static boolean isPossiblePalindrome ( char str [ ] ) { int n = str . length ; for ( int i = 0 ; i < n \\/ 2 ; i ++ ) { if ( str [ i ] != ' . ' && str [ n - i - 1 ] != ' . ' && str [ i ] != str [ n - i - 1 ] ) return false ; } return true ; } static void smallestPalindrome ( char str [ ] ) { if ( ! isPossiblePalindrome ( str ) ) System . out . println ( \\\" Not \u2581 Possible \\\" ) ; int n = str . length ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' . ' ) { if ( str [ n - i - 1 ] != ' . ' ) str [ i ] = str [ n - i - 1 ] ; else str [ i ] = str [ n - i - 1 ] = ' a ' ; } } for ( int i = 0 ; i < n ; i ++ ) System . out . print ( str [ i ] + \\\" \\\" ) ; } public static void main ( String [ ] args ) { String str = \\\" ab . . e . c . a \\\" ; char [ ] s = str . toCharArray ( ) ; smallestPalindrome ( s ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Number of n digit stepping numbers | Space optimized solution | function that calculates the answer ; dp [ j ] stores count of i digit stepping numbers ending with digit j . ; To store result of length i - 1 before updating dp [ j ] for length i . ; if n is 1 then answer will be 10. ; Initialize values for count of digits equal to 1. ; Compute values for count of digits more than 1. ; If ending digit is 0 ; If ending digit is 9 ; For other digits . ; stores the final answer ; driver program to test the above function\\\"\\nSolution in Javascript:\",\"targets\":\"function answer ( n ) { var dp = Array ( 10 ) ; var prev = Array ( 10 ) ; if ( n == 1 ) return 10 ; for ( var j = 0 ; j <= 9 ; j ++ ) dp [ j ] = 1 ; for ( var i = 2 ; i <= n ; i ++ ) { for ( var j = 0 ; j <= 9 ; j ++ ) { prev [ j ] = dp [ j ] ; } for ( var j = 0 ; j <= 9 ; j ++ ) { if ( j == 0 ) dp [ j ] = prev [ j + 1 ] ; else if ( j == 9 ) dp [ j ] = prev [ j - 1 ] ; else dp [ j ] = prev [ j - 1 ] + prev [ j + 1 ] ; } } var sum = 0 ; for ( var j = 1 ; j <= 9 ; j ++ ) sum += dp [ j ] ; return sum ; } var n = 2 ; document . write ( answer ( n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to make Bitwise XOR of odd and even indexed elements equal by removing an array element | Function to count ways to make Bitwise XOR of odd and even indexed elements equal by removing an array element ; Stores xor of odd and even indexed elements from the end ; Stores xor of odd and even indexed elements from the start ; Stores the required count ; Traverse the array in reverse ; If i is odd ; If i is even ; Traverse the array ; If i is odd ; If i is even ; Removing arr [ i ] , post_even stores XOR of odd indexed elements ; Removing arr [ i ] , post_odd stores XOR of even indexed elements ; Check if they are equal ; If i is odd , xor it with curr_odd ; If i is even , xor it with curr_even ; Finally print res ; Drivers Code ; Given array ; Given size ; Function call\\\"\\nSolution in Python:\",\"targets\":\"def Remove_one_element ( arr , n ) :\\n\\tpost_odd = 0\\n\\tpost_even = 0\\n\\tcurr_odd = 0\\n\\tcurr_even = 0\\n\\tres = 0\\n\\tfor i in range ( n - 1 , - 1 , - 1 ) :\\n\\t\\tif ( i % 2 ) :\\n\\t\\t\\tpost_odd ^= arr [ i ]\\n\\t\\telse :\\n\\t\\t\\tpost_even ^= arr [ i ]\\n\\tfor i in range ( n ) :\\n\\t\\tif ( i % 2 ) :\\n\\t\\t\\tpost_odd ^= arr [ i ]\\n\\t\\telse :\\n\\t\\t\\tpost_even ^= arr [ i ]\\n\\t\\tX = curr_odd ^ post_even\\n\\t\\tY = curr_even ^ post_odd\\n\\t\\tif ( X == Y ) :\\n\\t\\t\\tres += 1\\n\\t\\tif ( i % 2 ) :\\n\\t\\t\\tcurr_odd ^= arr [ i ]\\n\\t\\telse :\\n\\t\\t\\tcurr_even ^= arr [ i ]\\n\\tprint ( res )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ 1 , 0 , 1 , 0 , 1 ]\\n\\tN = len ( arr )\\n\\tRemove_one_element ( arr , N )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sequences of given length where every element is more than or equal to twice of previous | C # program to count total number of special sequences of length n where every element is more than or equal to twice of previous ; Recursive function to find the number of special sequences ; A special sequence cannot exist if length n is more than the maximum value m . ; If n is 0 , found an empty special sequence ; There can be two possibilities : ( 1 ) Reduce last element value ( 2 ) Consider last element as m and reduce number of terms ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int getTotalNumberOfSequences ( int m , int n ) { if ( m < n ) return 0 ; if ( n == 0 ) return 1 ; return getTotalNumberOfSequences ( m - 1 , n ) + getTotalNumberOfSequences ( m \\/ 2 , n - 1 ) ; } public static void Main ( ) { int m = 10 ; int n = 4 ; Console . Write ( \\\" Total \u2581 number \u2581 of \u2581 possible \u2581 sequences \u2581 \\\" + getTotalNumberOfSequences ( m , n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Cost required to make all array elements equal to 1 | Function to calculate the cost required to make all array elements equal to 1 ; Stores the total cost ; Traverse the array arr [ ] ; If current element is 0 ; Convert 0 to 1 ; Add the cost ; Return the total cost ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function findCost ( A , N ) { var totalCost = 0 ; var i ; for ( i = 0 ; i < N ; i ++ ) { if ( A [ i ] == 0 ) { A [ i ] = 1 ; totalCost += i ; } } return totalCost ; } var arr = [ 1 , 0 , 1 , 0 , 1 , 0 ] var N = arr . length document . write ( findCost ( arr , N ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Ways to multiply n elements with an associative operation | C ++ code to find number of ways to multiply n elements with an associative operation ; Function to find the required factorial ; Function to find nCr ; function to find the number of ways ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"# include \\nusing namespace std ; int fact ( int n ) { if ( n == 0 n == 1 ) return 1 ; int ans = 1 ; for ( int i = 1 ; i <= n ; i ++ ) ans = ans * i ; return ans ; } int nCr ( int n , int r ) { int Nr = n , Dr = 1 , ans = 1 ; for ( int i = 1 ; i <= r ; i ++ ) { ans = ( ans * Nr ) \\/ ( Dr ) ; Nr -- ; Dr ++ ; } return ans ; } int solve ( int n ) { int N = 2 * n - 2 ; int R = n - 1 ; return nCr ( N , R ) * fact ( n - 1 ) ; } int main ( ) { int n = 6 ; cout << solve ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Hoax Number | C # code to check if a number is a hoax number or not . ; Function to find distinct prime factors of given number n ; n is odd at this point , since it is no longer divisible by 2. So we can test only for the odd numbers , whether they are factors of n ; Check if i is prime factor ; This condition is to handle the case when n is a prime number greater than 2 ; Function to calculate sum of digits of distinct prime factors of given number n and sum of digits of number n and compare the sums obtained ; Distinct prime factors of n are being stored in vector pf ; If n is a prime number , it cannot be a hoax number ; Finding sum of digits of distinct prime factors of the number n ; Finding sum of digits in current prime factor pf [ i ] . ; Finding sum of digits of number n ; Comparing the two calculated sums ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static List < int > primeFactors ( int n ) { List < int > res = new List < int > ( ) ; if ( n % 2 == 0 ) { while ( n % 2 == 0 ) n = n \\/ 2 ; res . Add ( 2 ) ; } for ( int i = 3 ; i <= Math . Sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { while ( n % i == 0 ) n = n \\/ i ; res . Add ( i ) ; } } if ( n > 2 ) res . Add ( n ) ; return res ; } static bool isHoax ( int n ) { List < int > pf = primeFactors ( n ) ; if ( pf [ 0 ] == n ) return false ; int all_pf_sum = 0 ; for ( int i = 0 ; i < pf . Count ; i ++ ) { int pf_sum ; for ( pf_sum = 0 ; pf [ i ] > 0 ; pf_sum += pf [ i ] % 10 , pf [ i ] \\/= 10 ) ; all_pf_sum += pf_sum ; } int sum_n ; for ( sum_n = 0 ; n > 0 ; sum_n += n % 10 , n \\/= 10 ) ; return sum_n == all_pf_sum ; } public static void Main ( ) { int n = 84 ; if ( isHoax ( n ) ) Console . Write ( \\\" A \u2581 Hoax \u2581 Number \\n \\\" ) ; else Console . Write ( \\\" Not \u2581 a \u2581 Hoax \u2581 Number \\n \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Distance between two parallel Planes in 3 | C ++ program to find the Distance between two parallel Planes in 3 D . ; Function to find distance ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#include \\nusing namespace std ; void distance ( float a1 , float b1 , float c1 , float d1 , float a2 , float b2 , float c2 , float d2 ) { float x1 , y1 , z1 , d ; if ( a1 \\/ a2 == b1 \\/ b2 && b1 \\/ b2 == c1 \\/ c2 ) { x1 = y1 = 0 ; z1 = - d1 \\/ c1 ; d = fabs ( ( c2 * z1 + d2 ) ) \\/ ( sqrt ( a2 * a2 + b2 * b2 + c2 * c2 ) ) ; cout << \\\" Perpendicular \u2581 distance \u2581 is \u2581 \\\" << d << endl ; } else cout << \\\" Planes \u2581 are \u2581 not \u2581 parallel \\\" ; return ; } int main ( ) { float a1 = 1 ; float b1 = 2 ; float c1 = -1 ; float d1 = 1 ; float a2 = 3 ; float b2 = 6 ; float c2 = -3 ; float d2 = -4 ; distance ( a1 , b1 , c1 , d1 , a2 , b2 , c2 , d2 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimum LCM and GCD possible among all possible sub | Python3 implementation of the approach ; Function to return minimum GCD among all subarrays ; Minimum GCD among all sub - arrays will be the GCD of all the elements of the array ; Function to return minimum LCM among all subarrays ; Minimum LCM among all sub - arrays will be the minimum element from the array ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"from math import gcd\\ndef minGCD ( arr , n ) :\\n\\tminGCD = 0 ;\\n\\tfor i in range ( n ) :\\n\\t\\tminGCD = gcd ( minGCD , arr [ i ] ) ;\\n\\treturn minGCD ;\\ndef minLCM ( arr , n ) :\\n\\tminLCM = arr [ 0 ] ;\\n\\tfor i in range ( 1 , n ) :\\n\\t\\tminLCM = min ( minLCM , arr [ i ] ) ;\\n\\treturn minLCM ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ 2 , 66 , 14 , 521 ] ;\\n\\tn = len ( arr ) ;\\n\\tprint ( \\\" LCM \u2581 = \u2581 \\\" , minLCM ( arr , n ) , \\\" , \u2581 GCD \u2581 = \\\" , minGCD ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Probability that the sum of all numbers obtained on throwing a dice N times lies between two given integers | Python program for above approach ; Function to calculate the probability for the given sum to be equal to sum in N throws of dice ; Base cases ; Driver Code ; Calculate probability of all sums from a to b ; Prthe answer\\\"\\nHow can the above be solved in Python?\",\"targets\":\"dp = [ [ 0 for i in range ( 605 ) ] for j in range ( 105 ) ] ;\\ndef find ( N , sum ) :\\n\\tif ( N < 0 sum < 0 ) :\\n\\t\\treturn 0 ;\\n\\tif ( dp [ N ] [ sum ] > 0 ) :\\n\\t\\treturn dp [ N ] [ sum ] ;\\n\\tif ( sum > 6 * N or sum < N ) :\\n\\t\\treturn 0 ;\\n\\tif ( N == 1 ) :\\n\\t\\tif ( sum >= 1 and sum <= 6 ) :\\n\\t\\t\\treturn ( float ) ( 1.0 \\/ 6 ) ;\\n\\t\\telse :\\n\\t\\t\\treturn 0 ;\\n\\tfor i in range ( 1 , 7 ) :\\n\\t\\tdp [ N ] [ sum ] = dp [ N ] [ sum ] + find ( N - 1 , sum - i ) \\/ 6 ;\\n\\treturn dp [ N ] [ sum ] ;\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 4 ; a = 13 ; b = 17 ;\\n\\tprobability = 0.0\\n\\tf = 0 ;\\n\\tfor sum in range ( a , b + 1 ) :\\n\\t\\tprobability = probability + find ( N , sum ) ;\\n\\tprint ( \\\" % .6f \\\" % probability ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Search for an element in a Mountain Array | Function to find the index of the peak element in the array ; Stores left most index in which the peak element can be found ; Stores right most index in which the peak element can be found ; Stores mid of left and right ; If element at mid is less than element at ( mid + 1 ) ; Update left ; Update right ; Function to perform binary search in an a subarray if elements of the subarray are in an ascending order ; Stores mid of left and right ; If X found at mid ; If X is greater than mid ; Update left ; Update right ; Function to perform binary search in an a subarray if elements of the subarray are in an ascending order ; Stores mid of left and right ; If X found at mid ; Update right ; Update left ; Function to find the smallest index of X ; Stores index of peak element in array ; Stores index of X in the array ; If X greater than or equal to first element of array and less than the peak element ; Update res ; If element not found on left side of peak element ; Update res ; Print res ; Driver Code ; Given X ; Given array ; Function Call\\\"\\nSolution in Python:\",\"targets\":\"def findPeak ( arr ) :\\n\\tleft = 0\\n\\tright = len ( arr ) - 1\\n\\twhile ( left < right ) :\\n\\t\\tmid = left + ( right - left ) \\/\\/ 2\\n\\t\\tif ( arr [ mid ] < arr [ ( mid + 1 ) ] ) :\\n\\t\\t\\tleft = mid + 1\\n\\t\\telse :\\n\\t\\t\\tright = mid\\n\\treturn left\\ndef BS ( X , left , right , arr ) :\\n\\twhile ( left <= right ) :\\n\\t\\tmid = left + ( right - left ) \\/\\/ 2\\n\\t\\tif ( arr [ mid ] == X ) :\\n\\t\\t\\treturn mid\\n\\t\\telif ( X > arr [ mid ] ) :\\n\\t\\t\\tleft = mid + 1\\n\\t\\telse :\\n\\t\\t\\tright = mid - 1\\n\\treturn - 1\\ndef reverseBS ( X , left , right , arr ) :\\n\\twhile ( left <= right ) :\\n\\t\\tmid = left + ( right - left ) \\/\\/ 2\\n\\t\\tif ( arr [ mid ] == X ) :\\n\\t\\t\\treturn mid\\n\\t\\telif ( X > arr [ mid ] ) :\\n\\t\\t\\tright = mid - 1\\n\\t\\telse :\\n\\t\\t\\tleft = mid + 1\\n\\treturn - 1\\ndef findInMA ( X , mountainArr ) :\\n\\tpeakIndex = findPeak ( mountainArr )\\n\\tres = - 1\\n\\tif ( X >= mountainArr [ 0 ] and X <= mountainArr [ peakIndex ] ) :\\n\\t\\tres = BS ( X , 0 , peakIndex , mountainArr )\\n\\tif ( res == - 1 ) :\\n\\t\\tres = reverseBS ( X , peakIndex + 1 , mountainArr . size ( ) - 1 , mountainArr )\\n\\tprint ( res )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tX = 3\\n\\tarr = [ 1 , 2 , 3 , 4 , 5 , 3 , 1 ]\\n\\tfindInMA ( X , arr )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Next greater number than N with exactly one bit different in binary representation of N | Function to find next greater number than N with exactly one bit different in binary representation of N ; It is guaranteed that there is a bit zero in the number ; If the shifted bit is zero then break ; increase the bit shift ; increase the power of 2 ; set the lowest bit of the number ; Driver code ; display the next number\\\"\\nSolution in Javascript:\",\"targets\":\"function nextGreater ( N ) { var power_of_2 = 1 , shift_count = 0 ; while ( true ) { if ( ( ( N >> shift_count ) & 1 ) % 2 == 0 ) break ; shift_count ++ ; power_of_2 = power_of_2 * 2 ; } return ( N + power_of_2 ) ; } var N = 11 ; document . write ( \\\" \\\" + nextGreater ( N ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Coin Change | DP | Returns the count of ways we can sum S [ 0. . . m - 1 ] coins to get sum n ; If n is 0 then there is 1 solution ( do not include any coin ) ; If n is less than 0 then no solution exists ; If there are no coins and n is greater than 0 , then no solution exist ; count is sum of solutions ( i ) including S [ m - 1 ] ( ii ) excluding S [ m - 1 ] ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function coun ( $ S , $ m , $ n ) { if ( $ n == 0 ) return 1 ; if ( $ n < 0 ) return 0 ; if ( $ m <= 0 && $ n >= 1 ) return 0 ; return coun ( $ S , $ m - 1 , $ n ) + coun ( $ S , $ m , $ n - $ S [ $ m - 1 ] ) ; } $ arr = array ( 1 , 2 , 3 ) ; $ m = count ( $ arr ) ; echo coun ( $ arr , $ m , 4 ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find length of longest Fibonacci like subsequence | CPP implementation of above approach ; Function to return the max Length of Fibonacci subsequence ; Store all array elements in a hash table ; check until next fib element is found ; next element of fib subseq ; Driver program\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int LongestFibSubseq ( int A [ ] , int n ) { unordered_set < int > S ( A , A + n ) ; int maxLen = 0 , x , y ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = i + 1 ; j < n ; ++ j ) { x = A [ j ] ; y = A [ i ] + A [ j ] ; int length = 2 ; while ( S . find ( y ) != S . end ( ) ) { int z = x + y ; x = y ; y = z ; maxLen = max ( maxLen , ++ length ) ; } } } return maxLen >= 3 ? maxLen : 0 ; } int main ( ) { int A [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } ; int n = sizeof ( A ) \\/ sizeof ( A [ 0 ] ) ; cout << LongestFibSubseq ( A , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find substrings that contain all vowels | C # program to find all substring that contain all vowels ; Returns true if x is vowel . ; Function to check whether a character is vowel or not ; To store vowels Outer loop picks starting character and inner loop picks ending character . ; If current character is not vowel , then no more result substrings possible starting from str [ i ] . ; If vowel , then we insert it in hash ; If all vowels are present in current substring ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; public class GFG { public static bool isVowel ( char x ) { return ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } public static void findSubstring ( string str ) { HashSet < char > hash = new HashSet < char > ( ) ; int n = str . Length ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { if ( isVowel ( str [ j ] ) == false ) { break ; } hash . Add ( str [ j ] ) ; if ( hash . Count == 5 ) { Console . Write ( str . Substring ( i , ( j + 1 ) - i ) + \\\" \u2581 \\\" ) ; } } hash . Clear ( ) ; } } public static void Main ( string [ ] args ) { string str = \\\" aeoibsddaeiouudb \\\" ; findSubstring ( str ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximum Balanced String Partitions | C ++ program to find a maximum number X , such that a given string can be partitioned into X substrings that are each balanced ; Function to find a maximum number X , such that a given string can be partitioned into X substrings that are each balanced ; If the size of the string is 0 , then answer is zero ; variable that represents the number of ' R ' s and ' L ' s ; To store maximum number of possible partitions ; increment the variable r if the character in the string is ' R ' ; increment the variable l if the character in the string is ' L ' ; if r and l are equal , then increment ans ; Return the required answer ; Driver code ; Function call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int BalancedPartition ( string str , int n ) { if ( n == 0 ) return 0 ; int r = 0 , l = 0 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' R ' ) { r ++ ; } else if ( str [ i ] = ' L ' ) { l ++ ; } if ( r == l ) { ans ++ ; } } return ans ; } int main ( ) { string str = \\\" LLRRRLLRRL \\\" ; int n = str . size ( ) ; cout << BalancedPartition ( str , n ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Position of rightmost set bit | C # Code for Position of rightmost set bit ; Driver method\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { public static int getFirstSetBitPos ( int n ) { return ( int ) ( ( Math . Log10 ( n & - n ) ) \\/ Math . Log10 ( 2 ) ) + 1 ; } public static void Main ( ) { int n = 12 ; Console . WriteLine ( getFirstSetBitPos ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Interquartile Range ( IQR ) | Function to give index of the median ; Function to calculate IQR ; Index of median of entire data ; Median of first half ; Median of second half ; IQR calculation ; Driver Function\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function median ( $ a , $ l , $ r ) { $ n = $ r - $ l + 1 ; $ n = ( int ) ( ( $ n + 1 ) \\/ 2 ) - 1 ; return $ n + $ l ; } function IQR ( $ a , $ n ) { sort ( $ a ) ; $ mid_index = median ( $ a , 0 , $ n ) ; $ Q1 = $ a [ median ( $ a , 0 , $ mid_index ) ] ; $ Q3 = $ a [ $ mid_index + median ( $ a , $ mid_index + 1 , $ n ) ] ; return ( $ Q3 - $ Q1 ) ; } $ a = array ( 1 , 19 , 7 , 6 , 5 , 9 , 12 , 27 , 18 , 2 , 15 ) ; $ n = count ( $ a ) ; echo IQR ( $ a , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Largest gap in an array | A C ++ program to find largest gap between two elements in an array . ; function to solve the given problem ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int solve ( int a [ ] , int n ) { int max1 = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( abs ( a [ i ] - a [ j ] ) > max1 ) { max1 = abs ( a [ i ] - a [ j ] ) ; } } } return max1 ; } int main ( ) { int arr [ ] = { -1 , 2 , 3 , -4 , -10 , 22 } ; int size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << \\\" Largest \u2581 gap \u2581 is \u2581 : \u2581 \\\" << solve ( arr , size ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Interprime | JAVA program to check if a number is interprime or not ; Function to check if a number is prime or not ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to check if the given number is interprime or not ; Smallest Interprime is 4 So the number less than 4 can not be a Interprime ; Calculate first prime number < n ; Calculate first prime number > n ; check if next_prime and prev_prime have the same average ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } static boolean isInterprime ( int n ) { if ( n < 4 ) return false ; int prev_prime = n ; int next_prime = n ; while ( ! isPrime ( prev_prime ) ) { prev_prime -- ; } while ( ! isPrime ( next_prime ) ) { next_prime ++ ; } if ( ( prev_prime + next_prime ) == 2 * n ) return true ; else return false ; } public static void main ( String [ ] args ) { int n = 9 ; if ( isInterprime ( n ) ) System . out . println ( \\\" YES \\\" ) ; else System . out . println ( \\\" NO \\\" ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Space and time efficient Binomial Coefficient | Program to calculate C ( n , k ) ; Returns value of Binomial Coefficient C ( n , k ) ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] \\/ [ k * ( k - 1 ) * -- -- * 1 ] ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint binomialCoeff ( int n , int k ) { int res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res \\/= ( i + 1 ) ; } return res ; } int main ( ) { int n = 8 , k = 2 ; printf ( \\\" Value \u2581 of \u2581 C ( % d , \u2581 % d ) \u2581 is \u2581 % d \u2581 \\\" , n , k , binomialCoeff ( n , k ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum steps to reduce N to 0 by given operations | Function to find the minimum number to steps to reduce N to 0 ; Dictionary for storing the precomputed sum ; Bases Cases ; Check if n is not in dp then only call the function so as to reduce no of recursive calls ; Return the answer ; Given Number N ; Function Call\\\"\\nSolution in Python:\",\"targets\":\"def count ( n ) :\\n\\tdp = dict ( )\\n\\tdp [ 0 ] = 0\\n\\tdp [ 1 ] = 1\\n\\tif n not in dp :\\n\\t\\tdp [ n ] = 1 + min ( n % 2 + count ( n \\/\\/ 2 ) , n % 3 + count ( n \\/\\/ 3 ) )\\n\\treturn dp [ n ]\\nN = 6\\nprint ( str ( count ( N ) ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Longest subarray with difference exactly K between any two distinct values | Java implementation to find the longest subarray consisting of only two values with difference K ; Function to return the length of the longest sub - array ; Initialize set ; Store 1 st element of sub - array into set ; Check absolute difference between two elements ; If the new element is not present in the set ; If the set contains two elements ; Otherwise ; Update the maximum length ; Remove the set elements ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static int longestSubarray ( int arr [ ] , int n , int k ) { int i , j , Max = 1 ; HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( i = 0 ; i < n - 1 ; i ++ ) { s . add ( arr [ i ] ) ; for ( j = i + 1 ; j < n ; j ++ ) { if ( Math . abs ( arr [ i ] - arr [ j ] ) == 0 || Math . abs ( arr [ i ] - arr [ j ] ) == k ) { if ( ! s . contains ( arr [ j ] ) ) { if ( s . size ( ) == 2 ) break ; else s . add ( arr [ j ] ) ; } } else break ; } if ( s . size ( ) == 2 ) { Max = Math . max ( Max , j - i ) ; s . clear ( ) ; } else s . clear ( ) ; } return Max ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 2 , 2 , 5 , 5 , 5 } ; int N = arr . length ; int K = 1 ; int length = longestSubarray ( arr , N , K ) ; if ( length == 1 ) System . out . print ( - 1 ) ; else System . out . print ( length ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Numbers having Unique ( or Distinct ) digits | Java code for the above approach ; Function to print unique numbers ; Iterate from l to r ; Convert the no . to String ; Convert String to set using stl ; Output if condition satisfies ; Driver Code ; Input of the lower and higher limits ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static void printUnique ( int l , int r ) { for ( int i = l ; i <= r ; i ++ ) { String s = String . valueOf ( i ) ; HashSet < Integer > uniDigits = new HashSet < Integer > ( ) ; for ( int c : s . toCharArray ( ) ) uniDigits . add ( c ) ; if ( s . length ( ) == uniDigits . size ( ) ) { System . out . print ( i + \\\" \u2581 \\\" ) ; } } } public static void main ( String [ ] args ) { int l = 1 , r = 20 ; printUnique ( l , r ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Probability of rain on N + 1 th day | Java code to find the probability of rain on n + 1 - th day when previous day 's data is given ; Function to find the probability ; count 1 ; find probability ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { static float rainDayProbability ( int a [ ] , int n ) { float count = 0 , m ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 1 ) count ++ ; } m = count \\/ n ; return m ; } public static void main ( String args [ ] ) { int a [ ] = { 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 } ; int n = a . length ; System . out . print ( rainDayProbability ( a , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find all strings that match specific pattern in a dictionary | C # program to print all the strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary ; Function to print all the strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary ; len is length of the pattern ; For each word in the dictionary ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static bool check ( string pattern , string word ) { if ( pattern . Length != word . Length ) return false ; int [ ] ch = new int [ 128 ] ; int Len = word . Length ; for ( int i = 0 ; i < Len ; i ++ ) { if ( ch [ ( int ) pattern [ i ] ] == 0 ) { ch [ ( int ) pattern [ i ] ] = word [ i ] ; } else if ( ch [ ( int ) pattern [ i ] ] != word [ i ] ) { return false ; } } return true ; } static void findMatchedWords ( HashSet < string > dict , string pattern ) { int Len = pattern . Length ; string result = \\\" \u2581 \\\" ; foreach ( string word in dict ) { if ( check ( pattern , word ) ) { result = word + \\\" \u2581 \\\" + result ; } } Console . Write ( result ) ; } static void Main ( ) { HashSet < string > dict = new HashSet < string > ( new string [ ] { \\\" abb \\\" , \\\" abc \\\" , \\\" xyz \\\" , \\\" xyy \\\" } ) ; string pattern = \\\" foo \\\" ; findMatchedWords ( dict , pattern ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimum increment operations to make the array in increasing order | function to find minimum moves required to make the array in increasing order ; to store answer ; iterate over an array ; non - increasing order ; add moves to answer ; increase the element ; return required answer ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function MinimumMoves ( & $ a , $ n , $ x ) { $ ans = 0 ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { if ( $ a [ $ i ] <= $ a [ $ i - 1 ] ) { $ p = ( $ a [ $ i - 1 ] - $ a [ $ i ] ) \\/ $ x + 1 ; $ ans += $ p ; $ a [ $ i ] += $ p * $ x ; } } return $ ans ; } $ arr = array ( 1 , 3 , 3 , 2 ) ; $ x = 2 ; $ n = sizeof ( $ arr ) ; echo ( ( int ) MinimumMoves ( $ arr , $ n , $ x ) ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Length of Longest Balanced Subsequence | C # program to find length of the longest balanced subsequence . ; Considering all balanced substrings of length 2 ; Considering all other substrings ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int maxLength ( String s , int n ) { int [ , ] dp = new int [ n , n ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( s [ i ] == ' ( ' && s [ i + 1 ] == ' ) ' ) dp [ i , i + 1 ] = 2 ; for ( int l = 2 ; l < n ; l ++ ) { for ( int i = 0 , j = l ; j < n ; i ++ , j ++ ) { if ( s [ i ] == ' ( ' && s [ j ] == ' ) ' ) dp [ i , j ] = 2 + dp [ i + 1 , j - 1 ] ; for ( int k = i ; k < j ; k ++ ) dp [ i , j ] = Math . Max ( dp [ i , j ] , dp [ i , k ] + dp [ k + 1 , j ] ) ; } } return dp [ 0 , n - 1 ] ; } public static void Main ( ) { string s = \\\" ( ) ( ( ( ( ( ( ) \\\" ; int n = s . Length ; Console . WriteLine ( maxLength ( s , n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"Add two numbers without using arithmetic operators |\\nHow can the above be solved in C?\",\"targets\":\"int Add ( int x , int y ) { if ( y == 0 ) return x ; else return Add ( x ^ y , ( x & y ) << 1 ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to build a DFA to accept strings that start and end with same character | Java Program for DFA that accepts string if it starts and ends with same character ; Function for the state Q1 ; Condition to check end of string ; State transitions ' a ' takes to q1 , and ' b ' takes to q2 ; Function for the state Q2 ; Condition to check end of string ; State transitions ' a ' takes to q1 , and ' b ' takes to q2 ; Function for the state Q3 ; Condition to check end of string ; State transitions ' a ' takes to q4 , and ' b ' takes to q3 ; Function for the state Q4 ; Condition to check end of string ; State transitions ' a ' takes to q4 , and ' b ' takes to q3 ; Function for the state Q0 ; Condition to check end of string ; State transitions ' a ' takes to q1 , and ' b ' takes to q3 ; Driver Code ; Since q0 is the starting state Send the string to q0\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static void q1 ( String s , int i ) { if ( i == s . length ( ) ) { System . out . println ( \\\" Yes \\\" ) ; return ; } if ( s . charAt ( i ) == ' a ' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } static void q2 ( String s , int i ) { if ( i == s . length ( ) ) { System . out . println ( \\\" No \\\" ) ; return ; } if ( s . charAt ( i ) == ' a ' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } static void q3 ( String s , int i ) { if ( i == s . length ( ) ) { System . out . println ( \\\" Yes \\\" ) ; return ; } if ( s . charAt ( i ) == ' a ' ) q4 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } static void q4 ( String s , int i ) { if ( i == s . length ( ) ) { System . out . println ( \\\" No \\\" ) ; return ; } if ( s . charAt ( i ) == ' a ' ) q4 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } static void q0 ( String s , int i ) { if ( i == s . length ( ) ) { System . out . println ( \\\" No \\\" ) ; return ; } if ( s . charAt ( i ) == ' a ' ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } public static void main ( String [ ] args ) { String s = \\\" abbaabb \\\" ; q0 ( s , 0 ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Total area of two overlapping rectangles | Java program to find total area of two overlapping Rectangles ; Returns Total Area of two overlap rectangles ; Area of 1 st Rectangle ; Area of 2 nd Rectangle ; Length of intersecting part i . e start from max ( l1 . x , l2 . x ) of x - coordinate and end at min ( r1 . x , r2 . x ) x - coordinate by subtracting start from end we get required lengths ; Driver Code ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static class Point { int x , y ; public Point ( int x , int y ) { this . x = x ; this . y = y ; } } ; static int overlappingArea ( Point l1 , Point r1 , Point l2 , Point r2 ) { int area1 = Math . abs ( l1 . x - r1 . x ) * Math . abs ( l1 . y - r1 . y ) ; int area2 = Math . abs ( l2 . x - r2 . x ) * Math . abs ( l2 . y - r2 . y ) ; int x_dist = ( Math . min ( r1 . x , r2 . x ) - Math . max ( l1 . x , l2 . x ) ; int y_dist = ( Math . min ( r1 . y , r2 . y ) - Math . max ( l1 . y , l2 . y ) ; int areaI = 0 ; if ( x_dist > 0 && y_dist > 0 ) { areaI = x_dist * y_dist ; } return ( area1 + area2 - areaI ) ; } public static void main ( String [ ] args ) { Point l1 = new Point ( 2 , 2 ) , r1 = new Point ( 5 , 7 ) ; Point l2 = new Point ( 3 , 4 ) , r2 = new Point ( 6 , 9 ) ; System . out . println ( overlappingArea ( l1 , r1 , l2 , r2 ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Distinct powers of a number N such that the sum is equal to K | Python 3 implementation to find distinct powers of N that add up to K ; Function to return the highest power of N not exceeding K ; Loop to find the highest power less than K ; Initializing the PowerArray with all 0 's. ; Function to print the distinct powers of N that add upto K ; Getting the highest power of n before k ; To check if the power is being used twice or not ; Print - 1 if power is being used twice ; If the power is not visited , then mark the power as visited ; Decrementing the value of K ; Printing the powers of N that sum up to K ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"from math import pow\\ndef highestPower ( n , k ) :\\n\\ti = 0\\n\\ta = pow ( n , i )\\n\\twhile ( a <= k ) :\\n\\t\\ti += 1\\n\\t\\ta = pow ( n , i )\\n\\treturn i - 1\\nb = [ 0 for i in range ( 50 ) ]\\ndef PowerArray ( n , k ) :\\n\\twhile ( k ) :\\n\\t\\tt = highestPower ( n , k )\\n\\t\\tif ( b [ t ] ) :\\n\\t\\t\\tprint ( - 1 )\\n\\t\\t\\treturn 0\\n\\t\\telse :\\n\\t\\t\\tb [ t ] = 1\\n\\t\\tk -= pow ( n , t )\\n\\tfor i in range ( 50 ) :\\n\\t\\tif ( b [ i ] ) :\\n\\t\\t\\tprint ( i , end = ' , \u2581 ' )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 3\\n\\tK = 40\\n\\tPowerArray ( N , K )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimum sum of product of two arrays | Java program to find minimum sum of product of two arrays with k operations allowed on first array . ; Function to find the minimum product ; Find product of current elements and update result . ; If both product and b [ i ] are negative , we must increase value of a [ i ] to minimize result . ; If both product and a [ i ] are negative , we must decrease value of a [ i ] to minimize result . ; Similar to above two cases for positive product . ; Check if current difference becomes higher than the maximum difference so far . ; Driver function\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . math . * ; class GFG { static int minproduct ( int a [ ] , int b [ ] , int n , int k ) { int diff = 0 , res = 0 ; int temp = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int pro = a [ i ] * b [ i ] ; res = res + pro ; if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ; else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ; else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ; else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ; int d = Math . abs ( pro - temp ) ; if ( d > diff ) diff = d ; } return res - diff ; } public static void main ( String [ ] args ) { int a [ ] = { 2 , 3 , 4 , 5 , 4 } ; int b [ ] = { 3 , 4 , 2 , 3 , 2 } ; int n = 5 , k = 3 ; System . out . println ( minproduct ( a , b , n , k ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Extract ' k ' bits from a given position in a number . | Java program to extract k bits from a given position . ; Function to extract k bits from p position and returns the extracted value as integer ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int bitExtracted ( int number , int k , int p ) { return ( ( ( 1 << k ) - 1 ) & ( number >> ( p - 1 ) ) ) ; } public static void main ( String [ ] args ) { int number = 171 , k = 5 , p = 2 ; System . out . println ( \\\" The \u2581 extracted \u2581 number \u2581 is \u2581 \\\" + bitExtracted ( number , k , p ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find the final sequence of the array after performing given operations | C ++ implementation of the approach ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int * solve ( int arr [ ] , int n ) { static int b [ 4 ] ; int p = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { b [ p ] = arr [ i -- ] ; if ( i >= 0 ) b [ n - 1 - p ] = arr [ i ] ; p ++ ; } return b ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int * b ; b = solve ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) cout << b [ i ] << \\\" \u2581 \\\" ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Majority Element | C # program to demonstrate insert operation in binary search tree . ; A utility function to create a new BST node ; A utility function to insert a new node with given key in BST ; If the tree is empty , return a new node ; Otherwise , recur down the tree ; Find the max count ; Return the ( unchanged ) node pointer ; A utility function to do inorder traversal of BST ; Driver Code ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; public class Node { public int key ; public int c = 0 ; public Node left , right ; } class GFG { static int ma = 0 ; static Node newNode ( int item ) { Node temp = new Node ( ) ; temp . key = item ; temp . c = 1 ; temp . left = temp . right = null ; return temp ; } static Node insert ( Node node , int key ) { if ( node == null ) { if ( ma == 0 ) ma = 1 ; return newNode ( key ) ; } if ( key < node . key ) node . left = insert ( node . left , key ) ; else if ( key > node . key ) node . right = insert ( node . right , key ) ; else node . c ++ ; ma = Math . Max ( ma , node . c ) ; return node ; } static void inorder ( Node root , int s ) { if ( root != null ) { inorder ( root . left , s ) ; if ( root . c > ( s \\/ 2 ) ) Console . WriteLine ( root . key + \\\" \\n \\\" ) ; inorder ( root . right , s ) ; } } static public void Main ( ) { int [ ] a = { 1 , 3 , 3 , 3 , 2 } ; int size = a . Length ; Node root = null ; for ( int i = 0 ; i < size ; i ++ ) { root = insert ( root , a [ i ] ) ; } if ( ma > ( size \\/ 2 ) ) inorder ( root , size ) ; else Console . WriteLine ( \\\" No \u2581 majority \u2581 element \\n \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Program to print ' N ' alphabet using the number pattern from 1 to n | Function to print the desired Alphabet N Pattern ; Declaring the values of Right , Left and Diagonal values ; Main Loop for the rows ; For the left Values ; Spaces for the diagonals ; Condition for the diagonals ; Spaces for the Right Values ; For the right values ; Size of the Pattern ; Calling the function to print the desired Pattern\\\"\\nSolution in php:\",\"targets\":\"< ? php function Alphabet_N_Pattern ( $ N ) { $ index ; $ side_index ; $ size ; $ Right = 1 ; $ Left = 1 ; $ Diagonal = 2 ; for ( $ index = 0 ; $ index < $ N ; $ index ++ ) { echo $ Left ++ ; for ( $ side_index = 0 ; $ side_index < 2 * ( $ index ) ; $ side_index ++ ) echo \\\" \u2581 \\\" ; if ( $ index != 0 && $ index != $ N - 1 ) echo $ Diagonal ++ ; else echo \\\" \u2581 \\\" ; for ( $ side_index = 0 ; $ side_index < 2 * ( $ N - $ index - 1 ) ; $ side_index ++ ) echo \\\" \u2581 \\\" ; echo $ Right ++ ; echo \\\" \\n \\\" ; } } $ Size = 6 ; Alphabet_N_Pattern ( $ Size ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Matrix Chain Multiplication | DP | See the Cormen book for details of the following algorithm ; Matrix Ai has dimension p [ i - 1 ] x p [ i ] for i = 1. . n ; For simplicity of the program , one extra row and one extra column are allocated in m [ ] [ ] . 0 th row and 0 th column of m [ ] [ ] are not used ; cost is zero when multiplying one matrix . ; L is chain length . ; q = cost \\/ scalar multiplications ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nint MatrixChainOrder ( int p [ ] , int n ) { int m [ n ] [ n ] ; int i , j , k , L , q ; for ( i = 1 ; i < n ; i ++ ) m [ i ] [ i ] = 0 ; for ( L = 2 ; L < n ; L ++ ) { for ( i = 1 ; i < n - L + 1 ; i ++ ) { j = i + L - 1 ; m [ i ] [ j ] = INT_MAX ; for ( k = i ; k <= j - 1 ; k ++ ) { q = m [ i ] [ k ] + m [ k + 1 ] [ j ] + p [ i - 1 ] * p [ k ] * p [ j ] ; if ( q < m [ i ] [ j ] ) m [ i ] [ j ] = q ; } } } return m [ 1 ] [ n - 1 ] ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Minimum \u2581 number \u2581 of \u2581 multiplications \u2581 is \u2581 % d \u2581 \\\" , MatrixChainOrder ( arr , size ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Pairs of complete strings in two sets of strings | Java implementation for find pairs of complete strings . ; Returns count of complete pairs from set [ 0. . n - 1 ] and set2 [ 0. . m - 1 ] ; Consider all pairs of both strings ; Create a concatenation of current pair ; Compute frequencies of all characters in the concatenated String . ; If frequency of any character is not greater than 0 , then this pair is not complete . ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int countCompletePairs ( String set1 [ ] , String set2 [ ] , int n , int m ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { String concat = set1 [ i ] + set2 [ j ] ; int frequency [ ] = new int [ 26 ] ; for ( int k = 0 ; k < concat . length ( ) ; k ++ ) { frequency [ concat . charAt ( k ) - ' a ' ] ++ ; } int k ; for ( k = 0 ; k < 26 ; k ++ ) { if ( frequency [ k ] < 1 ) { break ; } } if ( k == 26 ) { result ++ ; } } } return result ; } static public void main ( String [ ] args ) { String set1 [ ] = { \\\" abcdefgh \\\" , \\\" geeksforgeeks \\\" , \\\" lmnopqrst \\\" , \\\" abc \\\" } ; String set2 [ ] = { \\\" ijklmnopqrstuvwxyz \\\" , \\\" abcdefghijklmnopqrstuvwxyz \\\" , \\\" defghijklmnopqrstuvwxyz \\\" } ; int n = set1 . length ; int m = set2 . length ; System . out . println ( countCompletePairs ( set1 , set2 , n , m ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Number of N digit integers with weight W | Function to find total possible numbers with n digits and weight w ; When Weight of an integer is Positive ; Subtract the weight from 9 ; When weight of an integer is negative ; add the weight to 10 to make it positive ; Driver code ; number of digits in an integer and w as weight ; print the total possible numbers with n digits and weight w\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function findNumbers ( n , w ) { let x = 0 , sum = 0 ; if ( w >= 0 && w <= 8 ) { x = 9 - w ; } else if ( w >= - 9 && w <= - 1 ) { x = 10 + w ; } sum = Math . pow ( 10 , n - 2 ) ; sum = ( x * sum ) ; return sum ; } let n , w ; n = 3 ; w = 4 ; document . write ( findNumbers ( n , w ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if a sequence of path visits any coordinate twice or not | Function to check if the man crosses previous visited coordinate or not ; Stores the count of crossed vertex ; Stores ( x , y ) coordinates ; The coordinates for the origin ; Iterate over the string ; Condition to increment X or Y co - ordinates respectively ; Check if ( x , y ) is already visited ; Print the result ; Given string ; Function call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def isCrossed ( path ) :\\n\\tif ( len ( path ) == 0 ) :\\n\\t\\treturn bool ( False )\\n\\tans = bool ( False )\\n\\tSet = set ( )\\n\\tx , y = 0 , 0\\n\\tSet . add ( ( x , y ) )\\n\\tfor i in range ( len ( path ) ) :\\n\\t\\tif ( path [ i ] == ' N ' ) :\\n\\t\\t\\tSet . add ( ( x , y ) )\\n\\t\\t\\ty = y + 1\\n\\t\\tif ( path [ i ] == ' S ' ) :\\n\\t\\t\\tSet . add ( ( x , y ) )\\n\\t\\t\\ty = y - 1\\n\\t\\tif ( path [ i ] == ' E ' ) :\\n\\t\\t\\tSet . add ( ( x , y ) )\\n\\t\\t\\tx = x + 1\\n\\t\\tif ( path [ i ] == ' W ' ) :\\n\\t\\t\\tSet . add ( ( x , y ) )\\n\\t\\t\\tx = x - 1\\n\\t\\tif ( x , y ) in Set :\\n\\t\\t\\tans = bool ( True )\\n\\t\\t\\tbreak\\n\\tif ( ans ) :\\n\\t\\tprint ( \\\" Crossed \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" Not \u2581 Crossed \\\" )\\npath = \\\" NESW \\\"\\nisCrossed ( path )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Average of even numbers till a given even number | Function to calculate the average of even numbers ; count even numbers ; store the sum of even numbers ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function averageEven ( $ n ) { if ( $ n % 2 != 0 ) { echo ( \\\" Invalid \u2581 Input \\\" ) ; return -1 ; } $ sum = 0 ; $ count = 0 ; while ( $ n >= 2 ) { $ count ++ ; $ sum += $ n ; $ n = $ n - 2 ; } return $ sum \\/ $ count ; } $ n = 16 ; echo ( averageEven ( $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Sum of Fibonacci Numbers with alternate negatives | Java Program to find alternate sum of Fibonacci numbers ; Computes value of first fibonacci numbers and stores their alternate sum ; Initialize result ; Add remaining terms ; For even terms ; For odd terms ; Return the alternating sum ; Driver code ; Get n ; Find the alternating sum\\\"\\nHow can the above be solved in Java?\",\"targets\":\"public class GFG { static double calculateAlternateSum ( int n ) { if ( n <= 0 ) return 0 ; int fibo [ ] = new int [ n + 1 ] ; fibo [ 0 ] = 0 ; fibo [ 1 ] = 1 ; double sum = Math . pow ( fibo [ 0 ] , 2 ) + Math . pow ( fibo [ 1 ] , 2 ) ; for ( int i = 2 ; i <= n ; i ++ ) { fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ; if ( i % 2 == 0 ) sum -= fibo [ i ] ; else sum += fibo [ i ] ; } return sum ; } public static void main ( String args [ ] ) { int n = 8 ; System . out . println ( \\\" Alternating \u2581 Fibonacci \u2581 Sum \u2581 upto \u2581 \\\" + n + \\\" \u2581 terms : \u2581 \\\" + calculateAlternateSum ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if a circle lies inside another circle or not | Java program to check if one circle lies inside another circle or not . ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static void circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) { int distSq = ( int ) Math . sqrt ( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) ) ; if ( distSq + r2 == r1 ) { System . out . println ( \\\" The \u2581 smaller \u2581 circle \u2581 lies \u2581 completely \\\" + \\\" \u2581 inside \u2581 the \u2581 bigger \u2581 circle \u2581 with \u2581 \\\" + \\\" touching \u2581 each \u2581 other \u2581 \\\" + \\\" at \u2581 a \u2581 point \u2581 of \u2581 circumference . \u2581 \\\" ) ; } else if ( distSq + r2 < r1 ) { System . out . println ( \\\" The \u2581 smaller \u2581 circle \u2581 lies \u2581 completely \\\" + \\\" \u2581 inside \u2581 the \u2581 bigger \u2581 circle \u2581 without \\\" + \\\" \u2581 touching \u2581 each \u2581 other \u2581 \\\" + \\\" at \u2581 a \u2581 point \u2581 of \u2581 circumference . \\\" ) ; } else { System . out . println ( \\\" The \u2581 smaller \u2581 does \u2581 not \u2581 lies \u2581 inside \\\" + \\\" \u2581 the \u2581 bigger \u2581 circle \u2581 completely . \\\" ) ; } } public static void main ( String [ ] args ) { int x1 = 10 , y1 = 8 ; int x2 = 1 , y2 = 2 ; int r1 = 30 , r2 = 10 ; circle ( x1 , y1 , x2 , y2 , r1 , r2 ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Dynamic Programming | A recursive solution for subset sum problem ; Returns true if there is a subset of set [ ] with sum equal to given sum ; Base Cases ; If last element is greater than sum , then ignore it ; else , check if sum can be obtained by any of the following : ( a ) including the last element ( b ) excluding the last element ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool isSubsetSum ( int set [ ] , int n , int sum ) { if ( sum == 0 ) return true ; if ( n == 0 ) return false ; if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ; return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ; } int main ( ) { int set [ ] = { 3 , 34 , 4 , 12 , 5 , 2 } ; int sum = 9 ; int n = sizeof ( set ) \\/ sizeof ( set [ 0 ] ) ; if ( isSubsetSum ( set , n , sum ) == true ) cout << \\\" Found \u2581 a \u2581 subset \u2581 with \u2581 given \u2581 sum \\\" ; else cout << \\\" No \u2581 subset \u2581 with \u2581 given \u2581 sum \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count pairs from two arrays with difference exceeding K | Function to count pairs that satisfy the given conditions ; Stores index of the left pointer . ; Stores index of the right pointer ; Stores count of total pairs that satisfy the conditions ; Sort arr [ ] array ; Sort brr [ ] array ; Traverse both the array and count then pairs ; If the value of ( brr [ j ] - arr [ i ] ) exceeds K ; Update cntPairs ; Update ; Update j ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def count_pairs ( arr , brr , N , M , K ) :\\n\\ti = 0\\n\\tj = 0\\n\\tcntPairs = 0\\n\\tarr = sorted ( arr )\\n\\tbrr = sorted ( brr )\\n\\twhile ( i < N and j < M ) :\\n\\t\\tif ( brr [ j ] - arr [ i ] > K ) :\\n\\t\\t\\tcntPairs += ( M - j )\\n\\t\\t\\ti += 1\\n\\t\\telse :\\n\\t\\t\\tj += 1\\n\\treturn cntPairs\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 5 , 9 , 1 , 8 ]\\n\\tbrr = [ 10 , 12 , 7 , 4 , 2 , 3 ]\\n\\tK = 3\\n\\tN = len ( arr )\\n\\tM = len ( brr )\\n\\tprint ( count_pairs ( arr , brr , N , M , K ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find the maximum sum leaf to root path in a Binary Tree | C program to find maximum sum leaf to root path in Binary Tree ; A tree node structure ; A utility function that prints all nodes on the path from root to target_leaf ; base case ; return true if this node is the target_leaf or target leaf is present in one of its descendants ; This function Sets the target_leaf_ref to refer the leaf node of the maximum path sum . Also , returns the max_sum using max_sum_ref ; Update current sum to hold sum of nodes on path from root to this node ; If this is a leaf node and path to this node has maximum sum so far , then make this node target_leaf ; If this is not a leaf node , then recur down to find the target_leaf ; Returns the maximum sum and prints the nodes on max sum path ; base case ; find the target leaf and maximum sum ; print the path from root to the target leaf ; return maximum sum ; Utility function to create a new Binary Tree node ; Driver function to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\n#include \\n#include \\nstruct node { int data ; struct node * left ; struct node * right ; } ; bool printPath ( struct node * root , struct node * target_leaf ) { if ( root == NULL ) return false ; if ( root == target_leaf || printPath ( root -> left , target_leaf ) || printPath ( root -> right , target_leaf ) ) { printf ( \\\" % d \u2581 \\\" , root -> data ) ; return true ; } return false ; } void getTargetLeaf ( struct node * node , int * max_sum_ref , int curr_sum , struct node * * target_leaf_ref ) { if ( node == NULL ) return ; curr_sum = curr_sum + node -> data ; if ( node -> left == NULL && node -> right == NULL ) { if ( curr_sum > * max_sum_ref ) { * max_sum_ref = curr_sum ; * target_leaf_ref = node ; } } getTargetLeaf ( node -> left , max_sum_ref , curr_sum , target_leaf_ref ) ; getTargetLeaf ( node -> right , max_sum_ref , curr_sum , target_leaf_ref ) ; } int maxSumPath ( struct node * node ) { if ( node == NULL ) return 0 ; struct node * target_leaf ; int max_sum = INT_MIN ; getTargetLeaf ( node , & max_sum , 0 , & target_leaf ) ; printPath ( node , target_leaf ) ; return max_sum ; } struct node * newNode ( int data ) { struct node * temp = ( struct node * ) malloc ( sizeof ( struct node ) ) ; temp -> data = data ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } int main ( ) { struct node * root = NULL ; root = newNode ( 10 ) ; root -> left = newNode ( -2 ) ; root -> right = newNode ( 7 ) ; root -> left -> left = newNode ( 8 ) ; root -> left -> right = newNode ( -4 ) ; printf ( \\\" Following \u2581 are \u2581 the \u2581 nodes \u2581 on \u2581 the \u2581 maximum \u2581 \\\" \\\" sum \u2581 path \u2581 \\n \\\" ) ; int sum = maxSumPath ( root ) ; printf ( \\\" Sum of the nodes is % d \\\" , sum ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Function to check if a singly linked list is palindrome | Program to check if a linked list is palindrome ; Link list node ; Function to check if given linked list is palindrome or not ; To handle odd size list ; initialize result ; Get the middle of the list . Move slow_ptr by 1 and fast_ptrr by 2 , slow_ptr will have the middle node ; We need previous of the slow_ptr for linked lists with odd elements ; fast_ptr would become NULL when there are even elements in list . And not NULL for odd elements . We need to skip the middle node for odd case and store it somewhere so that we can restore the original list ; Now reverse the second half and compare it with first half ; NULL terminate first half ; Reverse the second half ; compare ; Reverse the second half again ; If there was a mid node ( odd size case ) which was not part of either first half or second half . ; Function to reverse the linked list Note that this function may change the head ; Function to check if two input lists have same data ; Both are empty reurn 1 ; Will reach here when one is NULL and other is not ; Push a node to linked list . Note that this function changes the head ; allocate node ; link the old list off the new node ; move the head to pochar to the new node ; A utility function to print a given linked list ; Drier program to test above function ; Start with the empty list\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\n#include \\nstruct Node { char data ; struct Node * next ; } ; void reverse ( struct Node * * ) ; bool compareLists ( struct Node * , struct Node * ) ; bool isPalindrome ( struct Node * head ) { struct Node * slow_ptr = head , * fast_ptr = head ; struct Node * second_half , * prev_of_slow_ptr = head ; struct Node * midnode = NULL ; bool res = true ; if ( head != NULL && head -> next != NULL ) { while ( fast_ptr != NULL && fast_ptr -> next != NULL ) { fast_ptr = fast_ptr -> next -> next ; prev_of_slow_ptr = slow_ptr ; slow_ptr = slow_ptr -> next ; } if ( fast_ptr != NULL ) { midnode = slow_ptr ; slow_ptr = slow_ptr -> next ; } second_half = slow_ptr ; prev_of_slow_ptr -> next = NULL ; reverse ( & second_half ) ; res = compareLists ( head , second_half ) ; reverse ( & second_half ) ; if ( midnode != NULL ) { prev_of_slow_ptr -> next = midnode ; midnode -> next = second_half ; } else prev_of_slow_ptr -> next = second_half ; } return res ; } void reverse ( struct Node * * head_ref ) { struct Node * prev = NULL ; struct Node * current = * head_ref ; struct Node * next ; while ( current != NULL ) { next = current -> next ; current -> next = prev ; prev = current ; current = next ; } * head_ref = prev ; } bool compareLists ( struct Node * head1 , struct Node * head2 ) { struct Node * temp1 = head1 ; struct Node * temp2 = head2 ; while ( temp1 && temp2 ) { if ( temp1 -> data == temp2 -> data ) { temp1 = temp1 -> next ; temp2 = temp2 -> next ; } else return 0 ; } if ( temp1 == NULL && temp2 == NULL ) return 1 ; return 0 ; } void push ( struct Node * * head_ref , char new_data ) { struct Node * new_node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; new_node -> data = new_data ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } void printList ( struct Node * ptr ) { while ( ptr != NULL ) { printf ( \\\" % c - > \\\" , ptr -> data ) ; ptr = ptr -> next ; } printf ( \\\" NULL \\n \\\" ) ; } int main ( ) { struct Node * head = NULL ; char str [ ] = \\\" abacaba \\\" ;...\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of subsequences in a string divisible by n | C ++ program to count subsequences of a string divisible by n . ; Returns count of subsequences of str divisible by n . ; division by n can leave only n remainder [ 0. . n - 1 ] . dp [ i ] [ j ] indicates number of subsequences in string [ 0. . i ] which leaves remainder j after division by n . ; Filling value for first digit in str ; start a new subsequence with index i ; exclude i 'th character from all the current subsequences of string [0...i-1] ; include i 'th character in all the current subsequences of string [0...i-1] ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int countDivisibleSubseq ( string str , int n ) { int len = str . length ( ) ; int dp [ len ] [ n ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ 0 ] [ ( str [ 0 ] - '0' ) % n ] ++ ; for ( int i = 1 ; i < len ; i ++ ) { dp [ i ] [ ( str [ i ] - '0' ) % n ] ++ ; for ( int j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ; dp [ i ] [ ( j * 10 + ( str [ i ] - '0' ) ) % n ] += dp [ i - 1 ] [ j ] ; } } return dp [ len - 1 ] [ 0 ] ; } int main ( ) { string str = \\\"1234\\\" ; int n = 4 ; cout << countDivisibleSubseq ( str , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find the number of cells in the table contains X | CPP program to find number of cells in the table contains X ; Function to find number of cells in the table contains X ; Driver code ; Function call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int Cells ( int n , int x ) { int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) if ( x % i == 0 && x \\/ i <= n ) ans ++ ; return ans ; } int main ( ) { int n = 6 , x = 12 ; cout << Cells ( n , x ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Construct a Perfect Binary Tree from Preorder Traversal | Java program for the above approach ; Structure of the tree ; Function to create a new node with the value val ; Return the newly created node ; Function to create the Perfect Binary Tree ; If preStart > preEnd return NULL ; Initialize root as pre [ preStart ] ; If the only node is left , then return node ; Parameters for further recursion ; Recursive Call to build the subtree of root node ; Return the created root ; Function to build Perfect Binary Tree ; Function to print the Inorder of the given Tree ; Base Case ; Left Recursive Call ; Print the data ; Right Recursive Call ; Driver Code ; Function Call ; Print Inorder Traversal\\\"\\nHow can the above be solved in Java?\",\"targets\":\"public class Main { static class Node { public int data ; public Node left , right ; public Node ( int val ) { data = val ; left = right = null ; } } static Node getNewNode ( int val ) { Node newNode = new Node ( val ) ; return newNode ; } static Node buildPerfectBT_helper ( int preStart , int preEnd , int [ ] pre ) { if ( preStart > preEnd ) return null ; Node root = getNewNode ( pre [ preStart ] ) ; if ( preStart == preEnd ) return root ; int leftPreStart = preStart + 1 ; int rightPreStart = leftPreStart + ( preEnd - leftPreStart + 1 ) \\/ 2 ; int leftPreEnd = rightPreStart - 1 ; int rightPreEnd = preEnd ; root . left = buildPerfectBT_helper ( leftPreStart , leftPreEnd , pre ) ; root . right = buildPerfectBT_helper ( rightPreStart , rightPreEnd , pre ) ; return root ; } static Node buildPerfectBT ( int [ ] pre , int size ) { return buildPerfectBT_helper ( 0 , size - 1 , pre ) ; } static void printInorder ( Node root ) { if ( root == null ) return ; printInorder ( root . left ) ; System . out . print ( root . data + \\\" \u2581 \\\" ) ; printInorder ( root . right ) ; } public static void main ( String [ ] args ) { int [ ] pre = { 1 , 2 , 4 , 5 , 3 , 6 , 7 } ; int N = pre . length ; Node root = buildPerfectBT ( pre , N ) ; System . out . print ( \\\" Inorder \u2581 traversal \u2581 of \u2581 the \u2581 tree : \u2581 \\\" ) ; printInorder ( root ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"How to print maximum number of A 's using given four keys | A recursive C program to print maximum number of A 's using following four keys ; A recursive function that returns the optimal length string for N keystrokes ; The optimal string length is N when N is smaller than 7 ; Initialize result ; TRY ALL POSSIBLE BREAK - POINTS For any keystroke N , we need to loop from N - 3 keystrokes back to 1 keystroke to find a breakpoint ' b ' after which we will have Ctrl - A , Ctrl - C and then only Ctrl - V all the way . ; If the breakpoint is s at b 'th keystroke then the optimal string would have length (n-b-1)*screen[b-1]; ; Driver program ; for the rest of the array we will rely on the previous entries to compute new ones\\\"\\nSolution in C:\",\"targets\":\"#include \\nint findoptimal ( int N ) { if ( N <= 6 ) return N ; int max = 0 ; int b ; for ( b = N - 3 ; b >= 1 ; b -- ) { int curr = ( N - b - 1 ) * findoptimal ( b ) ; if ( curr > max ) max = curr ; } return max ; } int main ( ) { int N ; for ( N = 1 ; N <= 20 ; N ++ ) printf ( \\\" Maximum \u2581 Number \u2581 of \u2581 A ' s \u2581 with \u2581 % d \u2581 keystrokes \u2581 is \u2581 % d \\n \\\" , N , findoptimal ( N ) ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to calculate value of nCr | PHP program To calculate the Value Of nCr ; Returns factorial of n ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function nCr ( $ n , $ r ) { return fact ( $ n ) \\/ ( fact ( $ r ) * fact ( $ n - $ r ) ) ; } function fact ( $ n ) { $ res = 1 ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) $ res = $ res * $ i ; return $ res ; } $ n = 5 ; $ r = 3 ; echo nCr ( $ n , $ r ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Smallest perfect Cube divisible by all elements of an array | Function to return the gcd of two numbers ; Function to return the lcm of all the elements of the array ; To calculate lcm of two numbers multiply them and divide the result by gcd of both the numbers ; Return the LCM of the array elements ; Function to return the smallest perfect cube divisible by all the elements of arr [ ] ; LCM of all the elements of arr [ ] ; If 2 divides lcm cnt number of times ; Check all the numbers that divide lcm ; Return the answer ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def gcd ( a , b ) :\\n\\tif ( b == 0 ) :\\n\\t\\treturn a\\n\\telse :\\n\\t\\treturn gcd ( b , a % b )\\ndef lcmOfArray ( arr , n ) :\\n\\tif ( n < 1 ) :\\n\\t\\treturn 0\\n\\tlcm = arr [ 0 ]\\n\\tfor i in range ( n ) :\\n\\t\\tlcm = ( lcm * arr [ i ] ) \\/\\/ gcd ( lcm , arr [ i ] ) ;\\n\\treturn lcm\\ndef minPerfectCube ( arr , n ) :\\n\\tlcm = lcmOfArray ( arr , n )\\n\\tminPerfectCube = lcm\\n\\tcnt = 0\\n\\twhile ( lcm > 1 and lcm % 2 == 0 ) :\\n\\t\\tcnt += 1\\n\\t\\tlcm \\/\\/= 2\\n\\tif ( cnt % 3 == 2 ) :\\n\\t\\tminPerfectCube *= 2\\n\\telif ( cnt % 3 == 1 ) :\\n\\t\\tminPerfectCube *= 4\\n\\ti = 3\\n\\twhile ( lcm > 1 ) :\\n\\t\\tcnt = 0\\n\\t\\twhile ( lcm % i == 0 ) :\\n\\t\\t\\tcnt += 1\\n\\t\\t\\tlcm \\/\\/= i\\n\\t\\tif ( cnt % 3 == 1 ) :\\n\\t\\t\\tminPerfectCube *= i * i\\n\\t\\telif ( cnt % 3 == 2 ) :\\n\\t\\t\\tminPerfectCube *= i\\n\\t\\ti += 2\\n\\treturn minPerfectCube\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ 10 , 125 , 14 , 42 , 100 ]\\n\\tn = len ( arr )\\n\\tprint ( minPerfectCube ( arr , n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Nth Square free number | Function to find nth square free number ; To maintain count of square free number ; Loop for square free numbers ; Checking whether square of a number is divisible by any number which is a perfect square ; If number is square free ; If the cnt becomes n , return the number ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function squareFree ( $ n ) { $ cnt = 0 ; for ( $ i = 1 ; ; $ i ++ ) { $ isSqFree = true ; for ( $ j = 2 ; $ j * $ j <= $ i ; $ j ++ ) { if ( $ i % ( $ j * $ j ) == 0 ) { $ isSqFree = false ; break ; } } if ( $ isSqFree == true ) { $ cnt ++ ; if ( $ cnt == $ n ) return $ i ; } } return 0 ; } $ n = 10 ; echo ( squareFree ( $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to select N pairs of candies of distinct colors ( Dynamic Programming + Bitmasking ) | Java program to implement the above approach ; Function to count ways to select N distinct pairs of candies with different colours ; If n pairs are selected ; Stores count of ways to select the i - th pair ; Iterate over the range [ 0 , n ] ; If pair ( i , j ) is not included ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int numOfWays ( int a [ ] [ ] , int n , int i , HashSet < Integer > blue ) { if ( i == n ) return 1 ; int count = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( a [ i ] [ j ] == 1 && ! blue . contains ( j ) ) { blue . add ( j ) ; count += numOfWays ( a , n , i + 1 , blue ) ; blue . remove ( j ) ; } } return count ; } public static void main ( String [ ] args ) { int n = 3 ; int mat [ ] [ ] = { { 0 , 1 , 1 } , { 1 , 0 , 1 } , { 1 , 1 , 1 } } ; HashSet < Integer > mpp = new HashSet < > ( ) ; System . out . println ( ( numOfWays ( mat , n , 0 , mpp ) ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum cost to convert M to N by repeated addition of its even divisors | Python3 program for the above approach ; Function to find the value of minimum steps to convert m to n ; Base Case ; If n exceeds m ; Iterate through all possible even divisors of m ; If m is divisible by i , then find the minimum cost ; Add the cost to convert m to m + i and recursively call next state ; Return min_cost ; Driver Code ; Function call ; If conversion is not possible ; Print the cost\\\"\\nHow can the above be solved in Python?\",\"targets\":\"inf = 1000000008\\ndef minSteps ( m , n ) :\\n\\tif ( n == m ) :\\n\\t\\treturn 0\\n\\tif ( m > n ) :\\n\\t\\treturn inf\\n\\tmin_cost = inf\\n\\tfor i in range ( 2 , m , 2 ) :\\n\\t\\tif ( m % i == 0 ) :\\n\\t\\t\\tmin_cost = min ( min_cost , m \\/ i + minSteps ( m + i , n ) )\\n\\treturn min_cost\\nif __name__ == ' _ _ main _ _ ' :\\n\\tM = 6\\n\\tN = 24\\n\\tminimum_cost = minSteps ( M , N )\\n\\tif minimum_cost == inf :\\n\\t\\tminimum_cost = - 1\\n\\tprint ( minimum_cost )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of operations to move all uppercase characters before all lower case characters | Function to return the minimum number of operations required ; To store the indices of the last uppercase and the first lowercase character ; Find the last uppercase character ; Find the first lowercase character ; If all the characters are either uppercase or lowercase ; Count of uppercase characters that appear after the first lowercase character ; Count of lowercase characters that appear before the last uppercase character ; Return the minimum operations required ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function minOperations ( $ str , $ n ) { $ i ; $ lastUpper = -1 ; $ firstLower = -1 ; for ( $ i = $ n - 1 ; $ i >= 0 ; $ i -- ) { if ( ctype_upper ( $ str [ $ i ] ) ) { $ lastUpper = $ i ; break ; } } for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( ctype_lower ( $ str [ $ i ] ) ) { $ firstLower = $ i ; break ; } } if ( $ lastUpper == -1 $ firstLower == -1 ) return 0 ; $ countUpper = 0 ; for ( $ i = $ firstLower ; $ i < $ n ; $ i ++ ) { if ( ctype_upper ( $ str [ $ i ] ) ) { $ countUpper ++ ; } } $ countLower = 0 ; for ( $ i = 0 ; $ i < $ lastUpper ; $ i ++ ) { if ( ctype_lower ( $ str [ $ i ] ) ) { $ countLower ++ ; } } return min ( $ countLower , $ countUpper ) ; } { $ str = \\\" geEksFOrGEekS \\\" ; $ n = strlen ( $ str ) ; echo ( minOperations ( $ str , $ n ) ) ; } ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if any anagram of a string is palindrome or not | Javascript program to Check if any anagram of a string is palindrome or not ; function to check whether characters of a string can form a palindrome ; Create a count array and initialize all values as 0 ; For each character in input strings , increment count in the corresponding count array ; Count odd occurring characters ; Return true if odd count is 0 or 1 , ; Driver program to test to print printDups\\\"\\nHow can the above be solved in JS?\",\"targets\":\"let NO_OF_CHARS = 256 ; function canFormPalindrome ( str ) { let count = new Array ( NO_OF_CHARS ) ; count . fill ( 0 ) ; for ( let i = 0 ; i < str . length ; i ++ ) count [ str [ i ] . charCodeAt ( ) ] ++ ; let odd = 0 ; for ( let i = 0 ; i < NO_OF_CHARS ; i ++ ) { if ( ( count [ i ] & 1 ) != 0 ) odd ++ ; if ( odd > 1 ) return false ; } return true ; } document . write ( canFormPalindrome ( \\\" \\\" ) ? \\\" \\\" + \\\" \\\" : \\\" \\\" + \\\" \\\" ) ; document . write ( canFormPalindrome ( \\\" \\\" ) ? \\\" \\\" : \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Difference between Insertion sort and Selection sort | C # program for implementation of selection sort ; Function to implement the selection sort ; One by one move boundary of unsorted subarray ; Find the minimum element in unsorted array ; Swap the found minimum element with the first element ; Function to print an array ; Driver Code ; Function Call ; Print the array\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GFG { static void selectionSort ( int [ ] arr , int n ) { int i , j , min_idx ; for ( i = 0 ; i < n - 1 ; i ++ ) { min_idx = i ; for ( j = i + 1 ; j < n ; j ++ ) if ( arr [ j ] < arr [ min_idx ] ) min_idx = j ; int temp = arr [ min_idx ] ; arr [ min_idx ] = arr [ i ] ; arr [ i ] = temp ; } } static void printArray ( int [ ] arr , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) { Console . Write ( arr [ i ] + \\\" \u2581 \\\" ) ; } Console . WriteLine ( ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 64 , 25 , 12 , 22 , 11 } ; int n = arr . Length ; selectionSort ( arr , n ) ; Console . Write ( \\\" Sorted \u2581 array : \u2581 \\n \\\" ) ; printArray ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Largest right circular cylinder within a cube | Function to find the biggest right circular cylinder ; side cannot be negative ; radius of right circular cylinder ; height of right circular cylinder ; volume of right circular cylinder ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def findVolume ( a ) :\\n\\tif ( a < 0 ) :\\n\\t\\treturn - 1\\n\\tr = a \\/ 2\\n\\th = a\\n\\tV = 3.14 * pow ( r , 2 ) * h\\n\\treturn V\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\ta = 5\\n\\tprint ( findVolume ( a ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"Check for Majority Element in a sorted array | ;\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nbool isMajorityElement ( int arr [ ] , int n , int key ) { if ( arr [ n \\/ 2 ] == key ) return true ; else return false ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 3 , 3 , 3 , 10 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int x = 3 ; if ( isMajorityElement ( arr , n , x ) ) printf ( \\\" % d \u2581 appears \u2581 more \u2581 than \u2581 % d \u2581 times \u2581 in \u2581 arr [ ] \\\" , x , n \\/ 2 ) ; else printf ( \\\" % d \u2581 does \u2581 not \u2581 appear \u2581 more \u2581 than \u2581 % d \u2581 times \u2581 in \u2581 \\\" \\\" arr [ ] \\\" , x , n \\/ 2 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find two numbers whose sum and GCD are given | C ++ program to find two numbers whose sum and GCD is given ; Function to find two numbers whose sum and gcd is given ; sum != gcd checks that both the numbers are positive or not ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void findTwoNumbers ( int sum , int gcd ) { if ( __gcd ( gcd , sum - gcd ) == gcd && sum != gcd ) cout << \\\" a \u2581 = \u2581 \\\" << min ( gcd , sum - gcd ) << \\\" , \u2581 b \u2581 = \u2581 \\\" << sum - min ( gcd , sum - gcd ) << endl ; else cout << -1 << endl ; } int main ( ) { int sum = 8 ; int gcd = 2 ; findTwoNumbers ( sum , gcd ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find the direction from given string | C # implementation of above approach ; Function to find the final direction ; if count is positive that implies resultant is clockwise direction ; if count is negative that implies resultant is anti - clockwise direction ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static String findDirection ( String s ) { int count = 0 ; String d = \\\" \\\" ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ 0 ] == ' \\n ' ) return null ; if ( s [ i ] == ' L ' ) count -- ; else { if ( s [ i ] == ' R ' ) count ++ ; } } if ( count > 0 ) { if ( count % 4 == 0 ) d = \\\" N \\\" ; else if ( count % 4 == 1 ) d = \\\" E \\\" ; else if ( count % 4 == 2 ) d = \\\" S \\\" ; else if ( count % 4 == 3 ) d = \\\" W \\\" ; } if ( count < 0 ) { if ( count % 4 == 0 ) d = \\\" N \\\" ; else if ( count % 4 == - 1 ) d = \\\" W \\\" ; else if ( count % 4 == - 2 ) d = \\\" S \\\" ; else if ( count % 4 == - 3 ) d = \\\" E \\\" ; } return d ; } public static void Main ( ) { String s = \\\" LLRLRRL \\\" ; Console . WriteLine ( findDirection ( s ) ) ; s = \\\" LL \\\" ; Console . WriteLine ( findDirection ( s ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Permutation of first N natural numbers having given array as the prefix maximum array | Java program for the above approach ; Function to check if the maximum prefix array of ans [ ] is equal to array arr [ ] ; Initialize a variable , Max ; Traverse the array , ans [ ] ; Store the maximum value upto index i ; If it is not equal to a [ i ] , then return false ; Otherwise return false ; Function to find the permutation of the array whose prefix maximum array is same as the given array a [ ] ; Stores the required permutation ; Stores the index of first occurrence of elements ; Traverse the array a [ ] ; If a [ i ] is not present in um , then store it in um ; Update the ans [ i ] to a [ i ] ; Stores the unvisited numbers ; Fill the array , v [ ] ; Store the index ; Traverse the array , ans [ ] ; Fill v [ j ] at places where ans [ i ] is 0 ; Check if the current permutation maximum prefix array is same as the given array a [ ] ; If true , the print the permutation ; Otherwise , print - 1 ; Driver Code ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static boolean checkPermutation ( int ans [ ] , int a [ ] , int n ) { int Max = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { Max = Math . max ( Max , ans [ i ] ) ; if ( Max != a [ i ] ) return false ; } return true ; } static void findPermutation ( int a [ ] , int n ) { int ans [ ] = new int [ n ] ; HashMap < Integer , Integer > um = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! um . containsKey ( a [ i ] ) ) { ans [ i ] = a [ i ] ; um . put ( a [ i ] , i ) ; } } ArrayList < Integer > v = new ArrayList < > ( ) ; int j = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( ! um . containsKey ( i ) ) { v . add ( i ) ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( ans [ i ] == 0 ) { ans [ i ] = v . get ( j ) ; j ++ ; } } if ( checkPermutation ( ans , a , n ) ) { for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( ans [ i ] + \\\" \u2581 \\\" ) ; } } else System . out . println ( \\\" - 1\\\" ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 4 , 5 , 5 } ; int N = arr . length ; findPermutation ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Area of a Circumscribed Circle of a Square | PHP Program to find the area of a circumscribed circle ; function returns the area ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ PI = 3.14159265 ; function areacircumscribed ( $ a ) { global $ PI ; return ( $ a * $ a * ( $ PI \\/ 2 ) ) ; } $ a = 6 ; echo \\\" \u2581 Area \u2581 of \u2581 an \u2581 circumscribed \u2581 circle \u2581 is \u2581 : \u2581 \\\" , areacircumscribed ( $ a ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Aronson 's Sequence | Java program to generate the first n terms of Aronson 's sequence ; Returns the given number in words ; Get number of digits in given number ; Base cases ; The following arrays contain one digit ( both cardinal and ordinal forms ) , two digit ( < 20 , ordinal forms ) numbers , and multiples ( ordinal forms ) and powers of 10. ; If single digit number ; here len can be 3 or 4 ; last two digits ; Handle all powers of 10 ; Handle two digit numbers < 20 ; Function to print the first n terms of Aronson 's sequence ; check if character is alphabet or not ; convert number to words in ordinal format and append ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static String convert_to_words ( char [ ] num ) { int len = num . length ; if ( len == 0 len > 4 ) { return \\\" \\\" ; } String single_digits_temp [ ] = { \\\" \\\" , \\\" one \\\" , \\\" two \\\" , \\\" three \\\" , \\\" four \\\" , \\\" five \\\" , \\\" six \\\" , \\\" seven \\\" , \\\" eight \\\" , \\\" nine \\\" } ; String single_digits [ ] = { \\\" \\\" , \\\" first \\\" , \\\" second \\\" , \\\" third \\\" , \\\" fourth \\\" , \\\" fifth \\\" , \\\" sixth \\\" , \\\" seventh \\\" , \\\" eighth \\\" , \\\" ninth \\\" } ; String two_digits [ ] = { \\\" \\\" , \\\" tenth \\\" , \\\" eleventh \\\" , \\\" twelfth \\\" , \\\" thirteenth \\\" , \\\" fourteenth \\\" , \\\" fifteenth \\\" , \\\" sixteenth \\\" , \\\" seventeenth \\\" , \\\" eighteenth \\\" , \\\" nineteenth \\\" } ; String tens_multiple [ ] = { \\\" \\\" , \\\" tenth \\\" , \\\" twentieth \\\" , \\\" thirtieth \\\" , \\\" fortieth \\\" , \\\" fiftieth \\\" , \\\" sixtieth \\\" , \\\" seventieth \\\" , \\\" eightieth \\\" , \\\" ninetieth \\\" } ; String tens_power [ ] = { \\\" hundred \\\" , \\\" thousand \\\" } ; String word = \\\" \\\" ; if ( len == 1 ) { word += single_digits [ num [ 0 ] - '0' ] ; return word ; } int i = 0 , ctr = 0 ; String s = \\\" \u2581 \\\" ; while ( i < len ) { if ( len >= 3 ) { if ( num [ i ] != '0' ) { word += single_digits_temp [ num [ i ] - '0' ] + \\\" \u2581 \\\" ; word += tens_power [ len - 3 ] + \\\" \u2581 \\\" ; ctr ++ ; } len -- ; num = Arrays . copyOfRange ( num , 1 , num . length ) ; } else { if ( ctr != 0 ) { s = \\\" \u2581 and \u2581 \\\" ; word = word . substring ( 0 , word . length ( ) - 1 ) ; } if ( num [ i + 1 ] == '0' ) if ( num [ i ] == '0' ) word = word + \\\" th \\\" ; else word += s + tens_multiple [ num [ i ] - '0' ] ; else if ( num [ i ] == '1' ) word += s + two_digits [ num [ i + 1 ] - '0' + 1 ] ; else { if ( num [ i ] != '0' ) word += s + tens_multiple [ num [ i ] - '0' ] . substring ( 0 , tens_multiple [ num [ i ] - '0' ] . length ( ) - 4 ) + \\\" y \u2581 \\\" ; else word += s ; word += single_digits [ num [ i + 1 ] - '0' ] ; } i += 2 ; } if ( i == len ) { if ( word . charAt ( 0 ) == ' \u2581 ' ) word = word . substring ( 1 , word . length ( ) ) ; } } return word ; } static void Aronsons_sequence ( int n ) { String str = \\\" T \u2581 is \u2581 the \u2581 \\\" ; int ind = 0 ; for ( int i = 0 ; i < str ....\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count of integral coordinates that lies inside a Square | Function to calculate the integral points inside a square ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def countIntgralPoints ( x1 , y1 , x2 , y2 ) :\\n\\tprint ( ( y2 - y1 - 1 ) * ( x2 - x1 - 1 ) )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tx1 = 1\\n\\ty1 = 1\\n\\tx2 = 4\\n\\ty2 = 4\\n\\tcountIntgralPoints ( x1 , y1 , x2 , y2 )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count occurrences of substring X before every occurrence of substring Y in a given string | Java program for the above approach ; Function to count occurrences of the string Y in the string S for every occurrence of X in S ; Stores the count of occurrences of X ; Stores the lengths of the three strings ; Traverse the string S ; If the current substring is Y , then increment the value of count by 1 ; If the current substring is X , then print the count ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static void countOccurrences ( String S , String X , String Y ) { int count = 0 ; int N = S . length ( ) , A = X . length ( ) ; int B = Y . length ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( S . substring ( i , Math . min ( N , i + B ) ) . equals ( Y ) ) count ++ ; if ( S . substring ( i , Math . min ( N , i + A ) ) . equals ( X ) ) System . out . print ( count + \\\" \u2581 \\\" ) ; } } public static void main ( String [ ] args ) { String S = \\\" abcdefdefabc \\\" ; String X = \\\" abc \\\" ; String Y = \\\" def \\\" ; countOccurrences ( S , X , Y ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count of greater elements for each element in the Array | Python 3 implementation of the above approach ; Store the frequency of the array elements ; Store the sum of frequency of elements greater than the current element ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def countOfGreaterElements ( arr , n ) :\\n\\tmp = { i : 0 for i in range ( 1000 ) }\\n\\tfor i in range ( n ) :\\n\\t\\tmp [ arr [ i ] ] += 1\\n\\tx = 0\\n\\tp = [ ]\\n\\tq = [ ]\\n\\tm = [ ]\\n\\tfor key , value in mp . items ( ) :\\n\\t\\tm . append ( [ key , value ] )\\n\\tm = m [ : : - 1 ]\\n\\tfor p in m :\\n\\t\\ttemp = p [ 1 ]\\n\\t\\tmp [ p [ 0 ] ] = x\\n\\t\\tx += temp\\n\\tfor i in range ( n ) :\\n\\t\\tprint ( mp [ arr [ i ] ] , end = \\\" \u2581 \\\" )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 7 , 9 , 5 , 2 , 1 , 3 , 4 , 8 , 6 ]\\n\\tn = len ( arr )\\n\\tcountOfGreaterElements ( arr , n )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program to check Involutory Matrix | Java Program to implement involutory matrix . ; Function for matrix multiplication . ; Function to check involutory matrix . ; multiply function call . ; Driver function . ; Function call . If function return true then if part will execute otherwise else part will execute .\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int N = 3 ; static void multiply ( int mat [ ] [ ] , int res [ ] [ ] ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { res [ i ] [ j ] = 0 ; for ( int k = 0 ; k < N ; k ++ ) res [ i ] [ j ] += mat [ i ] [ k ] * mat [ k ] [ j ] ; } } } static boolean InvolutoryMatrix ( int mat [ ] [ ] ) { int res [ ] [ ] = new int [ N ] [ N ] ; multiply ( mat , res ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( i == j && res [ i ] [ j ] != 1 ) return false ; if ( i != j && res [ i ] [ j ] != 0 ) return false ; } } return true ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 1 , 0 , 0 } , { 0 , - 1 , 0 } , { 0 , 0 , - 1 } } ; if ( InvolutoryMatrix ( mat ) ) System . out . println ( \\\" Involutory \u2581 Matrix \\\" ) ; else System . out . println ( \\\" Not \u2581 Involutory \u2581 Matrix \\\" ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Queries to count the number of unordered co | Java program to find number of unordered coprime pairs of integers from 1 to N ; to store euler 's totient function ; to store required answer ; Computes and prints totient of all numbers smaller than or equal to N . ; Initialise the phi [ ] with 1 ; Compute other Phi values ; If phi [ p ] is not computed already , then number p is prime ; Phi of a prime number p is always equal to p - 1. ; Update phi values of all multiples of p ; Add contribution of p to its multiple i by multiplying with ( 1 - 1 \\/ p ) ; function to compute number coprime pairs ; function call to compute euler totient function ; prefix sum of all euler totient function values ; Driver code ; function call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static final int N = 100005 ; static int [ ] phi ; static int [ ] S ; static void computeTotient ( ) { for ( int i = 1 ; i < N ; i ++ ) phi [ i ] = i ; for ( int p = 2 ; p < N ; p ++ ) { if ( phi [ p ] == p ) { phi [ p ] = p - 1 ; for ( int i = 2 * p ; i < N ; i += p ) { phi [ i ] = ( phi [ i ] \\/ p ) * ( p - 1 ) ; } } } } static void CoPrimes ( ) { computeTotient ( ) ; for ( int i = 1 ; i < N ; i ++ ) S [ i ] = S [ i - 1 ] + phi [ i ] ; } public static void main ( String args [ ] ) { phi = new int [ N ] ; S = new int [ N ] ; CoPrimes ( ) ; int q [ ] = { 3 , 4 } ; int n = q . length ; for ( int i = 0 ; i < n ; i ++ ) System . out . println ( \\\"Number of unordered coprime \\\" \u2581 + \u2581 \\\" pairs of integers from 1 to \\\" \u2581 + \u2581 q [ i ] \u2581 + \u2581 \\\" are \\\" + S[q[i]] ); } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum increments to make all array elements equal with sum same as the given array after exactly one removal | Function to check if an array of equal elements with sum equal to the given array can be obtained or not ; Base case ; Stores sum of array elements ; Stores second largest array element ; Stores the largest array element ; Traverse the array ; Update secMax ; Update Max ; Update secMax ; Update totalSum ; If totalSum is less than secMax * ( N - 1 ) ) ; If totalSum is not divisible by ( N - 1 ) ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function CheckAllarrayEqual ( arr , N ) { if ( N == 1 ) { return true ; } let totalSum = arr [ 0 ] ; let secMax = Number . MIN_VALUE ; let Max = arr [ 0 ] ; for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] >= Max ) { secMax = Max ; Max = arr [ i ] ; } else if ( arr [ i ] > secMax ) { secMax = arr [ i ] ; } totalSum += arr [ i ] ; } if ( ( secMax * ( N - 1 ) ) > totalSum ) { return false ; } if ( totalSum % ( N - 1 ) != 0 ) { return false ; } return true ; } let arr = [ 6 , 2 , 2 , 2 ] ; let N = arr . length ; if ( CheckAllarrayEqual ( arr , N ) ) { document . write ( \\\" \\\" ) ; } else { document . write ( \\\" \\\" ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count pairs of equal elements possible by excluding each array element once | Function to count the number of required pairs for every array element ; Initialize a map ; Update the frequency of every element ; Stores the count of pairs ; Traverse the map ; Count the number of ways to select pairs consisting of equal elements only ; Traverse the array ; Print the count for every array element ; Driver code ; Given array ; Size of the array\\\"\\nSolution in Python:\",\"targets\":\"def countEqualElementPairs ( arr , N ) :\\n\\tmp = { }\\n\\tfor i in range ( N ) :\\n\\t\\tif arr [ i ] in mp :\\n\\t\\t\\tmp [ arr [ i ] ] += 1\\n\\t\\telse :\\n\\t\\t\\tmp [ arr [ i ] ] = 1\\n\\ttotal = 0\\n\\tfor key , value in mp . items ( ) :\\n\\t\\ttotal += ( value * ( value - 1 ) ) \\/ 2\\n\\tfor i in range ( N ) :\\n\\t\\tprint ( int ( total - ( mp [ arr [ i ] ] - 1 ) ) , end = \\\" \u2581 \\\" )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 1 , 1 , 2 , 1 , 2 ]\\n\\tN = len ( arr )\\n\\tcountEqualElementPairs ( arr , N )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Pair having all other given pairs lying between its minimum and maximum | C # program for the above approach ; Function to find the position of the pair that covers every pair in the array [ , ] arr ; Position to store the index ; Stores the maximum second value ; Stores the minimum first value ; Iterate over the array of pairs ; Update right maximum ; Update left minimum ; Iterate over the array of pairs ; If any pair exists with value { left , right } then store it ; Print the answer ; Driver Code ; Given array of pairs ; Function Call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void position ( int [ , ] arr , int N ) { int pos = - 1 ; int right = int . MinValue ; int left = int . MaxValue ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i , 1 ] > right ) { right = arr [ i , 1 ] ; } if ( arr [ i , 0 ] < left ) { left = arr [ i , 0 ] ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i , 0 ] == left && arr [ i , 1 ] == right ) { pos = i + 1 ; } } Console . Write ( pos + \\\" \\n \\\" ) ; } public static void Main ( String [ ] args ) { int [ , ] arr = { { 3 , 3 } , { 1 , 3 } , { 2 , 2 } , { 2 , 3 } , { 1 , 2 } } ; int N = arr . GetLength ( 0 ) ; position ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count set bits in an integer | ; Check each bit in a number is set or not and return the total count of the set bits . ; ( 1 << i ) = pow ( 2 , i ) ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\nint countSetBits ( int N ) { int count = 0 ; for ( int i = 0 ; i < sizeof ( int ) * 8 ; i ++ ) { if ( N & ( 1 << i ) ) count ++ ; } return count ; } int main ( ) { int N = 15 ; printf ( \\\" % d \\\" , countSetBits ( N ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check whether two strings can be made equal by increasing prefixes | Java implementation of above approach ; check whether the first string can be converted to the second string by increasing the ASCII value of prefix string of first string ; length of two strings ; If lengths are not equal ; store the difference of ASCII values ; difference of first element ; traverse through the string ; the ASCII value of the second string should be greater than or equal to first string , if it is violated return false . ; store the difference of ASCII values ; the difference of ASCII values should be in descending order ; if the difference array is not in descending order ; if all the ASCII values of characters of first string is less than or equal to the second string and the difference array is in descending order , return true ; Driver code ; create two strings ; check whether the first string can be converted to the second string\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static boolean find ( String s1 , String s2 ) { int len = s1 . length ( ) , len_1 = s2 . length ( ) ; if ( len != len_1 ) { return false ; } int d [ ] = new int [ len ] ; d [ 0 ] = s2 . charAt ( 0 ) - s1 . charAt ( 0 ) ; for ( int i = 1 ; i < len ; i ++ ) { if ( s1 . charAt ( i ) > s2 . charAt ( i ) ) { return false ; } else { d [ i ] = s2 . charAt ( i ) - s1 . charAt ( i ) ; } } for ( int i = 0 ; i < len - 1 ; i ++ ) { if ( d [ i ] < d [ i + 1 ] ) { return false ; } } return true ; } public static void main ( String [ ] args ) { String s1 = \\\" abcd \\\" , s2 = \\\" bcdd \\\" ; if ( find ( s1 , s2 ) ) { System . out . println ( \\\" Yes \\\" ) ; } else { System . out . println ( \\\" No \\\" ) ; } } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count sub | C ++ implementation of the approach ; Function to count sub - arrays whose product is divisible by K ; Calculate the product of the current sub - array ; If product of the current sub - array is divisible by K ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; #define ll long long\\nint countSubarrays ( const int * arr , int n , int K ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { ll product = 1 ; for ( int x = i ; x <= j ; x ++ ) product *= arr [ x ] ; if ( product % K == 0 ) count ++ ; } } return count ; } int main ( ) { int arr [ ] = { 6 , 2 , 8 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int K = 4 ; cout << countSubarrays ( arr , n , K ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Centered cube number | Program to find nth Centered cube number ; Function to find Centered cube number ; Formula to calculate nth Centered cube number & return it into main function . ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int centered_cube ( int n ) { return ( 2 * n + 1 ) * ( n * n + n + 1 ) ; } int main ( ) { int n = 3 ; cout << n << \\\" th \u2581 Centered \u2581 cube \u2581 number : \u2581 \\\" ; cout << centered_cube ( n ) ; cout << endl ; n = 10 ; cout << n << \\\" th \u2581 Centered \u2581 cube \u2581 number : \u2581 \\\" ; cout << centered_cube ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find nth Term of the Series 1 2 2 4 4 4 4 8 8 8 8 8 8 8 8 ... | Function that will return nth term ; Get n ; Get the value ; Get n ; Get the value\\\"\\nSolution in php:\",\"targets\":\"< ? php function getValue ( $ n ) { $ i = 0 ; $ k = 1 ; while ( $ i < $ n ) { $ i = $ i + $ k ; $ k = $ k * 2 ; } return ( int ) $ k \\/ 2 ; } $ n = 9 ; echo getValue ( $ n ) , \\\" \\n \\\" ; $ n = 1025 ; echo getValue ( $ n ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if a given Binary Tree is Heap | C # program to checks if a binary tree is max heap or not ; Tree node structure ; To add a new node ; Driver code ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; public class GFG { public class Node { public int data ; public Node left ; public Node right ; } ; static Node newNode ( int k ) { Node node = new Node ( ) ; node . data = k ; node . right = node . left = null ; return node ; } static bool isHeap ( Node root ) { Queue < Node > q = new Queue < Node > ( ) ; q . Enqueue ( root ) ; bool nullish = false ; while ( q . Count != 0 ) { Node temp = q . Peek ( ) ; q . Dequeue ( ) ; if ( temp . left != null ) { if ( nullish temp . left . data >= temp . data ) { return false ; } q . Enqueue ( temp . left ) ; } else { nullish = true ; } if ( temp . right != null ) { if ( nullish temp . right . data >= temp . data ) { return false ; } q . Enqueue ( temp . right ) ; } else { nullish = true ; } } return true ; } public static void Main ( String [ ] args ) { Node root = null ; root = newNode ( 10 ) ; root . left = newNode ( 9 ) ; root . right = newNode ( 8 ) ; root . left . left = newNode ( 7 ) ; root . left . right = newNode ( 6 ) ; root . right . left = newNode ( 5 ) ; root . right . right = newNode ( 4 ) ; root . left . left . left = newNode ( 3 ) ; root . left . left . right = newNode ( 2 ) ; root . left . right . left = newNode ( 1 ) ; if ( isHeap ( root ) ) Console . Write ( \\\" Given \u2581 binary \u2581 tree \u2581 is \u2581 a \u2581 Heap \\n \\\" ) ; else Console . Write ( \\\" Given \u2581 binary \u2581 tree \u2581 is \u2581 not \u2581 a \u2581 Heap \\n \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sum of first N natural numbers with alternate signs | Function to find the sum of First N natural numbers with alternate signs ; Stores sum of alternate sign of First N natural numbers ; If is an even number ; Update alternateSum ; If i is an odd number ; Update alternateSum ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def alternatingSumOfFirst_N ( N ) :\\n\\talternateSum = 0\\n\\tfor i in range ( 1 , N + 1 ) :\\n\\t\\tif ( i % 2 == 0 ) :\\n\\t\\t\\talternateSum += - i\\n\\t\\telse :\\n\\t\\t\\talternateSum += i\\n\\treturn alternateSum\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tN = 6\\n\\tprint ( alternatingSumOfFirst_N ( N ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program to find whether a no is power of two | Function to check if x is power of 2 ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def isPowerOfTwo ( n ) :\\n\\tif ( n == 0 ) :\\n\\t\\treturn False\\n\\twhile ( n != 1 ) :\\n\\t\\tif ( n % 2 != 0 ) :\\n\\t\\t\\treturn False\\n\\t\\tn = n \\/\\/ 2\\n\\treturn True\\nif ( isPowerOfTwo ( 31 ) ) :\\n\\tprint ( ' Yes ' )\\nelse :\\n\\tprint ( ' No ' )\\nif ( isPowerOfTwo ( 64 ) ) :\\n\\tprint ( ' Yes ' )\\nelse :\\n\\tprint ( ' No ' )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Smallest length of number divisible by K formed by using D only | Function to form the smallest number possible ; Array to mark the remainders counted already ; Iterate over the range ; If that remainder is already found , return - 1 ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function smallest ( k , d ) { let cnt = 1 ; let m = d % k ; let v = new Array ( k ) . fill ( 0 ) ; v [ m ] = 1 ; while ( 1 ) { if ( m == 0 ) return cnt ; m = ( ( ( m * ( 10 % k ) ) % k ) + ( d % k ) ) % k ; if ( v [ m ] == 1 ) return - 1 ; v [ m ] = 1 ; cnt ++ ; } return - 1 ; } let d = 1 ; let k = 41 ; document . write ( smallest ( k , d ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum cost to convert str1 to str2 with the given operations | Function to return the minimum cost to convert str1 to sr2 ; For every character of str1 ; If current character is not equal in both the strings ; If the next character is also different in both the strings then these characters can be swapped ; Change the current character ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def minCost ( str1 , str2 , n ) :\\n\\tcost = 0\\n\\tfor i in range ( n ) :\\n\\t\\tif ( str1 [ i ] != str2 [ i ] ) :\\n\\t\\t\\tif ( i < n - 1 and str1 [ i + 1 ] != str2 [ i + 1 ] ) :\\n\\t\\t\\t\\tswap ( str1 [ i ] , str1 [ i + 1 ] )\\n\\t\\t\\t\\tcost += 1\\n\\t\\t\\telse :\\n\\t\\t\\t\\tcost += 1\\n\\treturn cost\\nif __name__ == ' _ _ main _ _ ' :\\n\\tstr1 = \\\" abb \\\"\\n\\tstr2 = \\\" bba \\\"\\n\\tn = len ( str1 )\\n\\tprint ( minCost ( str1 , str2 , n ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find nth Magic Number | Function to find nth magic number ; Go through every bit of n ; If last bit of n is set ; proceed to next bit $n >>= 1 ; or $n = $n \\/ 2 ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function nthMagicNo ( $ n ) { $ pow = 1 ; $ answer = 0 ; while ( $ n ) { $ pow = $ pow * 5 ; if ( $ n & 1 ) $ answer += $ pow ; } return $ answer ; } $ n = 5 ; echo \\\" nth \u2581 magic \u2581 number \u2581 is \u2581 \\\" , nthMagicNo ( $ n ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the maximum sum ( a + b ) for a given input integer N satisfying the given condition | Java implementation to find the largest value of a + b satisfying the given condition ; Function to return the maximum sum of a + b satisfying the given condition ; Initialize max_sum ; Consider all possible pairs and check the sum divides product property ; To find the largest factor k ; Check if the product is divisible by the sum ; Storing the maximum sum in the max_sum variable ; Return the max_sum value ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int getLargestSum ( int N ) { int max_sum = 0 ; for ( int i = 1 ; i * i <= N ; i ++ ) { for ( int j = i + 1 ; j * j <= N ; j ++ ) { int k = N \\/ j ; int a = k * i ; int b = k * j ; if ( a <= N && b <= N && a * b % ( a + b ) == 0 ) max_sum = Math . max ( max_sum , a + b ) ; } } return max_sum ; } public static void main ( String [ ] args ) { int N = 25 ; int max_sum = getLargestSum ( N ) ; System . out . print ( max_sum + \\\"\\n\\\"); } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count subarrays having sum modulo K same as the length of the subarray | C ++ program of the above approach ; Function that counts the subarrays s . t . sum of elements in the subarray modulo k is equal to size of subarray ; Stores the count of ( pref [ i ] - i ) % k ; Stores the count of subarray ; Stores prefix sum of the array ; Find prefix sum array ; Base Condition ; Remove the index at present after K indices from the current index ; Update the answer for subarrays ending at the i - th index ; Add the calculated value of current index to count ; Print the count of subarrays ; Driver Code ; Given arr [ ] ; Size of the array ; Given K ; Function Call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; long long int countSubarrays ( int a [ ] , int n , int k ) { unordered_map < int , int > cnt ; long long int ans = 0 ; vector < int > pref ; pref . push_back ( 0 ) ; for ( int i = 0 ; i < n ; i ++ ) pref . push_back ( ( a [ i ] + pref [ i ] ) % k ) ; cnt [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { int remIdx = i - k ; if ( remIdx >= 0 ) { cnt [ ( pref [ remIdx ] - remIdx % k + k ) % k ] -- ; } ans += cnt [ ( pref [ i ] - i % k + k ) % k ] ; cnt [ ( pref [ i ] - i % k + k ) % k ] ++ ; } cout << ans << ' \u2581 ' ; } int main ( ) { int arr [ ] = { 2 , 3 , 5 , 3 , 1 , 5 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int K = 4 ; countSubarrays ( arr , N , K ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program for sum of cos ( x ) series | PHP program to find the sum of cos ( x ) series ; here x is in degree . we have to convert it to radian for using it with series formula , as in series expansion angle is in radian ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php $ PI = 3.142 ; function cosXSertiesSum ( $ x , $ n ) { global $ PI ; $ x = $ x * ( $ PI \\/ 180.0 ) ; $ res = 1 ; $ sign = 1 ; $ fact = 1 ; $ pow = 1 ; for ( $ i = 1 ; $ i < 5 ; $ i ++ ) { $ sign = $ sign * -1 ; $ fact = $ fact * ( 2 * $ i - 1 ) * ( 2 * $ i ) ; $ pow = $ pow * $ x * $ x ; $ res = $ res + $ sign * $ pow \\/ $ fact ; } return $ res ; } $ x = 50 ; $ n = 5 ; echo cosXSertiesSum ( $ x , 5 ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the minimum element in a sorted and rotated array | Function to find minimum element ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function findMin ( arr , low , high ) { while ( low < high ) { let mid = Math . floor ( low + ( high - low ) \\/ 2 ) ; if ( arr [ mid ] == arr [ high ] ) high -- ; else if ( arr [ mid ] > arr [ high ] ) low = mid + 1 ; else high = mid ; } return arr [ high ] ; } var arr1 = [ 5 , 6 , 1 , 2 , 3 , 4 ] ; var n1 = arr1 . length ; document . write ( \\\" \\\" + findMin ( arr1 , 0 , n1 - 1 ) + \\\" \\\" ) ; var arr2 = [ 1 , 2 , 3 , 4 ] ; var n2 = arr2 . length ; document . write ( \\\" \\\" + findMin ( arr2 , 0 , n2 - 1 ) + \\\" \\\" ) ; var arr3 = [ 1 ] ; var n3 = arr3 . length ; document . write ( \\\" \\\" + findMin ( arr3 , 0 , n3 - 1 ) + \\\" \\\" ) ; var arr4 = [ 1 , 2 ] ; var n4 = arr4 . length ; document . write ( \\\" \\\" + findMin ( arr4 , 0 , n4 - 1 ) + \\\" \\\" ) ; var arr5 = [ 2 , 1 ] ; var n5 = arr5 . length ; document . write ( \\\" \\\" + findMin ( arr5 , 0 , n5 - 1 ) + \\\" \\\" ) ; var arr6 = [ 5 , 6 , 7 , 1 , 2 , 3 , 4 ] ; var n6 = arr6 . length ; document . write ( \\\" \\\" + findMin ( arr6 , 0 , n6 - 1 ) + \\\" \\\" ) ; var arr7 = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ; var n7 = arr7 . length ; document . write ( \\\" \\\" + findMin ( arr7 , 0 , n7 - 1 ) + \\\" \\\" ) ; var arr8 = [ 2 , 3 , 4 , 5 , 6 , 7 , 8 , 1 ] ; var n8 = arr8 . length ; document . write ( \\\" \\\" + findMin ( arr8 , 0 , n8 - 1 ) + \\\" \\\" ) ; var arr9 = [ 3 , 4 , 5 , 1 , 2 ] ; var n9 = arr9 . length ; document . write ( \\\" \\\" + findMin ( arr9 , 0 , n9 - 1 ) + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Majority Element | Function to find the candidate for Majority ; Function to check if the candidate occurs more than n \\/ 2 times ; Function to print Majority Element ; Find the candidate for Majority ; Print the candidate if it is Majority ; Driver Code ; Function call\\\"\\nSolution in Javascript:\",\"targets\":\"function findCandidate ( a , size ) { let maj_index = 0 , count = 1 ; let i ; for ( i = 1 ; i < size ; i ++ ) { if ( a [ maj_index ] == a [ i ] ) count ++ ; else count -- ; if ( count == 0 ) { maj_index = i ; count = 1 ; } } return a [ maj_index ] ; } function isMajority ( a , size , cand ) { let i , count = 0 ; for ( i = 0 ; i < size ; i ++ ) { if ( a [ i ] == cand ) count ++ ; } if ( count > parseInt ( size \\/ 2 , 10 ) ) return true ; else return false ; } function printMajority ( a , size ) { let cand = findCandidate ( a , size ) ; if ( isMajority ( a , size , cand ) ) document . write ( \\\" \\\" + cand + \\\" \\\" ) ; else document . write ( \\\" \\\" ) ; } let a = [ 1 , 3 , 3 , 1 , 2 ] ; let size = a . length ; printMajority ( a , size ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Game Theory in Balanced Ternary Numeral System | ( Moving 3 k steps at a time ) | C ++ implementation of the approach ; Function that returns true if the game cannot be won ; Driver code ; Common length\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool isDefeat ( string s1 , string s2 , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( ( s1 [ i ] == '0' && s2 [ i ] == '1' ) || ( s1 [ i ] == '1' && s2 [ i ] == '0' ) ) continue ; else if ( ( s1 [ i ] == '0' && s2 [ i ] == ' Z ' ) || ( s1 [ i ] == ' Z ' && s2 [ i ] == '0' ) ) continue ; else { return true ; } } return false ; } int main ( ) { string s1 = { \\\"01001101ZZ \\\" } ; string s2 = { \\\"10Z1001000\\\" } ; int n = 10 ; if ( isDefeat ( s1 , s2 , n ) ) cout << \\\" Defeat \\\" ; else cout << \\\" Victory \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimum squares to cover a rectangle | PHP program to find the minimum number of squares to cover the surface of the rectangle with given dimensions ; function to count the number of squares that can cover the surface of the rectangle ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function squares ( $ l , $ b , $ a ) { return ceil ( $ l \\/ ( double ) $ a ) * ceil ( $ b \\/ ( double ) $ a ) ; } $ l = 11 ; $ b = 23 ; $ a = 14 ; echo squares ( $ l , $ b , $ a ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Positive elements at even and negative at odd positions ( Relative order not maintained ) | Print array function ; Driver code ; before modification ; out of order positive element ; find out of order negative element in remaining array ; out of order negative element ; find out of order positive element in remaining array ; after modification\\\"\\nSolution in Python:\",\"targets\":\"def printArray ( a , n ) :\\n\\tfor i in a :\\n\\t\\tprint ( i , end = \\\" \u2581 \\\" )\\n\\tprint ( )\\narr = [ 1 , - 3 , 5 , 6 , - 3 , 6 , 7 , - 4 , 9 , 10 ]\\nn = len ( arr )\\nprintArray ( arr , n )\\nfor i in range ( n ) :\\n\\tif ( arr [ i ] >= 0 and i % 2 == 1 ) :\\n\\t\\tfor j in range ( i + 1 , n ) :\\n\\t\\t\\tif ( arr [ j ] < 0 and j % 2 == 0 ) :\\n\\t\\t\\t\\tarr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\\n\\t\\t\\t\\tbreak\\n\\telif ( arr [ i ] < 0 and i % 2 == 0 ) :\\n\\t\\tfor j in range ( i + 1 , n ) :\\n\\t\\t\\tif ( arr [ j ] >= 0 and j % 2 == 1 ) :\\n\\t\\t\\t\\tarr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\\n\\t\\t\\t\\tbreak\\nprintArray ( arr , n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Print all possible combinations of r elements in a given array of size n | The main function that prints all combinations of size r in arr [ ] of size n . This function mainly uses combinationUtil ( ) ; A temporary array to store all combination one by one ; Print all combination using temprary array 'data[] ; arr [ ] -- -> Input Array data [ ] -- -> Temporary array to store current combination start & end -- -> Staring and Ending indexes in arr [ ] index -- -> Current index in data [ ] r -- -> Size of a combination to be printed ; Current combination is ready to be printed , print it ; replace index with all possible elements . The condition \\\" end - i + 1 \u2581 > = \u2581 \u2581 r - index \\\" makes sure that including one element at index will make a combination with remaining elements at remaining positions ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def printCombination ( arr , n , r ) :\\n\\tdata = [ 0 ] * r ;\\n\\tcombinationUtil ( arr , data , 0 , n - 1 , 0 , r ) ;\\ndef combinationUtil ( arr , data , start , end , index , r ) :\\n\\tif ( index == r ) :\\n\\t\\tfor j in range ( r ) :\\n\\t\\t\\tprint ( data [ j ] , end = \\\" \u2581 \\\" ) ;\\n\\t\\tprint ( ) ;\\n\\t\\treturn ;\\n\\ti = start ;\\n\\twhile ( i <= end and end - i + 1 >= r - index ) :\\n\\t\\tdata [ index ] = arr [ i ] ;\\n\\t\\tcombinationUtil ( arr , data , i + 1 , end , index + 1 , r ) ;\\n\\t\\ti += 1 ;\\narr = [ 1 , 2 , 3 , 4 , 5 ] ;\\nr = 3 ;\\nn = len ( arr ) ;\\nprintCombination ( arr , n , r ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program to print ' N ' alphabet using the number pattern from 1 to n | C ++ implementation of the approach ; Function to print the desired Alphabet N Pattern ; Declaring the values of Right , Left and Diagonal values ; Main Loop for the rows ; For the left Values ; Spaces for the diagonals ; Condition for the diagonals ; Spaces for the Right Values ; For the right values ; Driver Code ; Size of the Pattern ; Calling the function to print the desired Pattern\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void Alphabet_N_Pattern ( int N ) { int index , side_index , size ; int Right = 1 , Left = 1 , Diagonal = 2 ; for ( index = 0 ; index < N ; index ++ ) { cout << Left ++ ; for ( side_index = 0 ; side_index < 2 * ( index ) ; side_index ++ ) cout << \\\" \u2581 \\\" ; if ( index != 0 && index != N - 1 ) cout << Diagonal ++ ; else cout << \\\" \u2581 \\\" ; for ( side_index = 0 ; side_index < 2 * ( N - index - 1 ) ; side_index ++ ) cout << \\\" \u2581 \\\" ; cout << Right ++ ; cout << endl ; } } int main ( int argc , char * * argv ) { int Size = 6 ; Alphabet_N_Pattern ( Size ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find most significant set bit of a number | Simple Java program to find MSB number for given n . ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static int setBitNumber ( int n ) { if ( n == 0 ) return 0 ; int msb = 0 ; n = n \\/ 2 ; while ( n != 0 ) { n = n \\/ 2 ; msb ++ ; } return ( 1 << msb ) ; } public static void main ( String [ ] args ) { int n = 0 ; System . out . println ( setBitNumber ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count of substrings from given Ternary strings containing characters at least once | Function to count the number of substrings consists of 0 , 1 , and 2 ; Initialize frequency array of size 3 ; Stores the resultant count ; Traversing string str ; Update frequency array ; If all the characters are present counting number of substrings possible ; Update number of substrings ; Return the number of substrings ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def countSubstrings ( str ) :\\n\\tfreq = [ 0 ] * 3\\n\\tcount = 0\\n\\ti = 0\\n\\tfor j in range ( 0 , len ( str ) ) :\\n\\t\\tfreq [ ord ( str [ j ] ) - ord ( '0' ) ] += 1\\n\\t\\twhile ( freq [ 0 ] > 0 and freq [ 1 ] > 0 and freq [ 2 ] > 0 ) :\\n\\t\\t\\ti += 1\\n\\t\\t\\tfreq [ ord ( str [ i ] ) - ord ( '0' ) ] -= 1\\n\\t\\tcount += i\\n\\treturn count\\nstr = \\\"00021\\\"\\ncount = countSubstrings ( str )\\nprint ( count )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count composite fibonacci numbers from given array | Java program to implement the above approach ; Function to find all Fibonacci numbers up to Max ; Store all Fibonacci numbers upto Max ; Stores previous element of Fibonacci sequence ; Stores previous element of Fibonacci sequence ; Insert prev into hashmap ; Insert all the Fibonacci numbers up to Max ; Insert curr into hashmap ; Stores curr into temp ; Update curr ; Update prev ; Function to find all Composite numbers up to Max ; isPrime [ i ] : Stores if i is a prime number or not ; Calculate all prime numbers up to Max using Sieve of Eratosthenes ; If P is a prime number ; Set all multiple of P as non - prime ; Update isPrime ; Function to find the numbers which is both a composite and Fibonacci number ; Stores the largest element of the array ; Traverse the array arr [ ] ; Update Max ; isPrim [ i ] check i is a prime number or not ; Stores all the Fibonacci numbers ; Traverse the array arr [ ] ; current element is not a composite number ; If current element is a Fibonacci and composite number ; Print current element ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static boolean [ ] isPrime ; static HashSet < Integer > createhashmap ( int Max ) { HashSet < Integer > hashmap = new HashSet < > ( ) ; int curr = 1 ; int prev = 0 ; hashmap . add ( prev ) ; while ( curr < Max ) { hashmap . add ( curr ) ; int temp = curr ; curr = curr + prev ; prev = temp ; } return hashmap ; } static void SieveOfEratosthenes ( int Max ) { isPrime = new boolean [ Max ] ; Arrays . fill ( isPrime , true ) ; isPrime [ 0 ] = false ; isPrime [ 1 ] = false ; for ( int p = 2 ; p * p <= Max ; p ++ ) { if ( isPrime [ p ] ) { for ( int i = p * p ; i <= Max ; i += p ) { isPrime [ i ] = false ; } } } } static void cntFibonacciPrime ( int arr [ ] , int N ) { int Max = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { Max = Math . max ( Max , arr [ i ] ) ; } SieveOfEratosthenes ( Max ) ; HashSet < Integer > hashmap = createhashmap ( Max ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) continue ; if ( ( hashmap . contains ( arr [ i ] ) ) && ! isPrime [ arr [ i ] ] ) { System . out . print ( arr [ i ] + \\\" \u2581 \\\" ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 13 , 55 , 7 , 3 , 5 , 21 , 233 , 144 , 89 } ; int N = arr . length ; cntFibonacciPrime ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Subset Sum Problem in O ( sum ) space | ; initializing with 1 as sum 0 is always possible ; loop to go through every element of the elements array ; to change the value o all possible sum values to True ; If target is possible return True else False ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def isPossible ( elements , target ) :\\n\\tdp = [ False ] * ( target + 1 )\\n\\tdp [ 0 ] = True\\n\\tfor ele in elements :\\n\\t\\tfor j in range ( target , ele - 1 , - 1 ) :\\n\\t\\t\\tif dp [ j - ele ] :\\n\\t\\t\\t\\tdp [ j ] = True\\n\\treturn dp [ target ]\\narr = [ 6 , 2 , 5 ]\\ntarget = 7\\nif isPossible ( arr , target ) :\\n\\tprint ( \\\" YES \\\" )\\nelse :\\n\\tprint ( \\\" NO \\\" )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Largest Square in a Binary Matrix with at most K 1 s for multiple Queries | Javascript implementation to find the largest square in the matrix such that it contains atmost K 1 's ; Function to calculate the largest square with atmost K 1 s for Q queries ; Loop to solve for each query ; Traversing the each sub square and counting total ; Breaks when exceeds the maximum count ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"var MAX = 100 ; function largestSquare ( matrix , R , C , q_i , q_j , K , Q ) { for ( var q = 0 ; q < Q ; q ++ ) { var i = q_i [ q ] ; var j = q_j [ q ] ; var min_dist = Math . min ( Math . min ( i , j ) , Math . min ( R - i - 1 , C - j - 1 ) ) ; var ans = - 1 ; for ( var k = 0 ; k <= min_dist ; k ++ ) { var count = 0 ; for ( var row = i - k ; row <= i + k ; row ++ ) for ( var col = j - k ; col <= j + k ; col ++ ) count += matrix [ row ] [ col ] ; if ( count > K ) break ; ans = 2 * k + 1 ; } document . write ( ans + \\\" \\\" ) ; } } var matrix = [ [ 1 , 0 , 1 , 0 , 0 ] , [ 1 , 0 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] , [ 1 , 0 , 0 , 1 , 0 ] ] ; var K = 9 , Q = 1 ; var q_i = [ 1 ] ; var q_j = [ 2 ] ; largestSquare ( matrix , 4 , 5 , q_i , q_j , K , Q ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Given a number as a string , find the number of contiguous subsequences which recursively add up to 9 | PHP program to count substrings with recursive sum equal to 9 ; To store result ; Consider every character as beginning of substring ; sum of digits in current substring ; One by one choose every character as an ending character ; Add current digit to sum , if sum becomes multiple of 5 then increment count . Let us do modular arithmetic to avoid overflow for big strings ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function count9s ( $ number ) { $ count = 0 ; $ n = strlen ( $ number ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ sum = $ number [ $ i ] - '0' ; if ( $ number [ $ i ] == '9' ) $ count ++ ; for ( $ j = $ i + 1 ; $ j < $ n ; $ j ++ ) { $ sum = ( $ sum + $ number [ $ j ] - '0' ) % 9 ; if ( $ sum == 0 ) $ count ++ ; } } return $ count ; } echo count9s ( \\\" 4189 \\\" ) , \\\" \\n \\\" ; echo count9s ( \\\" 1809 \\\" ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the element in the matrix generated by given rules | Function to return the element in the rth row and cth column from the required matrix ; Condition for lower half of matrix ; Condition if element is in first row ; Starting element of AP in row r ; Common difference of AP in row r ; Position of element to find in AP in row r ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def getElement ( N , r , c ) :\\n\\tif ( r > c ) :\\n\\t\\treturn 0 ;\\n\\tif ( r == 1 ) :\\n\\t\\treturn c ;\\n\\ta = ( r + 1 ) * pow ( 2 , r - 2 ) ;\\n\\td = pow ( 2 , r - 1 ) ;\\n\\tc = c - r ;\\n\\telement = a + d * c ;\\n\\treturn element ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tN = 4 ; R = 3 ; C = 4 ;\\n\\tprint ( getElement ( N , R , C ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Number of pairs of lines having integer intersection points | Count number of pairs of lines having integer intersection point ; Initialize arrays to store counts ; Count number of odd and even Pi ; Count number of odd and even Qi ; Return the count of pairs ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function countPairs ( P , Q , N , M ) { var A = [ 0 , 0 ] , B = [ 0 , 0 ] ; for ( var i = 0 ; i < N ; i ++ ) A [ P [ i ] % 2 ] ++ ; for ( var i = 0 ; i < M ; i ++ ) B [ Q [ i ] % 2 ] ++ ; return ( A [ 0 ] * B [ 0 ] + A [ 1 ] * B [ 1 ] ) ; } var P = [ 1 , 3 , 2 ] , Q = [ 3 , 0 ] ; var N = P . length ; var M = Q . length ; document . write ( countPairs ( P , Q , N , M ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"An efficient way to check whether n | A simple C ++ program to check if n - th Fibonacci number is multiple of 10. ; Returns true if n - th Fibonacci number is multiple of 10. ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nint fibonacci ( int n ) { int a = 0 , b = 1 , c ; if ( n <= 1 ) return n ; for ( int i = 2 ; i <= n ; i ++ ) { c = a + b ; a = b ; b = c ; } return c ; } bool isMultipleOf10 ( int n ) { int f = fibonacci ( 30 ) ; return ( f % 10 == 0 ) ; } int main ( ) { int n = 30 ; if ( isMultipleOf10 ( n ) ) printf ( \\\" Yes \\n \\\" ) ; else printf ( \\\" No \\n \\\" ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Sum of divisors of factorial of a number | C # program to find sum of proper divisor of factorial of a number ; function to calculate factorial ; function to calculate sum of divisor ; Returns sum of divisors of n ! ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class Division { static int fac ( int n ) { if ( n == 0 ) return 1 ; return n * fac ( n - 1 ) ; } static int div ( int x ) { int ans = 0 ; for ( int i = 1 ; i <= x ; i ++ ) if ( x % i == 0 ) ans += i ; return ans ; } static int sumFactDiv ( int n ) { return div ( fac ( n ) ) ; } public static void Main ( ) { int n = 4 ; Console . Write ( sumFactDiv ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Partition problem | DP | A Dynamic Programming based C # program to partition problem ; Returns true if arr [ ] can be partitioned in two subsets of equal sum , otherwise false ; Calculate sum of all elements ; Initialze the part array as 0 ; Fill the partition table in bottom up manner ; The element to be included in the sum cannot be greater than the sum ; Check if sum - arr [ i ] could be formed from a subset using elements before index i ; Driver code ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static bool findPartiion ( int [ ] arr , int n ) { int sum = 0 ; int i , j ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; bool [ ] part = new bool [ sum \\/ 2 + 1 ] ; for ( i = 0 ; i <= sum \\/ 2 ; i ++ ) { part [ i ] = false ; } for ( i = 0 ; i < n ; i ++ ) { for ( j = sum \\/ 2 ; j >= arr [ i ] ; j -- ) { if ( part [ j - arr [ i ] ] == true j == arr [ i ] ) part [ j ] = true ; } } return part [ sum \\/ 2 ] ; } static void Main ( ) { int [ ] arr = { 1 , 3 , 3 , 2 , 3 , 2 } ; int n = 6 ; if ( findPartiion ( arr , n ) == true ) Console . WriteLine ( \\\" Can \u2581 be \u2581 divided \u2581 into \u2581 two \u2581 \\\" + \\\" subsets \u2581 of \u2581 equal \u2581 sum \\\" ) ; else Console . WriteLine ( \\\" Can \u2581 not \u2581 be \u2581 divided \u2581 into \u2581 \\\" + \\\" two \u2581 subsets \u2581 of \u2581 equal \u2581 sum \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find all possible coordinates of parallelogram | coordinates of A ; coordinates of B ; coordinates of C\\\"\\nSolution in php:\",\"targets\":\"< ? php $ ax = 5 ; $ ay = 0 ; $ bx = 1 ; $ by = 1 ; $ cx = 2 ; $ cy = 5 ; echo $ ax + $ bx - $ cx , \\\" , \u2581 \\\" , $ ay + $ by - $ cy , \\\" \\n \\\" ; echo $ ax + $ cx - $ bx , \\\" , \u2581 \\\" , $ ay + $ cy - $ by , \\\" \\n \\\" ; echo $ cx + $ bx - $ ax , \\\" , \u2581 \\\" , $ cy + $ by - $ ax ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Dynamic Programming | Returns true if there is a subset of set [ ] with sum equal to given sum ; Base Cases ; If last element is greater than sum , then ignore it ; else , check if sum can be obtained by any of the following ( a ) including the last element ( b ) excluding the last element ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function isSubsetSum ( set , n , sum ) { if ( sum == 0 ) return true ; if ( n == 0 ) return false ; if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ; return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ; } let set = [ 3 , 34 , 4 , 12 , 5 , 2 ] ; let sum = 9 ; let n = set . length ; if ( isSubsetSum ( set , n , sum ) == true ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find original sequence from Array containing the sequence merged many times in order | Function that returns the restored permutation ; Vector to store the result ; Set to insert unique elements ; Check if the element is coming first time ; Push in result vector ; Function to print the result ; Given Array ; Function call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function restore ( arr , N ) { let result = [ ] ; let count1 = 1 ; let s = new Set ( ) ; for ( let i = 0 ; i < N ; i ++ ) { s . add ( arr [ i ] ) ; if ( s . size == count1 ) { result . push ( arr [ i ] ) ; count1 ++ ; } } return result ; } function print_result ( result ) { for ( let i = 0 ; i < result . length ; i ++ ) document . write ( result [ i ] + \\\" \\\" ) ; } let arr = [ 1 , 13 , 1 , 24 , 13 , 24 , 2 , 2 ] ; let N = arr . length ; print_result ( restore ( arr , N ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Kth ancestor of all nodes in an N | Java implementation of the above approach ; Function to add an edge in the tree ; DFS to find the Kth ancestor of every node ; Pushing current node in the vector ; Traverse its neighbors ; If K ancestors are not found for current node ; Add the Kth ancestor for the node ; Function to find Kth ancestor of each node ; Building the tree ; Stores all parents of a node ; Store Kth ancestor of all nodes ; Print the ancestors ; Driver code ; Given N and K ; Given edges of n - ary tree ; Function call\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void addEdge ( Vector < Integer > v [ ] , int x , int y ) { v [ x ] . add ( y ) ; v [ y ] . add ( x ) ; } static void dfs ( Vector < Integer > tree [ ] , Vector < Integer > temp , int ancestor [ ] , int u , int parent , int k ) { temp . add ( u ) ; for ( int i : tree [ u ] ) { if ( i == parent ) continue ; dfs ( tree , temp , ancestor , i , u , k ) ; } temp . remove ( temp . size ( ) - 1 ) ; if ( temp . size ( ) < k ) { ancestor [ u ] = - 1 ; } else { ancestor [ u ] = temp . get ( temp . size ( ) - k ) ; } } static void KthAncestor ( int N , int K , int E , int edges [ ] [ ] ) { @ SuppressWarnings ( \\\" unchecked \\\" ) Vector < Integer > [ ] tree = new Vector [ N + 1 ] ; for ( int i = 0 ; i < tree . length ; i ++ ) tree [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < E ; i ++ ) { addEdge ( tree , edges [ i ] [ 0 ] , edges [ i ] [ 1 ] ) ; } Vector < Integer > temp = new Vector < Integer > ( ) ; int [ ] ancestor = new int [ N + 1 ] ; dfs ( tree , temp , ancestor , 1 , 0 , K ) ; for ( int i = 1 ; i <= N ; i ++ ) { System . out . print ( ancestor [ i ] + \\\" \u2581 \\\" ) ; } } public static void main ( String [ ] args ) { int N = 9 ; int K = 2 ; int E = 8 ; int edges [ ] [ ] = { { 1 , 2 } , { 1 , 3 } , { 2 , 4 } , { 2 , 5 } , { 2 , 6 } , { 3 , 7 } , { 3 , 8 } , { 3 , 9 } } ; KthAncestor ( N , K , E , edges ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Efficiently compute sums of diagonals of a matrix | A simple Python program to find sum of diagonals ; Condition for principal diagonal ; Condition for secondary diagonal ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"MAX = 100\\ndef printDiagonalSums ( mat , n ) :\\n\\tprincipal = 0\\n\\tsecondary = 0 ;\\n\\tfor i in range ( 0 , n ) :\\n\\t\\tfor j in range ( 0 , n ) :\\n\\t\\t\\tif ( i == j ) :\\n\\t\\t\\t\\tprincipal += mat [ i ] [ j ]\\n\\t\\t\\tif ( ( i + j ) == ( n - 1 ) ) :\\n\\t\\t\\t\\tsecondary += mat [ i ] [ j ]\\n\\tprint ( \\\" Principal \u2581 Diagonal : \\\" , principal )\\n\\tprint ( \\\" Secondary \u2581 Diagonal : \\\" , secondary )\\na = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] ]\\nprintDiagonalSums ( a , 4 )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Nearest prime less than given number n | PHP program to find the nearest prime to n . ; array to store all primes less than 10 ^ 6 ; Utility function of Sieve of Sundaram ; In general Sieve of Sundaram , produces primes smaller than ( 2 * x + 2 ) for a number given number x ; This array is used to separate numbers of the form i + j + 2 ij from others where 1 <= i <= j ; eliminate indexes which does not produce primes ; Since 2 is a prime number ; Remaining primes are of the form 2 * i + 1 such that marked [ i ] is false . ; modified binary search to find nearest prime less than N ; base condition is , if we are reaching at left corner or right corner of primes [ ] array then return that corner element because before or after that we don 't have any prime number in primes array ; now if n is itself a prime so it will be present in primes array and here we have to find nearest prime less than n so we will return primes [ mid - 1 ] ; now if primes [ mid ] < n and primes [ mid + 1 ] > n that means we reached at nearest prime ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php $ MAX = 10000 ; $ primes = array ( ) ; function Sieve ( ) { global $ MAX , $ primes ; $ n = $ MAX ; $ nNew = ( int ) ( sqrt ( $ n ) ) ; $ marked = array_fill ( 0 , ( int ) ( $ n \\/ 2 + 500 ) , 0 ) ; for ( $ i = 1 ; $ i <= ( $ nNew - 1 ) \\/ 2 ; $ i ++ ) for ( $ j = ( $ i * ( $ i + 1 ) ) << 1 ; $ j <= $ n \\/ 2 ; $ j = $ j + 2 * $ i + 1 ) $ marked [ $ j ] = 1 ; array_push ( $ primes , 2 ) ; for ( $ i = 1 ; $ i <= $ n \\/ 2 ; $ i ++ ) if ( $ marked [ $ i ] == 0 ) array_push ( $ primes , 2 * $ i + 1 ) ; } function binarySearch ( $ left , $ right , $ n ) { global $ primes ; if ( $ left <= $ right ) { $ mid = ( int ) ( ( $ left + $ right ) \\/ 2 ) ; if ( $ mid == 0 || $ mid == count ( $ primes ) - 1 ) return $ primes [ $ mid ] ; if ( $ primes [ $ mid ] == $ n ) return $ primes [ $ mid - 1 ] ; if ( $ primes [ $ mid ] < $ n && $ primes [ $ mid + 1 ] > $ n ) return $ primes [ $ mid ] ; if ( $ n < $ primes [ $ mid ] ) return binarySearch ( $ left , $ mid - 1 , $ n ) ; else return binarySearch ( $ mid + 1 , $ right , $ n ) ; } return 0 ; } Sieve ( ) ; $ n = 17 ; echo binarySearch ( 0 , count ( $ primes ) - 1 , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Primality Test | Set 5 ( Using Lucas | CPP program to check for primality using Lucas - Lehmer series . ; Function to check whether ( 2 ^ p - 1 ) is prime or not . ; generate the number ; First number of the series ; Generate the rest ( p - 2 ) terms of the series . ; now if the ( p - 1 ) th term is 0 return true else false . ; Driver Program ; Check whether 2 ^ p - 1 is prime or not .\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#include \\nusing namespace std ; bool isPrime ( int p ) { long long checkNumber = pow ( 2 , p ) - 1 ; long long nextval = 4 % checkNumber ; for ( int i = 1 ; i < p - 1 ; i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ; return ( nextval == 0 ) ; } int main ( ) { int p = 7 ; long long checkNumber = pow ( 2 , p ) - 1 ; if ( isPrime ( p ) ) cout << checkNumber << \\\" \u2581 is \u2581 Prime . \\\" ; else cout << checkNumber << \\\" \u2581 is \u2581 not \u2581 Prime . \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if given number is Emirp Number or not | Returns true if n is prime else false ; Corner case ; Check from 2 to n - 1 ; Function will check whether number is Emirp or not ; Check if n is prime ; Find reverse of n ; If both Original and Reverse are Prime , then it is an Emirp number ; Input number\\\"\\nSolution in php:\",\"targets\":\"< ? php function isPrime ( $ n ) { if ( $ n <= 1 ) return -1 ; for ( $ i = 2 ; $ i < $ n ; $ i ++ ) if ( $ n % $ i == 0 ) return -1 ; return 1 ; } function isEmirp ( $ n ) { if ( isPrime ( $ n ) == -1 ) return -1 ; $ rev = 0 ; while ( $ n != 0 ) { $ d = $ n % 10 ; $ rev = $ rev * 10 + $ d ; $ n \\/= 10 ; } return isPrime ( $ rev ) ; } $ n = 13 ; if ( isEmirp ( $ n ) == -1 ) echo \\\" Yes \\\" ; else echo \\\" No \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the number of ways to reach Kth step in stair case | Python3 implementation of the approach ; Function to return the number of ways to reach the kth step ; Create the dp array ; Broken steps ; Calculate the number of ways for the rest of the positions ; If it is a blocked position ; Number of ways to get to the ith step ; Return the required answer ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"MOD = 1000000007 ;\\ndef number_of_ways ( arr , n , k ) :\\n\\tif ( k == 1 ) :\\n\\t\\treturn 1 ;\\n\\tdp = [ - 1 ] * ( k + 1 ) ;\\n\\tfor i in range ( n ) :\\n\\t\\tdp [ arr [ i ] ] = 0 ;\\n\\tdp [ 0 ] = 1 ;\\n\\tdp [ 1 ] = 1 if ( dp [ 1 ] == - 1 ) else dp [ 1 ] ;\\n\\tfor i in range ( 2 , k + 1 ) :\\n\\t\\tif ( dp [ i ] == 0 ) :\\n\\t\\t\\tcontinue ;\\n\\t\\tdp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\\n\\t\\tdp [ i ] %= MOD ;\\n\\treturn dp [ k ] ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ 3 ] ;\\n\\tn = len ( arr ) ;\\n\\tk = 6 ;\\n\\tprint ( number_of_ways ( arr , n , k ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Connect n ropes with minimum cost | Java program to connect n ropes with minimum cost ; Create a priority queue ; Initialize result ; While size of priority queue is more than 1 ; Extract shortest two ropes from pq ; Connect the ropes : update result and insert the new rope to pq ; Driver program to test above function\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class ConnectRopes { static int minCost ( int arr [ ] , int n ) { PriorityQueue < Integer > pq = new PriorityQueue < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { pq . add ( arr [ i ] ) ; } int res = 0 ; while ( pq . size ( ) > 1 ) { int first = pq . poll ( ) ; int second = pq . poll ( ) ; res += first + second ; pq . add ( first + second ) ; } return res ; } public static void main ( String args [ ] ) { int len [ ] = { 4 , 3 , 2 , 6 } ; int size = len . length ; System . out . println ( \\\" Total \u2581 cost \u2581 for \u2581 connecting \\\" + \\\" \u2581 ropes \u2581 is \u2581 \\\" + minCost ( len , size ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Turn off the rightmost set bit | Set 2 | Unsets the rightmost set bit of n and returns the result ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def FlipBits ( n ) :\\n\\tn -= ( n & ( - n ) ) ;\\n\\treturn n ;\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 12 ;\\n\\tprint ( \\\" The \u2581 number \u2581 after \u2581 unsetting \u2581 the \\\" , end = \\\" \\\" ) ;\\n\\tprint ( \\\" \u2581 rightmost \u2581 set \u2581 bit : \u2581 \\\" , FlipBits ( N ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find Cube Pairs | Set 2 ( A n ^ ( 1 \\/ 3 ) Solution ) | C ++ program to find pairs that can represent the given number as sum of two cubes ; Function to find pairs that can represent the given number as sum of two cubes ; find cube root of n ; create a array of size of size ' cubeRoot ' ; for index i , cube [ i ] will contain i ^ 3 ; Find all pairs in above sorted array cube [ ] whose sum is equal to n ; Driver function\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#include \\nusing namespace std ; void findPairs ( int n ) { int cubeRoot = pow ( n , 1.0 \\/ 3.0 ) ; int cube [ cubeRoot + 1 ] ; for ( int i = 1 ; i <= cubeRoot ; i ++ ) cube [ i ] = i * i * i ; int l = 1 ; int r = cubeRoot ; while ( l < r ) { if ( cube [ l ] + cube [ r ] < n ) l ++ ; else if ( cube [ l ] + cube [ r ] > n ) r -- ; else { cout << \\\" ( \\\" << l << \\\" , \u2581 \\\" << r << \\\" ) \\\" << endl ; l ++ ; r -- ; } } } int main ( ) { int n = 20683 ; findPairs ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the sum of a Series ( 1 * 1 ) + ( 2 * 2 ) + ( 3 * 3 ) + ( 4 * 4 ) + ( 5 * 5 ) + ... + ( n * n ) | Java program to calculate the following series ; Function to calculate the following series ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static int Series ( int n ) { int i ; int sums = 0 ; for ( i = 1 ; i <= n ; i ++ ) sums += ( i * i ) ; return sums ; } public static void main ( String [ ] args ) { int n = 3 ; int res = Series ( n ) ; System . out . println ( res ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Number of substrings divisible by 6 in a string of integers | Java program to calculate number of substring divisible by 6. ; Return the number of substring divisible by 6 and starting at index i in s [ ] and previous sum of digits modulo 3 is m . ; End of the string . ; If already calculated , return the stored value . ; Converting into integer . ; Increment result by 1 , if current digit is divisible by 2 and sum of digits is divisible by 3. And recur for next index with new modulo . ; Returns substrings divisible by 6. ; For storing the value of all states . ; If string contain 0 , increment count by 1. ; Else calculate using recursive function . Pass previous sum modulo 3 as 0. ; Driven Program\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static int MAX = 100002 ; static int f ( int i , int m , char s [ ] , int memoize [ ] [ ] ) { if ( i == s . length ) { return 0 ; } if ( memoize [ i ] [ m ] != - 1 ) { return memoize [ i ] [ m ] ; } int x = s [ i ] - '0' ; int ans = ( ( x + m ) % 3 == 0 && x % 2 == 0 ) ? 1 + f ( i + 1 , ( m + x ) % 3 , s , memoize ) : f ( i + 1 , ( m + x ) % 3 , s , memoize ) ; memoize [ i ] [ m ] = ans ; return memoize [ i ] [ m ] ; } static int countDivBy6 ( char s [ ] ) { int n = s . length ; int [ ] [ ] memoize = new int [ n + 1 ] [ 3 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { memoize [ i ] [ j ] = - 1 ; } } int ans = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == '0' ) { ans ++ ; } else { ans += f ( i , 0 , s , memoize ) ; } } return ans ; } public static void main ( String [ ] args ) { char s [ ] = \\\"4806\\\" . toCharArray ( ) ; System . out . println ( countDivBy6 ( s ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Print array after it is right rotated K times | Function to rightRotate array ; If rotation is greater than size of array ; Printing rightmost kth elements ; Prints array after ' k ' elements ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function RightRotate ( a , n , k ) { k = k % n ; for ( let i = 0 ; i < n ; i ++ ) { if ( i < k ) { document . write ( a [ n + i - k ] + \\\" \\\" ) ; } else { document . write ( ( a [ i - k ] ) + \\\" \\\" ) ; } } document . write ( \\\" \\\" ) ; } let Array = [ 1 , 2 , 3 , 4 , 5 ] ; let N = Array . length ; let K = 2 ; RightRotate ( Array , N , K ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program for subtraction of matrices | Python 3 program for subtraction of matrices ; This function returns 1 if A [ ] [ ] and B [ ] [ ] are identical otherwise returns 0 ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"N = 4\\ndef subtract ( A , B , C ) :\\n\\tfor i in range ( N ) :\\n\\t\\tfor j in range ( N ) :\\n\\t\\t\\tC [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ]\\nA = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ]\\nB = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ]\\nC = A [ : ] [ : ]\\nsubtract ( A , B , C )\\nprint ( \\\" Result \u2581 matrix \u2581 is \\\" )\\nfor i in range ( N ) :\\n\\tfor j in range ( N ) :\\n\\t\\tprint ( C [ i ] [ j ] , \\\" \u2581 \\\" , end = ' ' )\\n\\tprint ( )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Longest Common Subsequence | DP | Dynamic Programming C implementation of LCS problem ; Returns length of LCS for X [ 0. . m - 1 ] , Y [ 0. . n - 1 ] ; Following steps build L [ m + 1 ] [ n + 1 ] in bottom up fashion . Note that L [ i ] [ j ] contains length of LCS of X [ 0. . i - 1 ] and Y [ 0. . j - 1 ] ; L [ m ] [ n ] contains length of LCS for X [ 0. . n - 1 ] and Y [ 0. . m - 1 ] ; Utility function to get max of 2 integers ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\nint max ( int a , int b ) ; int lcs ( char * X , char * Y , int m , int n ) { int L [ m + 1 ] [ n + 1 ] ; int i , j ; for ( i = 0 ; i <= m ; i ++ ) { for ( j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i ] [ j ] = 0 ; else if ( X [ i - 1 ] == Y [ j - 1 ] ) L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; else L [ i ] [ j ] = max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } return L [ m ] [ n ] ; } int max ( int a , int b ) { return ( a > b ) ? a : b ; } int main ( ) { char X [ ] = \\\" AGGTAB \\\" ; char Y [ ] = \\\" GXTXAYB \\\" ; int m = strlen ( X ) ; int n = strlen ( Y ) ; printf ( \\\" Length \u2581 of \u2581 LCS \u2581 is \u2581 % d \\\" , lcs ( X , Y , m , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the Excenters of a Triangle | Python3 program for the above approach ; Function to calculate the distance between a pair of points ; Function to calculate the coordinates of the excenters of a triangle ; Length of the sides of the triangle ; Stores the coordinates of the excenters of the triangle ; For I1 ; For I2 ; For I3 ; Print the excenters of the triangle ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"from math import sqrt\\ndef distance ( m , n , p , q ) :\\n\\treturn ( sqrt ( pow ( n - m , 2 ) + pow ( q - p , 2 ) * 1.0 ) )\\ndef Excenters ( x1 , y1 , x2 , y2 , x3 , y3 ) :\\n\\ta = distance ( x2 , x3 , y2 , y3 )\\n\\tb = distance ( x3 , x1 , y3 , y1 )\\n\\tc = distance ( x1 , x2 , y1 , y2 )\\n\\texcenter = [ [ 0 , 0 ] for i in range ( 4 ) ]\\n\\texcenter [ 1 ] [ 0 ] = ( ( - ( a * x1 ) + ( b * x2 ) + ( c * x3 ) ) \\/\\/ ( - a + b + c ) )\\n\\texcenter [ 1 ] [ 1 ] = ( ( - ( a * y1 ) + ( b * y2 ) + ( c * y3 ) ) \\/\\/ ( - a + b + c ) )\\n\\texcenter [ 2 ] [ 0 ] = ( ( ( a * x1 ) - ( b * x2 ) + ( c * x3 ) ) \\/\\/ ( a - b + c ) )\\n\\texcenter [ 2 ] [ 1 ] = ( ( ( a * y1 ) - ( b * y2 ) + ( c * y3 ) ) \\/\\/ ( a - b + c ) )\\n\\texcenter [ 3 ] [ 0 ] = ( ( ( a * x1 ) + ( b * x2 ) - ( c * x3 ) ) \\/\\/ ( a + b - c ) )\\n\\texcenter [ 3 ] [ 1 ] = ( ( ( a * y1 ) + ( b * y2 ) - ( c * y3 ) ) \\/\\/ ( a + b - c ) )\\n\\tfor i in range ( 1 , 4 ) :\\n\\t\\tprint ( int ( excenter [ i ] [ 0 ] ) , int ( excenter [ i ] [ 1 ] ) )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tx1 = 0\\n\\tx2 = 3\\n\\tx3 = 0\\n\\ty1 = 0\\n\\ty2 = 0\\n\\ty3 = 4\\n\\tExcenters ( x1 , y1 , x2 , y2 , x3 , y3 )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"Insertion Sort | C program for insertion sort ; Function to sort an array using insertion sort ; Move elements of arr [ 0. . i - 1 ] , that are greater than key , to one position ahead of their current position ; A utility function to print an array of size n ; Driver program to test insertion sort\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nvoid insertionSort ( int arr [ ] , int n ) { int i , key , j ; for ( i = 1 ; i < n ; i ++ ) { key = arr [ i ] ; j = i - 1 ; while ( j >= 0 && arr [ j ] > key ) { arr [ j + 1 ] = arr [ j ] ; j = j - 1 ; } arr [ j + 1 ] = key ; } } void printArray ( int arr [ ] , int n ) { int i ; for ( i = 0 ; i < n ; i ++ ) printf ( \\\" % d \u2581 \\\" , arr [ i ] ) ; printf ( \\\" \\n \\\" ) ; } int main ( ) { int arr [ ] = { 12 , 11 , 13 , 5 , 6 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; insertionSort ( arr , n ) ; printArray ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Babylonian method for square root | Returns the square root of n . Note that the function ; We are using n itself as initial approximation This can definitely be improved ; e decides the accuracy level ; Driver program to test above function\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def squareRoot ( n ) :\\n\\tx = n\\n\\ty = 1\\n\\te = 0.000001\\n\\twhile ( x - y > e ) :\\n\\t\\tx = ( x + y ) \\/ 2\\n\\t\\ty = n \\/ x\\n\\treturn x\\nn = 50\\nprint ( \\\" Square \u2581 root \u2581 of \\\" , n , \\\" is \\\" , round ( squareRoot ( n ) , 6 ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count inversions in a permutation of first N natural numbers | C # program for the above approach ; Function to count number of inversions in a permutation of first N natural numbers ; Store array elements in sorted order ; Store the count of inversions ; Traverse the array ; Store the index of first occurrence of arr [ i ] in vector V ; Add count of smaller elements than current element ; Erase current element from vector and go to next index ; Print the result ; Driver code ; Given Input ; Function Call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void countInversions ( int [ ] arr , int n ) { List < int > v = new List < int > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { v . Add ( i ) ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int itr = v . IndexOf ( arr [ i ] ) ; ans += itr ; v . RemoveAt ( itr ) ; } Console . WriteLine ( ans ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 2 , 3 , 1 , 5 , 4 } ; int n = arr . Length ; countInversions ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find the sum of first N odd Fibonacci numbers | C # program to Find the sum of first N odd Fibonacci numbers ; Function to calculate sum of first N odd Fibonacci numbers ; base values ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GFG { static int mod = 1000000007 ; static int sumOddFibonacci ( int n ) { int [ ] Sum = new int [ n + 1 ] ; Sum [ 0 ] = 0 ; Sum [ 1 ] = 1 ; Sum [ 2 ] = 2 ; Sum [ 3 ] = 5 ; Sum [ 4 ] = 10 ; Sum [ 5 ] = 23 ; for ( int i = 6 ; i <= n ; i ++ ) { Sum [ i ] = ( ( Sum [ i - 1 ] + ( 4 * Sum [ i - 2 ] ) % mod - ( 4 * Sum [ i - 3 ] ) % mod + mod ) % mod + ( Sum [ i - 4 ] - Sum [ i - 5 ] + mod ) % mod ) % mod ; } return Sum [ n ] ; } static public void Main ( ) { int n = 6 ; Console . WriteLine ( sumOddFibonacci ( n ) ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Counts Path in an Array | C # implementation of above approach ; find the number of ways to reach the end ; dp to store value ; base case ; Bottom up dp structure ; F [ i ] is dependent of F [ i + 1 ] to F [ i + k ] ; Return value of dp [ 0 ] ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static readonly int mod = ( int ) ( 1e9 + 7 ) ; static int ways ( int [ ] arr , int n ) { int [ ] dp = new int [ n + 1 ] ; dp [ n - 1 ] = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { dp [ i ] = 0 ; for ( int j = 1 ; ( ( j + i ) < n && j <= arr [ i ] ) ; j ++ ) { dp [ i ] += dp [ i + j ] ; dp [ i ] %= mod ; } } return dp [ 0 ] % mod ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 3 , 1 , 4 , 3 } ; int n = arr . Length ; Console . WriteLine ( ways ( arr , n ) % mod ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the sum of the series ( 1 \\/ a + 2 \\/ a ^ 2 + 3 \\/ a ^ 3 + ... + n \\/ a ^ n ) | C ++ program to find the sum of the given series ; Function to return the sum of the series ; variable to store the answer ; Math . pow ( x , y ) returns x ^ y ; Driver code ; Print the sum of the series\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#include \\n#include \\nusing namespace std ; float getSum ( int a , int n ) { float sum = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { sum += ( i \\/ pow ( a , i ) ) ; } return sum ; } int main ( ) { int a = 3 , n = 3 ; cout << ( getSum ( a , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Convert vowels into upper case character in a given string | Function to convert vowels into uppercase ; Stores the length of str ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def conVowUpp ( str ) :\\n\\tN = len ( str )\\n\\tstr1 = \\\" \\\"\\n\\tfor i in range ( N ) :\\n\\t\\tif ( str [ i ] == ' a ' or str [ i ] == ' e ' or str [ i ] == ' i ' or str [ i ] == ' o ' or str [ i ] == ' u ' ) :\\n\\t\\t\\tc = ( str [ i ] ) . upper ( )\\n\\t\\t\\tstr1 += c\\n\\t\\telse :\\n\\t\\t\\tstr1 += str [ i ]\\n\\tprint ( str1 )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tstr = \\\" eutopia \\\"\\n\\tconVowUpp ( str )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find missing elements of a range | A sorting based Java program to find missing elements from an array ; Print all elements of range [ low , high ] that are not present in arr [ 0. . n - 1 ] ; Do binary search for ' low ' in sorted array and find index of first element which either equal to or greater than low . ; Start from the found index and linearly search every range element x after this index in arr [ ] ; If x doesn 't math with current element print it ; If x matches , move to next element in arr [ ] ; Move to next element in range [ low , high ] ; Print range elements thar are greater than the last element of sorted array . ; Utility function to find ceil index of given element ; Driver program to test above function\\\"\\nSolution in Java:\",\"targets\":\"import java . util . Arrays ; public class PrintMissing { static void printMissing ( int ar [ ] , int low , int high ) { Arrays . sort ( ar ) ; int index = ceilindex ( ar , low , 0 , ar . length - 1 ) ; int x = low ; while ( index < ar . length && x <= high ) { if ( ar [ index ] != x ) { System . out . print ( x + \\\" \u2581 \\\" ) ; } else index ++ ; x ++ ; } while ( x <= high ) { System . out . print ( x + \\\" \u2581 \\\" ) ; x ++ ; } } static int ceilindex ( int ar [ ] , int val , int low , int high ) { if ( val < ar [ 0 ] ) return 0 ; if ( val > ar [ ar . length - 1 ] ) return ar . length ; int mid = ( low + high ) \\/ 2 ; if ( ar [ mid ] == val ) return mid ; if ( ar [ mid ] < val ) { if ( mid + 1 < high && ar [ mid + 1 ] >= val ) return mid + 1 ; return ceilindex ( ar , val , mid + 1 , high ) ; } else { if ( mid - 1 >= low && ar [ mid - 1 ] < val ) return mid ; return ceilindex ( ar , val , low , mid - 1 ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 , 4 } ; int low = 1 , high = 10 ; printMissing ( arr , low , high ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Remove minimum numbers from the array to get minimum OR value | Function to return the minimum deletions to get minimum OR ; To store the minimum element ; Find the minimum element from the array ; To store the frequency of the minimum element ; Find the frequency of the minimum element ; Return the final answer ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function findMinDel ( arr , n ) { var min_num = 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) min_num = Math . min ( arr [ i ] , min_num ) ; var cnt = 0 ; for ( var i = 0 ; i < n ; i ++ ) if ( arr [ i ] == min_num ) cnt ++ ; return n - cnt ; } var arr = [ 3 , 3 , 2 ] ; var n = arr . length ; document . write ( findMinDel ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Concatenate strings in any order to get Maximum Number of \\\" AB \\\" | C # implementation of above approach ; Function to find maximum number of ABs ; variable A , B , AB for count strings that end with ' A ' but not end with ' B ' , ' B ' but does not end with ' A ' and ' B ' and ends with ' A ' respectively . ; ' AB ' is already present in string before concatenate them ; count of strings that begins with ' B ' and ends with 'A ; count of strings that begins with ' B ' but does not end with ' A ' ; count of strings that ends with ' A ' but not end with ' B ' ; updating the value of ans and add extra count of ' AB ' ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int maxCountAB ( string [ ] s , int n ) { int A = 0 , B = 0 , BA = 0 , ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { string S = s [ i ] ; int L = S . Length ; for ( int j = 0 ; j < L - 1 ; j ++ ) { if ( S [ j ] == ' A ' && S [ j + 1 ] == ' B ' ) { ans ++ ; } } if ( S [ 0 ] == ' B ' && S [ L - 1 ] == ' A ' ) BA ++ ; else if ( S [ 0 ] == ' B ' ) B ++ ; else if ( S [ L - 1 ] == ' A ' ) A ++ ; } if ( BA == 0 ) ans += Math . Min ( B , A ) ; else if ( A + B == 0 ) ans += BA - 1 ; else ans += BA + Math . Min ( B , A ) ; return ans ; } public static void Main ( ) { string [ ] s = { \\\" ABCA \\\" , \\\" BOOK \\\" , \\\" BAND \\\" } ; int n = s . Length ; Console . WriteLine ( maxCountAB ( s , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sum of products of all combination taken ( 1 to n ) at a time | Java Program to find sum of all combination takne ( 1 to N ) at a time using dynamic programming ; find the postfix sum array ; modify the array such that we don 't have to compute the products which are obtained before ; finding sum of all combination taken 1 to N at a time ; sum taken 1 at time is simply sum of 1 - N ; for sum of products for all combination ; finding postfix array ; sum of products taken i + 1 at a time ; modify the array for overlapping problem ; Driver 's Code ; storing numbers from 1 to N ; calling allCombination\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void postfix ( int a [ ] , int n ) { for ( int i = n - 1 ; i > 0 ; i -- ) { a [ i - 1 ] = a [ i - 1 ] + a [ i ] ; } } static void modify ( int a [ ] , int n ) { for ( int i = 1 ; i < n ; i ++ ) { a [ i - 1 ] = i * a [ i ] ; } } static void allCombination ( int a [ ] , int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { sum += i ; } System . out . println ( \\\" f ( 1 ) \u2581 - - > \u2581 \\\" + sum ) ; for ( int i = 1 ; i < n ; i ++ ) { postfix ( a , n - i + 1 ) ; sum = 0 ; for ( int j = 1 ; j <= n - i ; j ++ ) { sum += ( j * a [ j ] ) ; } System . out . println ( \\\" f ( \\\" + ( i + 1 ) + \\\" ) \u2581 - - > \u2581 \\\" + sum ) ; modify ( a , n ) ; } } public static void main ( String [ ] args ) { int n = 5 ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = i + 1 ; } allCombination ( a , n ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if a number is formed by Concatenation of 1 , 14 or 144 only | Function to check if a number is formed by Concatenation of 1 , 14 or 144 only ; check for each possible digit if given number consist other then 1 , 14 , 144 print NO else print YES ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def checkNumber ( N ) :\\n\\ttemp = N\\n\\twhile ( temp > 0 ) :\\n\\t\\tif ( temp % 1000 == 144 ) :\\n\\t\\t\\ttemp \\/= 1000\\n\\t\\telif ( temp % 100 == 14 ) :\\n\\t\\t\\ttemp \\/= 100\\n\\t\\telif ( temp % 10 == 1 ) :\\n\\t\\t\\ttemp \\/= 10\\n\\t\\telse :\\n\\t\\t\\treturn \\\" YES \\\"\\n\\treturn \\\" NO \\\"\\nN = 1414 ;\\nprint ( checkNumber ( N ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Reverse string without using any temporary variable | C # Program to reverse a string without using temp variable ; Function to reverse string and return revesed string ; Iterate loop upto start not equal to end ; XOR for swapping the variable ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static String reversingString ( char [ ] str , int start , int end ) { while ( start < end ) { str [ start ] ^= str [ end ] ; str [ end ] ^= str [ start ] ; str [ start ] ^= str [ end ] ; ++ start ; -- end ; } return String . Join ( \\\" \\\" , str ) ; } public static void Main ( String [ ] args ) { String s = \\\" GeeksforGeeks \\\" ; Console . WriteLine ( reversingString ( s . ToCharArray ( ) , 0 , 12 ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"Program for array rotation | C program to rotate an array by d elements ; Function to left Rotate arr [ ] of size n by 1 ; Function to left rotate arr [ ] of size n by d ; utility function to print an array ; Driver program to test above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\nvoid leftRotatebyOne ( int arr [ ] , int n ) ; void leftRotatebyOne ( int arr [ ] , int n ) { int temp = arr [ 0 ] , i ; for ( i = 0 ; i < n - 1 ; i ++ ) arr [ i ] = arr [ i + 1 ] ; arr [ n - 1 ] = temp ; } void leftRotate ( int arr [ ] , int d , int n ) { int i ; for ( i = 0 ; i < d ; i ++ ) leftRotatebyOne ( arr , n ) ; } void printArray ( int arr [ ] , int n ) { int i ; for ( i = 0 ; i < n ; i ++ ) printf ( \\\" % d \u2581 \\\" , arr [ i ] ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; leftRotate ( arr , 2 , 7 ) ; printArray ( arr , 7 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to find parity | C # program to find parity of an integer ; Function to get parity of number n . It returns 1 if n has odd parity , and returns 0 if n has even parity ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static bool getParity ( int n ) { bool parity = false ; while ( n != 0 ) { parity = ! parity ; n = n & ( n - 1 ) ; } return parity ; } public static void Main ( ) { int n = 7 ; Console . Write ( \\\" Parity \u2581 of \u2581 no \u2581 \\\" + n + \\\" \u2581 = \u2581 \\\" + ( getParity ( n ) ? \\\" odd \\\" : \\\" even \\\" ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Print all possible combinations of r elements in a given array of size n | Program to print all combination of size r in an array of size n ; The main function that prints all combinations of size r in arr [ ] of size n . This function mainly uses combinationUtil ( ) ; A temporary array to store all combination one by one ; Print all combination using temprary array ' data [ ] ' ; arr [ ] -- -> Input Array n -- -> Size of input array r -- -> Size of a combination to be printed index -- -> Current index in data [ ] data [ ] -- -> Temporary array to store current combination i -- -> index of current element in arr [ ] ; Current cobination is ready , print it ; When no more elements are there to put in data [ ] ; current is included , put next at next location ; current is excluded , replace it with next ( Note that i + 1 is passed , but index is not changed ) ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\nvoid combinationUtil ( int arr [ ] , int n , int r , int index , int data [ ] , int i ) ; void printCombination ( int arr [ ] , int n , int r ) { int data [ r ] ; combinationUtil ( arr , n , r , 0 , data , 0 ) ; } void combinationUtil ( int arr [ ] , int n , int r , int index , int data [ ] , int i ) { if ( index == r ) { for ( int j = 0 ; j < r ; j ++ ) printf ( \\\" % d \u2581 \\\" , data [ j ] ) ; printf ( \\\" \\n \\\" ) ; return ; } if ( i >= n ) return ; data [ index ] = arr [ i ] ; combinationUtil ( arr , n , r , index + 1 , data , i + 1 ) ; combinationUtil ( arr , n , r , index , data , i + 1 ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int r = 3 ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printCombination ( arr , n , r ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Smallest index in given range of indices which is not equal to X | C # program to find the smallest index in the array in the range [ L , R ] which does not contain X ; Precompute the index of next different element in the array for every array element ; Default value ; Compute nextpos [ i ] using nextpos [ i + 1 ] ; Function to return the smallest index ; nextpos [ i ] will store the next position p where arr [ p ] != arr [ i ] ; If X is not present at l ; Otherwise ; Find the index which stores a value different from X ; If that index is within the range ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void precompute ( int [ ] nextpos , int [ ] arr , int N ) { nextpos [ N - 1 ] = N ; for ( int i = N - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] == arr [ i + 1 ] ) nextpos [ i ] = nextpos [ i + 1 ] ; else nextpos [ i ] = i + 1 ; } } static void findIndex ( int [ , ] query , int [ ] arr , int N , int Q ) { int [ ] nextpos = new int [ N ] ; precompute ( nextpos , arr , N ) ; for ( int i = 0 ; i < Q ; i ++ ) { int l , r , x ; l = query [ i , 0 ] ; r = query [ i , 1 ] ; x = query [ i , 2 ] ; int ans = - 1 ; if ( arr [ l ] != x ) ans = l ; else { int d = nextpos [ l ] ; if ( d <= r ) ans = d ; } Console . Write ( ans + \\\" \\n \\\" ) ; } } public static void Main ( String [ ] args ) { int N , Q ; N = 6 ; Q = 3 ; int [ ] arr = { 1 , 2 , 1 , 1 , 3 , 5 } ; int [ , ] query = { { 0 , 3 , 1 } , { 1 , 5 , 2 } , { 2 , 3 , 1 } } ; findIndex ( query , arr , N , Q ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimum and maximum number of digits required to be removed to make a given number divisible by 3 | Java program for the above approach ; Function to find the maximum and minimum number of digits to be removed to make str divisible by 3 ; Convert the string into array of digits ; Count of 0 s , 1 s , and 2 s ; Traverse the array ; Find the sum of digits % 3 ; Cases to find minimum number of digits to be removed ; Cases to find maximum number of digits to be removed ; Driver code ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static void minMaxDigits ( String str , int N ) { int arr [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) arr [ i ] = ( str . charAt ( i ) - '0' ) % 3 ; int zero = 0 , one = 0 , two = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) zero ++ ; if ( arr [ i ] == 1 ) one ++ ; if ( arr [ i ] == 2 ) two ++ ; } int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum = ( sum + arr [ i ] ) % 3 ; } if ( sum == 0 ) { System . out . print ( 0 + \\\" \u2581 \\\" ) ; } if ( sum == 1 ) { if ( ( one != 0 ) && ( N > 1 ) ) System . out . print ( 1 + \\\" \u2581 \\\" ) ; else if ( two > 1 && N > 2 ) System . out . print ( 2 + \\\" \u2581 \\\" ) ; else System . out . print ( - 1 + \\\" \u2581 \\\" ) ; } if ( sum == 2 ) { if ( two != 0 && N > 1 ) System . out . print ( 1 + \\\" \u2581 \\\" ) ; else if ( one > 1 && N > 2 ) System . out . print ( 2 + \\\" \u2581 \\\" ) ; else System . out . print ( - 1 + \\\" \u2581 \\\" ) ; } if ( zero > 0 ) System . out . print ( N - 1 + \\\" \u2581 \\\" ) ; else if ( one > 0 && two > 0 ) System . out . print ( N - 2 + \\\" \u2581 \\\" ) ; else if ( one > 2 two > 2 ) System . out . print ( N - 3 + \\\" \u2581 \\\" ) ; else System . out . print ( - 1 + \\\" \u2581 \\\" ) ; } public static void main ( String [ ] args ) { String str = \\\"12345\\\" ; int N = str . length ( ) ; minMaxDigits ( str , N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximum number of times str1 appears as a non | Javascript implementation of the approach ; Function to return the maximum number of times str1 can appear as a non - overlapping substring in str2 ; str1 cannot never be substring of str2 ; Store the frequency of the characters of str1 ; Store the frequency of the characters of str2 ; To store the required count of substrings ; Current character doesn 't appear in str1 ; Frequency of the current character in str1 is greater than its frequency in str2 ; Update the count of possible substrings ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"const MAX = 26 ; function maxSubStr ( str1 , len1 , str2 , len2 ) { if ( len1 > len2 ) return 0 ; let freq1 = new Array ( MAX ) . fill ( 0 ) ; for ( let i = 0 ; i < len1 ; i ++ ) freq1 [ str1 . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ] ++ ; let freq2 = new Array ( MAX ) . fill ( 0 ) ; for ( let i = 0 ; i < len2 ; i ++ ) freq2 [ str2 . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ] ++ ; let minPoss = Number . MAX_SAFE_INTEGER ; for ( let i = 0 ; i < MAX ; i ++ ) { if ( freq1 [ i ] == 0 ) continue ; if ( freq1 [ i ] > freq2 [ i ] ) return 0 ; minPoss = Math . min ( minPoss , Math . floor ( freq2 [ i ] \\/ freq1 [ i ] ) ) ; } return minPoss ; } let str1 = \\\" \\\" , str2 = \\\" \\\" ; let len1 = str1 . length ; let len2 = str2 . length ; document . write ( maxSubStr ( str1 , len1 , str2 , len2 ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Gold Mine Problem | C # program to solve Gold Mine problem ; Returns maximum amount of gold that can be collected when journey started from first column and moves allowed are right , right - up and right - down ; Create a table for storing intermediate results and initialize all cells to 0. The first row of goldMineTable gives the maximum gold that the miner can collect when starts that row ; Gold collected on going to the cell on the right ( -> ) ; Gold collected on going to the cell to right up ( \\/ ) ; Gold collected on going to the cell to right down ( \\\\ ) ; Max gold collected from taking either of the above 3 paths ; The max amount of gold collected will be the max value in first column of all rows ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int MAX = 100 ; static int getMaxGold ( int [ , ] gold , int m , int n ) { int [ , ] goldTable = new int [ m , n ] ; for ( int i = 0 ; i < m ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) goldTable [ i , j ] = 0 ; for ( int col = n - 1 ; col >= 0 ; col -- ) { for ( int row = 0 ; row < m ; row ++ ) { int right = ( col == n - 1 ) ? 0 : goldTable [ row , col + 1 ] ; int right_up = ( row == 0 col == n - 1 ) ? 0 : goldTable [ row - 1 , col + 1 ] ; int right_down = ( row == m - 1 col == n - 1 ) ? 0 : goldTable [ row + 1 , col + 1 ] ; goldTable [ row , col ] = gold [ row , col ] + Math . Max ( right , Math . Max ( right_up , right_down ) ) ; } } int res = goldTable [ 0 , 0 ] ; for ( int i = 1 ; i < m ; i ++ ) res = Math . Max ( res , goldTable [ i , 0 ] ) ; return res ; } static void Main ( ) { int [ , ] gold = new int [ , ] { { 1 , 3 , 1 , 5 } , { 2 , 2 , 4 , 1 } , { 5 , 0 , 2 , 3 } , { 0 , 6 , 1 , 2 } } ; int m = 4 , n = 4 ; Console . Write ( getMaxGold ( gold , m , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"N | Function to return the decimal value of a binary number ; Initializing base value to 1 , i . e 2 ^ 0 ; find the binary representation of the N - th number in sequence ; base case ; answer string ; add n - 1 1 's ; add 0 ; add n 1 's at end ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function binaryToDecimal ( n ) { let num = n ; let dec_value = 0 ; let base = 1 ; let len = num . length ; for ( let i = len - 1 ; i >= 0 ; i -- ) { if ( num [ i ] == ' ' ) dec_value += base ; base = base * 2 ; } return dec_value ; } function numberSequence ( n ) { if ( n == 1 ) return 1 ; let s = \\\" \\\" ; for ( let i = 1 ; i < n ; i ++ ) s += ' ' ; s += ' ' ; for ( let i = 1 ; i <= n ; i ++ ) s += ' ' ; let num = binaryToDecimal ( s ) ; return num ; } let n = 4 ; document . write ( numberSequence ( n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find profession in a special family | Returns ' e ' if profession of node at given level and position is engineer . Else doctor . The function assumes that given position and level have valid values . ; Base case ; Recursively find parent 's profession. If parent is a Doctor, this node will be a Doctor if it is at odd position and an engineer if at even position ; If parent is an engineer , then current node will be an engineer if at add position and doctor if even position . ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def findProffesion ( level , pos ) :\\n\\tif ( level == 1 ) :\\n\\t\\treturn ' e '\\n\\tif ( findProffesion ( level - 1 , ( pos + 1 ) \\/\\/ 2 ) == ' d ' ) :\\n\\t\\tif ( pos % 2 ) :\\n\\t\\t\\treturn ' d '\\n\\t\\telse :\\n\\t\\t\\treturn ' e '\\n\\tif ( pos % 2 ) :\\n\\t\\treturn ' e '\\n\\telse :\\n\\t\\treturn ' d '\\nif __name__ == ' _ _ main _ _ ' :\\n\\tlevel = 3\\n\\tpos = 4\\n\\tif ( findProffesion ( level , pos ) == ' e ' ) :\\n\\t\\tprint ( \\\" Engineer \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" Doctor \\\" )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimum flips required to generate continuous substrings of 0 \u00e2 \u20ac\u2122 s and 1 \u00e2 \u20ac\u2122 s | Python3 implementation of the above approach ; Traverse input string and store the count of 0 ; Traverse the input string again to find minimum number of flips ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def minChanges ( str , N ) :\\n\\tcount0 = 0\\n\\tcount1 = 0\\n\\tfor x in str :\\n\\t\\tcount0 += ( x == '0' )\\n\\tres = count0\\n\\tfor x in str :\\n\\t\\tcount0 -= ( x == '0' )\\n\\t\\tcount1 += ( x == '1' )\\n\\t\\tres = min ( res , count1 + count0 )\\n\\treturn res\\nN = 9\\nstr = \\\"000101001\\\"\\nprint ( minChanges ( str , N ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimum insertions to form a palindrome | DP | A Naive recursive program to find minimum number insertions needed to make a string palindrome ; A utility function to find minimum of two numbers ; Recursive function to find minimum number of insertions ; Base Cases ; Check if the first and last characters are same . On the basis of the comparison result , decide which subrpoblem ( s ) to call ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\n#include \\nint min ( int a , int b ) { return a < b ? a : b ; } int findMinInsertions ( char str [ ] , int l , int h ) { if ( l > h ) return INT_MAX ; if ( l == h ) return 0 ; if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ; return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ; } int main ( ) { char str [ ] = \\\" geeks \\\" ; printf ( \\\" % d \\\" , findMinInsertions ( str , 0 , strlen ( str ) - 1 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum steps required to reach the end of a matrix | Set 2 | C # implementation of the approach ; Function to return the minimum steps required to reach the end of the matrix ; Array to determine whether a cell has been visited before ; Queue for bfs ; Initializing queue ; To store the depth of search ; BFS algorithm ; Current queue size ; Top - most element of queue ; To store index of cell for simplicity ; Base case ; If we reach ( n - 1 , n - 1 ) ; Marking the cell visited ; Pushing the adjacent cells in the queue that can be visited from the current cell ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int n = 3 ; public class Pair { public int first , second ; public Pair ( int a , int b ) { first = a ; second = b ; } } static int minSteps ( int [ , ] arr ) { Boolean [ , ] v = new Boolean [ n , n ] ; Queue < Pair > q = new Queue < Pair > ( ) ; q . Enqueue ( new Pair ( 0 , 0 ) ) ; int depth = 0 ; while ( q . Count != 0 ) { int x = q . Count ; while ( x -- > 0 ) { Pair y = q . Peek ( ) ; int i = y . first , j = y . second ; q . Dequeue ( ) ; if ( v [ i , j ] ) continue ; if ( i == n - 1 && j == n - 1 ) return depth ; v [ i , j ] = true ; if ( i + arr [ i , j ] < n ) q . Enqueue ( new Pair ( i + arr [ i , j ] , j ) ) ; if ( j + arr [ i , j ] < n ) q . Enqueue ( new Pair ( i , j + arr [ i , j ] ) ) ; } depth ++ ; } return - 1 ; } public static void Main ( ) { int [ , ] arr = { { 1 , 1 , 1 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ; Console . WriteLine ( minSteps ( arr ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"K | C # program for the above approach ; Function to find the kth digit from last in an integer n ; If k is less than equal to 0 ; Convert integer into string ; If k is greater than length of the string temp ; Print the k digit from last ; Driver code ; Given Input ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void kthDigitFromLast ( int n , int k ) { if ( k <= 0 ) { Console . Write ( - 1 ) ; return ; } string temp = n . ToString ( ) ; if ( k > temp . Length ) { Console . WriteLine ( - 1 ) ; } else { Console . Write ( temp [ temp . Length - k ] - 48 ) ; } } public static void Main ( ) { int n = 2354 ; int k = 2 ; kthDigitFromLast ( n , k ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Square root of an integer | Returns floor of square root of x ; Base cases ; Do Binary Search for floor ( sqrt ( x ) ) ; If x is a perfect square ; Since we need floor , we update answer when mid * mid is smaller than x , and move closer to sqrt ( x ) ; If mid * mid is greater than x ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function floorSqrt ( $ x ) { if ( $ x == 0 $ x == 1 ) return $ x ; $ start = 1 ; $ end = $ x ; $ ans ; while ( $ start <= $ end ) { $ mid = ( $ start + $ end ) \\/ 2 ; if ( $ mid * $ mid == $ x ) return $ mid ; if ( $ mid * $ mid < $ x ) { $ start = $ mid + 1 ; $ ans = $ mid ; } else $ end = $ mid - 1 ; } return $ ans ; } $ x = 11 ; echo floorSqrt ( $ x ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximum number of pair reductions possible on a given triplet | Java program for the above approach ; Function to count the maximum number of pair reductions possible on a given triplet ; Convert them into an array ; Stores count of operations ; Sort the array ; If the first two array elements reduce to 0 ; Apply the operations ; Increment count ; Print the maximum count ; Driver Code ; Given triplet\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static void maxOps ( int a , int b , int c ) { int arr [ ] = { a , b , c } ; int count = 0 ; while ( 1 != 0 ) { Arrays . sort ( arr ) ; if ( arr [ 0 ] == 0 && arr [ 1 ] == 0 ) break ; arr [ 1 ] -= 1 ; arr [ 2 ] -= 1 ; count += 1 ; } System . out . print ( count ) ; } public static void main ( String [ ] args ) { int a = 4 , b = 3 , c = 2 ; maxOps ( a , b , c ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Print the string after the specified character has occurred given no . of times | C # program for above implementation ; Method to print the string ; If given count is 0 print the given string and return ; Start traversing the string ; Increment occ if current char is equal to given character ; Break the loop if given character has been occurred given no . of times ; Print the string after the occurrence of given character given no . of times ; Otherwise string is empty ; Driver Method\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; public class GFG { static public void printString ( string str , char ch , int count ) { int occ = 0 , i ; if ( count == 0 ) { Console . WriteLine ( str ) ; return ; } for ( i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == ch ) occ ++ ; if ( occ == count ) break ; } if ( i < str . Length - 1 ) Console . WriteLine ( str . Substring ( i + 1 ) ) ; else Console . WriteLine ( \\\" Empty \u2581 string \\\" ) ; } static public void Main ( ) { string str = \\\" geeks \u2581 for \u2581 geeks \\\" ; printString ( str , ' e ' , 2 ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Highest power of 2 less than or equal to given number | C ++ program to find highest power of 2 smaller than or equal to n . ; If i is a power of 2 ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int highestPowerof2 ( int n ) { int res = 0 ; for ( int i = n ; i >= 1 ; i -- ) { if ( ( i & ( i - 1 ) ) == 0 ) { res = i ; break ; } } return res ; } int main ( ) { int n = 10 ; cout << highestPowerof2 ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Unique element in an array where all elements occur K times except one | Set 2 | Function to find single occurrence element ; By shifting 1 to left ith time and taking and with 1 will give us that ith bit of a [ j ] is 1 or 0 ; Taking modulo of p with k ; Generate result ; Loop for negative numbers ; Check if the calculated value res is present in array , then mark c = 1 and if c = 1 return res else res must be - ve ; Driver code ; Function call\\\"\\nSolution in Javascript:\",\"targets\":\"function findunique ( a , k ) { var res = 0 ; for ( var i = 0 ; i < 32 ; i ++ ) { var p = 0 ; for ( var j = 0 ; j < a . length ; j ++ ) { p += ( Math . abs ( a [ j ] ) & ( 1 << i ) ) != 0 ? 1 : 0 ; } p %= k ; res += Math . pow ( 2 , i ) * p ; } var c = 0 ; for ( var i = 0 ; i < a . length ; i ++ ) if ( a [ i ] == res ) { c = 1 ; break ; } return c == 1 ? res : - res ; } var a = [ 12 , 12 , 2 , 2 , 3 ] ; var k = 2 ; document . write ( findunique ( a , k ) + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if a large number is divisible by 3 or not | Function to find that number divisible by 3 or not ; Compute sum of digits ; Check if sum of digits is divisible by 3. ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function check ( str ) { let n = str . length ; let digitSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) digitSum += ( str [ i ] - ' ' ) ; return ( digitSum % 3 == 0 ) ; } let str = \\\" \\\" ; let x = check ( str ) ? \\\" \\\" : \\\" \\\" ; document . write ( x ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximize Sum possible by subtracting same value from all elements of a Subarray of the given Array | Function to find the maximum sum by subtracting same value from all elements of a Subarray ; Stores previous smaller element ; Stores next smaller element ; Calculate contribution of each element ; Return answer ; Function to generate previous smaller element for each array element ; The first element has no previous smaller ; Stack to keep track of elements that have occurred previously ; Push the first index ; Pop all the elements until the previous element is smaller than current element ; Store the previous smaller element ; Push the index of the current element ; Return the array ; Function to generate next smaller element for each array element ; Stack to keep track of elements that have occurring next ; Iterate in reverse order for calculating next smaller ; Pop all the elements until the next element is smaller than current element ; Store the next smaller element ; Push the index of the current element ; Return the array ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function findMaximumSum ( a , n ) { var prev_smaller = findPrevious ( a , n ) ; var next_smaller = findNext ( a , n ) ; var max_value = 0 ; for ( var i = 0 ; i < n ; i ++ ) { max_value = Math . max ( max_value , a [ i ] * ( next_smaller [ i ] - prev_smaller [ i ] - 1 ) ) ; } return max_value ; } function findPrevious ( a , n ) { var ps = Array ( n ) . fill ( 0 ) ; ps [ 0 ] = - 1 ; let stack = Array ( ) ; stack . push ( 0 ) ; for ( var i = 1 ; i < a . length ; i ++ ) { while ( stack . length > 0 && a [ stack [ stack . length - 1 ] ] >= a [ i ] ) stack . pop ( ) ; ps [ i ] = stack . length > 0 ? stack [ stack . length - 1 ] : - 1 ; stack . push ( i ) ; } return ps ; } function findNext ( a , n ) { var ns = Array ( n ) . fill ( 0 ) ; ns [ n - 1 ] = n ; var stack = Array ( ) ; stack . push ( n - 1 ) ; for ( var i = n - 2 ; i >= 0 ; i -- ) { while ( stack . length > 0 && a [ stack [ stack . length - 1 ] ] >= a [ i ] ) stack . pop ( ) ; ns [ i ] = stack . length > 0 ? stack [ stack . length - 1 ] : a . length ; stack . push ( i ) ; } return ns ; } var n = 3 ; var a = [ 80 , 48 , 82 ] ; document . write ( findMaximumSum ( a , n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count integers up to N which can be represented as sum of two or more consecutive numbers | Function to count integers in the range [ 1 , N ] that can be expressed as sum of 2 or more consecutive numbers ; Count powers of 2 up to N ; Increment count ; Update current power of 2 ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function countElements ( N ) { var Cur_Ele = 1 ; var Count = 0 ; while ( Cur_Ele <= N ) { Count ++ ; Cur_Ele = Cur_Ele * 2 ; } document . write ( N - Count ) ; } var N = 15 ; countElements ( N ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Selection Sort | C program for implementation of selection sort ; swap function ; sort function ; One by one move boundary of unsorted subarray ; Find the minimum element in unsorted array ; Swap the found minimum element with the first element ; Function to print an array ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\nvoid swap ( int * xp , int * yp ) { int temp = * xp ; * xp = * yp ; * yp = temp ; } void selectionSort ( int arr [ ] , int n ) { int i , j , min_idx ; for ( i = 0 ; i < n - 1 ; i ++ ) { min_idx = i ; for ( j = i + 1 ; j < n ; j ++ ) if ( arr [ j ] < arr [ min_idx ] ) min_idx = j ; swap ( & arr [ min_idx ] , & arr [ i ] ) ; } } void printArray ( int arr [ ] , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) printf ( \\\" % d \u2581 \\\" , arr [ i ] ) ; printf ( \\\" \\n \\\" ) ; } int main ( ) { int arr [ ] = { 64 , 25 , 12 , 22 , 11 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; selectionSort ( arr , n ) ; printf ( \\\" Sorted \u2581 array : \u2581 \\n \\\" ) ; printArray ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Sum of the multiples of two numbers below N | C program for above approach ; Function to return the sum of all the integers below N which are multiples of either A or B ; If i is a multiple of a or b ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint findSum ( int n , int a , int b ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( i % a == 0 i % b == 0 ) sum += i ; return sum ; } int main ( ) { int n = 10 , a = 3 , b = 5 ; printf ( \\\" % d \\\" , findSum ( n , a , b ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Length of the Longest Consecutive 1 s in Binary Representation | Function to find length of the longest consecutive 1 s in binary representation of a number ; Initialize result ; Count the number of iterations to reach x = 0. ; This operation reduces length of every sequence of 1 s by one . ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function maxConsecutiveOnes ( $ x ) { $ count = 0 ; while ( $ x != 0 ) { $ x = ( $ x & ( $ x << 1 ) ) ; $ count ++ ; } return $ count ; } echo maxConsecutiveOnes ( 14 ) , \\\" \\n \\\" ; echo maxConsecutiveOnes ( 222 ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Biggest Square that can be inscribed within an Equilateral triangle | Function to find the side of the square ; the side cannot be negative ; side of the square ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function square ( $ a ) { if ( $ a < 0 ) return -1 ; $ x = 0.464 * $ a ; return $ x ; } $ a = 5 ; echo square ( $ a ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count the number of primes in the prefix sum array of the given array | Java implementation of the approach ; returns the max element ; Function to return the count of primes in the given array ; Find maximum value in the array ; USE SIEVE TO FIND ALL PRIME NUMBERS LESS THAN OR EQUAL TO max_val Create a boolean array \\\" prime [ 0 . . n ] \\\" . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; Remaining part of SIEVE ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Find all primes in arr [ ] ; Function to generate the prefix array ; Fill the prefix array ; Driver code ; Prefix array of arr [ ] ; Count of primes in the prefix array\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static int max_element ( int a [ ] ) { int m = a [ 0 ] ; for ( int i = 0 ; i < a . length ; i ++ ) m = Math . max ( a [ i ] , m ) ; return m ; } static int primeCount ( int arr [ ] , int n ) { int max_val = max_element ( arr ) ; boolean prime [ ] = new boolean [ max_val + 1 ] ; for ( int p = 0 ; p <= max_val ; p ++ ) prime [ p ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( prime [ arr [ i ] ] ) count ++ ; return count ; } static int [ ] getPrefixArray ( int arr [ ] , int n , int pre [ ] ) { pre [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { pre [ i ] = pre [ i - 1 ] + arr [ i ] ; } return pre ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 4 , 8 , 4 } ; int n = arr . length ; int pre [ ] = new int [ n ] ; pre = getPrefixArray ( arr , n , pre ) ; System . out . println ( primeCount ( pre , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Mean of array generated by products of all pairs of the given array | C # program for the above approach ; Function to find the mean of pair product array of arr [ ] ; Initializing suffix sum array ; Build suffix sum array ; Size of pairProductArray ; Stores sum of pairProductArray ; Store the mean ; Find mean of pairProductArray ; Return the resultant mean ; Driver code ; Given array arr [ ] ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static double pairProductMean ( int [ ] arr , int N ) { int [ ] suffixSumArray = new int [ N ] ; suffixSumArray [ N - 1 ] = arr [ N - 1 ] ; for ( int i = N - 2 ; i >= 0 ; i -- ) { suffixSumArray [ i ] = suffixSumArray [ i + 1 ] + arr [ i ] ; } int length = ( N * ( N - 1 ) ) \\/ 2 ; double res = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { res += arr [ i ] * suffixSumArray [ i + 1 ] ; } double mean ; if ( length != 0 ) mean = res \\/ length ; else mean = 0 ; return mean ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 4 , 8 } ; int N = arr . Length ; Console . WriteLine ( string . Format ( \\\" { 0:0.00 } \\\" , pairProductMean ( arr , N ) ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Longest substring with K unique characters using Binary Search | Function that returns True if there is a sub of length len with <= k unique characters ; Size of the ; Map to store the characters and their frequency ; Update the map for the first sub ; Check for the rest of the subs ; Add the new character ; Remove the first character of the previous window ; Update the map ; Function to return the length of the longest sub which has K unique characters ; Check if the complete contains K unique characters ; Size of the ; Apply binary search ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def isValidLen ( s , lenn , k ) :\\n\\tn = len ( s )\\n\\tmp = dict ( )\\n\\tright = 0\\n\\twhile ( right < lenn ) :\\n\\t\\tmp [ s [ right ] ] = mp . get ( s [ right ] , 0 ) + 1\\n\\t\\tright += 1\\n\\tif ( len ( mp ) <= k ) :\\n\\t\\treturn True\\n\\twhile ( right < n ) :\\n\\t\\tmp [ s [ right ] ] = mp . get ( s [ right ] , 0 ) + 1\\n\\t\\tmp [ s [ right - lenn ] ] -= 1\\n\\t\\tif ( mp [ s [ right - lenn ] ] == 0 ) :\\n\\t\\t\\tdel mp [ s [ right - lenn ] ]\\n\\t\\tif ( len ( mp ) <= k ) :\\n\\t\\t\\treturn True\\n\\t\\tright += 1\\n\\treturn len ( mp ) <= k\\ndef maxLenSubStr ( s , k ) :\\n\\tuni = dict ( )\\n\\tfor x in s :\\n\\t\\tuni [ x ] = 1\\n\\tif ( len ( uni ) < k ) :\\n\\t\\treturn - 1\\n\\tn = len ( s )\\n\\tlo = - 1\\n\\thi = n + 1\\n\\twhile ( hi - lo > 1 ) :\\n\\t\\tmid = lo + hi >> 1\\n\\t\\tif ( isValidLen ( s , mid , k ) ) :\\n\\t\\t\\tlo = mid\\n\\t\\telse :\\n\\t\\t\\thi = mid\\n\\treturn lo\\ns = \\\" aabacbebebe \\\"\\nk = 3\\nprint ( maxLenSubStr ( s , k ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Generate number with given operation and check if it is palindrome | Function that returns true if str is a palindrome ; Function that returns true if the generated string is a palindrome ; sub contains N as a string ; Calculate the sum of the digits ; Repeat the substring until the length of the resultant string < sum ; If length of the resultant string exceeded sum then take substring from 0 to sum - 1 ; If the generated string is a palindrome ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def isPalindrome ( s ) :\\n\\tl = len ( s )\\n\\tfor i in range ( l \\/\\/ 2 ) :\\n\\t\\tif ( s [ i ] != s [ l - 1 - i ] ) :\\n\\t\\t\\treturn False\\n\\treturn True\\ndef createStringAndCheckPalindrome ( N ) :\\n\\tsub = \\\" \\\" + chr ( N )\\n\\tres_str = \\\" \\\"\\n\\tsum = 0\\n\\twhile ( N > 0 ) :\\n\\t\\tdigit = N % 10\\n\\t\\tsum += digit\\n\\t\\tN = N \\/\\/ 10\\n\\twhile ( len ( res_str ) < sum ) :\\n\\t\\tres_str += sub\\n\\tif ( len ( res_str ) > sum ) :\\n\\t\\tres_str = res_str [ 0 : sum ]\\n\\tif ( isPalindrome ( res_str ) ) :\\n\\t\\treturn True\\n\\treturn False\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tN = 10101\\n\\tif ( createStringAndCheckPalindrome ( N ) ) :\\n\\t\\tprint ( \\\" Yes \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Highest power of 2 less than or equal to given number | PHP program to find highest power of 2 smaller than or equal to n . ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function highestPowerof2 ( $ n ) { $ p = ( int ) log ( $ n , 2 ) ; return ( int ) pow ( 2 , $ p ) ; } $ n = 10 ; echo highestPowerof2 ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Probability that the sum of all numbers obtained on throwing a dice N times lies between two given integers | C # program for above approach ; Function to calculate the probability for the given sum to be equal to sum in N throws of dice ; Base cases ; Driver Code ; Calculate probability of all sums from a to b ; Print the answer\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; public class GFG { static float [ , ] dp = new float [ 105 , 605 ] ; static float find ( int N , int sum ) { if ( N < 0 sum < 0 ) return 0 ; if ( dp [ N , sum ] > 0 ) return dp [ N , sum ] ; if ( sum > 6 * N sum < N ) return 0 ; if ( N == 1 ) { if ( sum >= 1 && sum <= 6 ) return ( float ) ( 1.0 \\/ 6 ) ; else return 0 ; } for ( int i = 1 ; i <= 6 ; i ++ ) dp [ N , sum ] = dp [ N , sum ] + find ( N - 1 , sum - i ) \\/ 6 ; return dp [ N , sum ] ; } public static void Main ( String [ ] args ) { int N = 4 , a = 13 , b = 17 ; float probability = 0.0f ; for ( int sum = a ; sum <= b ; sum ++ ) probability = probability + find ( N , sum ) ; Console . Write ( \\\" { 0 : F6 } \\\" , probability ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Intersecting rectangle when bottom | function to find intersection rectangle of given two rectangles . ; gives bottom - left point of intersection rectangle ; gives top - right point of intersection rectangle ; no intersection ; gives top - left point of intersection rectangle ; gives bottom - right point of intersection rectangle ; bottom - left and top - right corners of first rectangle ; bottom - left and top - right corners of first rectangle ; function call\\\"\\nSolution in php:\",\"targets\":\"< ? php function FindPoints ( $ x1 , $ y1 , $ x2 , $ y2 , $ x3 , $ y3 , $ x4 , $ y4 ) { $ x5 = max ( $ x1 , $ x3 ) ; $ y5 = max ( $ y1 , $ y3 ) ; $ x6 = min ( $ x2 , $ x4 ) ; $ y6 = min ( $ y2 , $ y4 ) ; if ( $ x5 > $ x6 $ y5 > $ y6 ) { echo \\\" No \u2581 intersection \\\" ; return ; } echo \\\" ( \\\" . $ x5 . \\\" , \\\" \u2581 . \u2581 $ y5 \u2581 . \u2581 \\\" ) \\\" ; echo \\\" ( \\\" . $ x6 . \\\" , \\\" \u2581 . \u2581 $ y6 \u2581 . \u2581 \\\" ) \\\" ; $ x7 = $ x5 ; $ y7 = $ y6 ; echo \\\" ( \\\" . $ x7 . \\\" , \\\" \u2581 . \u2581 $ y7 \u2581 . \u2581 \\\" ) \\\" ; $ x8 = $ x6 ; $ y8 = $ y5 ; echo \\\" ( \\\" . $ x8 . \\\" , \\\" \u2581 . \u2581 $ y8 \u2581 . \u2581 \\\" ) \\\" ; } $ x1 = 0 ; $ y1 = 0 ; $ x2 = 10 ; $ y2 = 8 ; $ x3 = 2 ; $ y3 = 3 ; $ x4 = 7 ; $ y4 = 9 ; FindPoints ( $ x1 , $ y1 , $ x2 , $ y2 , $ x3 , $ y3 , $ x4 , $ y4 ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximum number of multiples in an array before any element | C # implementation of the approach ; Map to store the divisor count ; Function to generate the divisors of all the array elements ; Function to find the maximum number of multiples in an array before it ; To store the maximum divisor count ; Update ans if more number of divisors are found ; Generating all the divisors of the next element of the array ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int MAX = 100000 ; static int [ ] divisors = new int [ MAX ] ; static void generateDivisors ( int n ) { for ( int i = 1 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n \\/ i == i ) { divisors [ i ] ++ ; } else { divisors [ i ] ++ ; divisors [ n \\/ i ] ++ ; } } } } static int findMaxMultiples ( int [ ] arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans = Math . Max ( divisors [ arr [ i ] ] , ans ) ; generateDivisors ( arr [ i ] ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 8 , 1 , 28 , 4 , 2 , 6 , 7 } ; int n = arr . Length ; Console . Write ( findMaxMultiples ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Given a binary tree , print out all of its root | A binary tree node has data , pointer to left child and a pointer to right child ; Given a binary tree , print out all of its root - to - leaf paths , one per line . Uses a recursive helper to do the work . ; Recursive helper function -- given a node , and an array containing the path from the root node up to but not including this node , print out all the root - leaf paths . ; append this node to the path array ; it 's a leaf, so print the path that led to here ; otherwise try both subtrees ; Utility that prints out an array on a line ; Driver program to test all above functions ; Print all root - to - leaf paths of the input tree\\\"\\nSolution in Java:\",\"targets\":\"class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; void printPaths ( Node node ) { int path [ ] = new int [ 1000 ] ; printPathsRecur ( node , path , 0 ) ; } void printPathsRecur ( Node node , int path [ ] , int pathLen ) { if ( node == null ) return ; path [ pathLen ] = node . data ; pathLen ++ ; if ( node . left == null && node . right == null ) printArray ( path , pathLen ) ; else { printPathsRecur ( node . left , path , pathLen ) ; printPathsRecur ( node . right , path , pathLen ) ; } } void printArray ( int ints [ ] , int len ) { int i ; for ( i = 0 ; i < len ; i ++ ) System . out . print ( ints [ i ] + \\\" \u2581 \\\" ) ; System . out . println ( \\\" \\\" ) ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . printPaths ( tree . root ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check whether frequency of characters in a string makes Fibonacci Sequence | C ++ program to check whether frequency of characters in a string makes Fibonacci Sequence ; Function to check if the frequencies are in Fibonacci series ; map to store the frequencies of character ; Vector to store first n fibonacci numbers ; Get the size of the map ; a and b are first and second terms of fibonacci series ; vector v contains elements of fibonacci series ; Compare vector elements with values in Map ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; string isFibonacci ( string s ) { map < char , int > m ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { m [ s [ i ] ] ++ ; } vector < int > v ; int n = m . size ( ) ; int a = 1 , b = 1 ; int c ; v . push_back ( a ) ; v . push_back ( b ) ; for ( int i = 0 ; i < n - 2 ; i ++ ) { v . push_back ( a + b ) ; c = a + b ; a = b ; b = c ; } int flag = 1 ; int i = 0 ; for ( auto itr = m . begin ( ) ; itr != m . end ( ) ; itr ++ ) { if ( itr -> second != v [ i ] ) { flag = 0 ; break ; } i ++ ; } if ( flag == 1 ) return \\\" YES \\\" ; else return \\\" NO \\\" ; } int main ( ) { string s = \\\" abeeedd \\\" ; cout << isFibonacci ( s ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Average of odd numbers till a given odd number | Program to find average of odd numbers till a given odd number . ; Function to calculate the average of odd numbers ; driver function\\\"\\nSolution in C:\",\"targets\":\"#include \\nint averageOdd ( int n ) { if ( n % 2 == 0 ) { printf ( \\\" Invalid \u2581 Input \\\" ) ; return -1 ; } return ( n + 1 ) \\/ 2 ; } int main ( ) { int n = 15 ; printf ( \\\" % d \\\" , averageOdd ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Egg Dropping Puzzle | DP | ; Function to get minimum number of trials needed in worst case with n eggs and k floors ; If there are no floors , then no trials needed . OR if there is one floor , one trial needed . ; We need k trials for one egg and k floors ; Consider all droppings from 1 st floor to kth floor and return the minimum of these values plus 1. ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int eggDrop ( int n , int k ) { if ( k == 1 k == 0 ) return k ; if ( n == 1 ) return k ; int min = int . MaxValue ; int x , res ; for ( x = 1 ; x <= k ; x ++ ) { res = Math . Max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ; if ( res < min ) min = res ; } return min + 1 ; } static void Main ( ) { int n = 2 , k = 10 ; Console . Write ( \\\" Minimum \u2581 number \u2581 of \u2581 \\\" + \\\" trials \u2581 in \u2581 worst \u2581 case \u2581 with \u2581 \\\" + n + \\\" \u2581 eggs \u2581 and \u2581 \\\" + k + \\\" \u2581 floors \u2581 is \u2581 \\\" + eggDrop ( n , k ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximum Primes whose sum is equal to given N | Function to find max count of primes ; if n is even n \\/ 2 is required answer if n is odd floor ( n \\/ 2 ) = ( int ) ( n \\/ 2 ) is required answer ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def maxPrmimes ( n ) :\\n\\treturn n \\/\\/ 2\\nn = 17\\nprint ( maxPrmimes ( n ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Construct an N | C ++ program to implement the above approach ; Keep track of visited nodes ; Function to construct a tree such that there are no two adjacent nodes with the same weight ; If minimum and maximum elements are equal , i . e . array contains one distinct element ; Tree cannot be constructed ; Otherwise ; Tree can be constructed ; Choose weights [ 0 ] as root ; First Node is visited ; Traverse the array ; Otherwise , make an edge ; Mark this node as visited ; Find a weight not same as the root & make edges with that node ; Join non - roots with remaining nodes ; Check if current node ' s \u2581 weight \u2581 \u2581 is \u2581 same \u2581 as \u2581 root \u2581 node ' s weight and if it is not visited or not ; Driver Code ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; const int N = 1e5 + 5 ; int visited [ N ] ; void construct_tree ( int weights [ ] , int n ) { int minimum = * min_element ( weights , weights + n ) ; int maximum = * max_element ( weights , weights + n ) ; if ( minimum == maximum ) { cout << \\\" No \\\" ; return ; } else { cout << \\\" Yes \\\" << endl ; } int root = weights [ 0 ] ; visited [ 1 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( weights [ i ] != root && visited [ i + 1 ] == 0 ) { cout << 1 << \\\" \u2581 \\\" << i + 1 << \\\" \u2581 \\\" << endl ; visited [ i + 1 ] = 1 ; } } int notroot = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( weights [ i ] != root ) { notroot = i + 1 ; break ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( weights [ i ] == root && visited [ i + 1 ] == 0 ) { cout << notroot << \\\" \u2581 \\\" << i + 1 << endl ; visited [ i + 1 ] = 1 ; } } } int main ( ) { int weights [ ] = { 1 , 2 , 1 , 2 , 5 } ; int N = sizeof ( weights ) \\/ sizeof ( weights [ 0 ] ) ; construct_tree ( weights , N ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Expected Number of Trials to get N Consecutive Heads | Java implementation of the above approach ; Driver Code ; Formula for number of trails for N consecutive heads\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { public static void main ( String [ ] args ) { int N = 3 ; System . out . print ( Math . pow ( 2 , N + 1 ) - 2 ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximize sum by choosing elements from different section of a matrix | Javascript program for the above approach ; Function to find the maximum value ; Dp table ; Fill the dp in bottom up manner ; Maximum of the three sections ; Maximum of the first section ; Maximum of the second section ; Maximum of the third section ; If we choose element from section 1 , we cannot have selection from same section in adjacent rows ; Print the maximum sum ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"const n = 6 , m = 6 ; function maxSum ( arr ) { const dp = new Array ( n + 1 ) . fill ( 0 ) . map ( ( ) => new Array ( 3 ) . fill ( 0 ) ) ; for ( var i = 0 ; i < n ; i ++ ) { var m1 = 0 , m2 = 0 , m3 = 0 ; for ( var j = 0 ; j < m ; j ++ ) { if ( parseInt ( j \\/ ( m \\/ 3 ) ) == 0 ) { m1 = Math . max ( m1 , arr [ i ] [ j ] ) ; } else if ( parseInt ( j \\/ ( m \\/ 3 ) ) == 1 ) { m2 = Math . max ( m2 , arr [ i ] [ j ] ) ; } else if ( parseInt ( j \\/ ( m \\/ 3 ) ) == 2 ) { m3 = Math . max ( m3 , arr [ i ] [ j ] ) ; } } dp [ i + 1 ] [ 0 ] = Math . max ( dp [ i ] [ 1 ] , dp [ i ] [ 2 ] ) + m1 ; dp [ i + 1 ] [ 1 ] = Math . max ( dp [ i ] [ 0 ] , dp [ i ] [ 2 ] ) + m2 ; dp [ i + 1 ] [ 2 ] = Math . max ( dp [ i ] [ 1 ] , dp [ i ] [ 0 ] ) + m3 ; } document . write ( parseInt ( Math . max ( Math . max ( dp [ n ] [ 0 ] , dp [ n ] [ 1 ] ) , dp [ n ] [ 2 ] ) ) + \\\" \\\" ) ; } arr = [ [ 1 , 3 , 5 , 2 , 4 , 6 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 1 , 3 , 5 , 2 , 4 , 6 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 1 , 3 , 5 , 2 , 4 , 6 ] ] ; maxSum ( arr ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"D Numbers | Java implementation for the above approach ; Function to find the N - th icosikaipentagon number ; Number should be greater than 3 ; Check every k in range 2 to n - 1 ; Condition for D - Number ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static boolean isDNum ( int n ) { if ( n < 4 ) return false ; int numerator = 0 , hcf = 0 ; for ( int k = 2 ; k <= n ; k ++ ) { numerator = ( int ) ( Math . pow ( k , n - 2 ) - k ) ; hcf = __gcd ( n , k ) ; } if ( hcf == 1 && ( numerator % n ) != 0 ) return false ; return true ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int n = 15 ; boolean a = isDNum ( n ) ; if ( a ) System . out . print ( \\\" Yes \\\" ) ; else System . out . print ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Write a program to reverse digits of a number | C program to reverse digits of a number ; Recursive function to reverse digits of num ; Driver program to test reversDigits\\\"\\nSolution in C:\",\"targets\":\"#include ; int reversDigits ( int num ) { static int rev_num = 0 ; static int base_pos = 1 ; if ( num > 0 ) { reversDigits ( num \\/ 10 ) ; rev_num += ( num % 10 ) * base_pos ; base_pos *= 10 ; } return rev_num ; } int main ( ) { int num = 4562 ; printf ( \\\" Reverse \u2581 of \u2581 no . \u2581 is \u2581 % d \\\" , reversDigits ( num ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Ternary Search | C program to illustrate iterative approach to ternary search ; Function to perform Ternary Search ; Find the mid1 and mid2 ; Check if key is present at any mid ; Since key is not present at mid , check in which region it is present then repeat the Search operation in that region ; The key lies in between l and mid1 ; The key lies in between mid2 and r ; The key lies in between mid1 and mid2 ; Key not found ; Driver code ; Get the array Sort the array if not sorted ; Starting index ; length of array ; Key to be searched in the array ; Search the key using ternarySearch ; Print the result ; Key to be searched in the array ; Search the key using ternarySearch ; Print the result\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint ternarySearch ( int l , int r , int key , int ar [ ] ) { while ( r >= l ) { int mid1 = l + ( r - l ) \\/ 3 ; int mid2 = r - ( r - l ) \\/ 3 ; if ( ar [ mid1 ] == key ) { return mid1 ; } if ( ar [ mid2 ] == key ) { return mid2 ; } if ( key < ar [ mid1 ] ) { r = mid1 - 1 ; } else if ( key > ar [ mid2 ] ) { l = mid2 + 1 ; } else { l = mid1 + 1 ; r = mid2 - 1 ; } } return -1 ; } int main ( ) { int l , r , p , key ; int ar [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; l = 0 ; r = 9 ; key = 5 ; p = ternarySearch ( l , r , key , ar ) ; printf ( \\\" Index \u2581 of \u2581 % d \u2581 is \u2581 % d \\n \\\" , key , p ) ; key = 50 ; p = ternarySearch ( l , r , key , ar ) ; printf ( \\\" Index \u2581 of \u2581 % d \u2581 is \u2581 % d \\\" , key , p ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of coins to be collected per hour to empty N piles in at most H hours | C ++ program for the above approach ; Function to find the minimum number of coins to be collected per hour to empty N piles in H hours ; Stores the minimum coins to be removed per hour ; Find the maximum array element ; Perform Binary Search ; Store the mid value of the range in K ; Find the total time taken to empty N piles by removing K coins per hour ; If total time does not exceed H ; Otherwise ; Print the required result ; Driver Code ; Function Call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int minCollectingSpeed ( vector < int > & piles , int H ) { int ans = -1 ; int low = 1 , high ; high = * max_element ( piles . begin ( ) , piles . end ( ) ) ; while ( low <= high ) { int K = low + ( high - low ) \\/ 2 ; int time = 0 ; for ( int ai : piles ) { time += ( ai + K - 1 ) \\/ K ; } if ( time <= H ) { ans = K ; high = K - 1 ; } else { low = K + 1 ; } } cout << ans ; } int main ( ) { vector < int > arr = { 3 , 6 , 7 , 11 } ; int H = 8 ; minCollectingSpeed ( arr , H ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the mid | Function to find the midpoint of a line ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def midpoint ( x1 , x2 , y1 , y2 ) :\\n\\tprint ( ( x1 + x2 ) \\/\\/ 2 , \\\" \u2581 , \u2581 \\\" , ( y1 + y2 ) \\/\\/ 2 )\\nx1 , y1 , x2 , y2 = - 1 , 2 , 3 , - 6\\nmidpoint ( x1 , x2 , y1 , y2 )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Convert to number with digits as 3 and 8 only | function for minimum operation ; remainder and operations count ; count digits not equal to 3 or 8 ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function minOp ( $ num ) { $ count = 0 ; while ( $ num ) { $ rem = intval ( $ num % 10 ) ; if ( ! ( $ rem == 3 $ rem == 8 ) ) $ count ++ ; $ num = intval ( $ num \\/ 10 ) ; } return $ count ; } $ num = 234198 ; echo \\\" Minimum \u2581 Operations \u2581 = \u2581 \\\" . minOp ( $ num ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Number of sub | Function to return the count of the required substrings ; To store the final answer ; Loop to find the answer ; Condition to update the answer ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function countSubStr ( str , len ) { var ans = 0 ; for ( var i = 0 ; i < len ; i ++ ) { if ( str [ i ] == ' ' ) ans += ( i + 1 ) ; } return ans ; } var str = \\\" \\\" ; var len = str . length ; document . write ( countSubStr ( str , len ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find n positive integers that satisfy the given equations | C ++ implementation of the approach ; Function to find n positive integers that satisfy the given conditions ; To store n positive integers ; Place N - 1 one 's ; If can not place ( y - ( n - 1 ) ) as the Nth integer ; Place Nth integer ; To store the sum of squares of N integers ; If it is less than x ; Print the required integers ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void findIntegers ( int n , int x , int y ) { vector < int > ans ; for ( int i = 0 ; i < n - 1 ; i ++ ) ans . push_back ( 1 ) ; if ( y - ( n - 1 ) <= 0 ) { cout << \\\" - 1\\\" ; return ; } ans . push_back ( y - ( n - 1 ) ) ; int store = 0 ; for ( int i = 0 ; i < n ; i ++ ) store += ans [ i ] * ans [ i ] ; if ( store < x ) { cout << \\\" - 1\\\" ; return ; } for ( int i = 0 ; i < n ; i ++ ) cout << ans [ i ] << \\\" \u2581 \\\" ; } int main ( ) { int n = 3 , x = 254 , y = 18 ; findIntegers ( n , x , y ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the sum of a Series 1 + 1 \\/ 2 ^ 2 + 1 \\/ 3 ^ 3 + \u00e2 \u20ac\u00a6 . . + 1 \\/ n ^ n | C program to calculate the following series ; Function to calculate the following series ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\ndouble Series ( int n ) { int i ; double sums = 0.0 , ser ; for ( i = 1 ; i <= n ; ++ i ) { ser = 1 \\/ pow ( i , i ) ; sums += ser ; } return sums ; } int main ( ) { int n = 3 ; double res = Series ( n ) ; printf ( \\\" % .5f \\\" , res ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of cycles in a Polygon with lines from Centroid to Vertices | Function to find the Number of Cycles ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def nCycle ( N ) :\\n\\treturn ( N ) * ( N - 1 ) + 1\\nN = 4\\nprint ( nCycle ( N ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Shortest distance from the centre of a circle to a chord | Function to find the shortest distance ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def shortdis ( r , d ) :\\n\\tprint ( \\\" The \u2581 shortest \u2581 distance \u2581 \\\" , end = \\\" \\\" ) ;\\n\\tprint ( \\\" from \u2581 the \u2581 chord \u2581 to \u2581 centre \u2581 \\\" , end = \\\" \\\" ) ;\\n\\tprint ( ( ( r * r ) - ( ( d * d ) \\/ 4 ) ) ** ( 1 \\/ 2 ) ) ;\\nr = 4 ;\\nd = 3 ;\\nshortdis ( r , d ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Logarithm tricks for Competitive Programming | C implementation to check if the number is power of K ; Function to check if the number is power of K ; Logarithm function to calculate value ; Compare to the result1 or result2 both are equal ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\n_Bool isPower ( int N , int K ) { int res1 = log ( N ) \\/ log ( K ) ; double res2 = log ( N ) \\/ log ( K ) ; return ( res1 == res2 ) ; } int main ( ) { int N = 8 ; int K = 2 ; if ( isPower ( N , K ) ) { printf ( \\\" Yes \\\" ) ; } else { printf ( \\\" No \\\" ) ; } return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Reduce a given number to form a key by the given operations | Function to find the key of the given number ; Convert the integer to String ; Iterate the num - string to get the result ; Check if digit is even or odd ; Iterate until odd sum is obtained by adding consecutive digits ; Check if sum becomes odd ; Add the result in ans ; Assign the digit index to num string ; If the number is odd ; Iterate until odd sum is obtained by adding consecutive digits ; Check if sum becomes even ; Add the result in ans ; assign the digit index to main numstring ; Check if all digits are visited or not ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function key ( N ) { let num = \\\" \\\" + N . toString ( ) ; let ans = 0 ; let j = 0 ; for ( j = 0 ; j < num . length ; j ++ ) { if ( ( num [ j ] . charCodeAt ( ) - 48 ) % 2 == 0 ) { let add = 0 ; let i ; for ( i = j ; j < num . length ; j ++ ) { add += num [ j ] . charCodeAt ( ) - 48 ; if ( add % 2 == 1 ) break ; } if ( add == 0 ) { ans *= 10 ; } else { let digit = Math . floor ( Math . log10 ( add ) + 1 ) ; ans *= parseInt ( Math . pow ( 10 , digit ) , 10 ) ; ans += add ; } i = j ; } else { let add = 0 ; let i ; for ( i = j ; j < num . length ; j ++ ) { add += num [ j ] . charCodeAt ( ) - 48 ; if ( add % 2 == 0 ) { break ; } } if ( add == 0 ) { ans *= 10 ; } else { let digit = Math . floor ( Math . log10 ( add ) + 1 ) ; ans *= parseInt ( Math . pow ( 10 , digit ) , 10 ) ; ans += add ; } i = j ; } } if ( j + 1 >= num . length ) { return ans ; } else { return ans += num [ num . length - 1 ] . charCodeAt ( ) - 48 ; } } let N = 1667848271 ; document . write ( key ( N ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find extra element in the second array | Function to return the extra element in B [ ] ; To store the result ; Find the XOR of all the element of array A [ ] and array B [ ] ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function extraElement ( A , B , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) ans ^= A [ i ] ; for ( let i = 0 ; i < n + 1 ; i ++ ) ans ^= B [ i ] ; return ans ; } let A = [ 10 , 15 , 5 ] ; let B = [ 10 , 100 , 15 , 5 ] ; let n = A . length ; document . write ( extraElement ( A , B , n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Radius of the circle when the width and height of an arc is given | Function to find the radius ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function rad ( $ d , $ h ) { echo \\\" The \u2581 radius \u2581 of \u2581 the \u2581 circle \u2581 is \u2581 \\\" , ( ( $ d * $ d ) \\/ ( 8 * $ h ) + $ h \\/ 2 ) , \\\" \\n \\\" ; } $ d = 4 ; $ h = 1 ; rad ( $ d , $ h ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count quadruples from four sorted arrays whose sum is equal to a given value x | C ++ implementation to count quadruples from four sorted arrays whose sum is equal to a given value x ; find the ' value ' in the given array ' arr [ ] ' binary search technique is applied ; ' value ' found ; ' value ' not found ; function to count all quadruples from four sorted arrays whose sum is equal to a given value x ; generate all triplets from the 1 st three arrays ; calculate the sum of elements in the triplet so generated ; check if ' x - T ' is present in 4 th array or not ; increment count ; required count of quadruples ; Driver program to test above ; four sorted arrays each of size ' n '\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool isPresent ( int arr [ ] , int low , int high , int value ) { while ( low <= high ) { int mid = ( low + high ) \\/ 2 ; if ( arr [ mid ] == value ) return true ; else if ( arr [ mid ] > value ) high = mid - 1 ; else low = mid + 1 ; } return false ; } int countQuadruples ( int arr1 [ ] , int arr2 [ ] , int arr3 [ ] , int arr4 [ ] , int n , int x ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) for ( int k = 0 ; k < n ; k ++ ) { int T = arr1 [ i ] + arr2 [ j ] + arr3 [ k ] ; if ( isPresent ( arr4 , 0 , n , x - T ) ) count ++ ; } return count ; } int main ( ) { int arr1 [ ] = { 1 , 4 , 5 , 6 } ; int arr2 [ ] = { 2 , 3 , 7 , 8 } ; int arr3 [ ] = { 1 , 4 , 6 , 10 } ; int arr4 [ ] = { 2 , 4 , 7 , 8 } ; int n = sizeof ( arr1 ) \\/ sizeof ( arr1 [ 0 ] ) ; int x = 30 ; cout << \\\" Count \u2581 = \u2581 \\\" << countQuadruples ( arr1 , arr2 , arr3 , arr4 , n , x ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Given an array arr [ ] , find the maximum j | CPP program for the above approach ; For a given array arr [ ] , returns the maximum j a i such that arr [ j ] > arr [ i ] ; Driver program to test above functions\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int maxIndexDiff ( int arr [ ] , int n ) { int maxDiff = -1 ; int i , j ; for ( i = 0 ; i < n ; ++ i ) { for ( j = n - 1 ; j > i ; -- j ) { if ( arr [ j ] > arr [ i ] && maxDiff < ( j - i ) ) maxDiff = j - i ; } } return maxDiff ; } int main ( ) { int arr [ ] = { 9 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 18 , 0 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int maxDiff = maxIndexDiff ( arr , n ) ; cout << \\\" \\n \\\" << maxDiff ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimum cost to merge all elements of List | Java implementation of the approach ; To store the states of DP ; Function to return the minimum merge cost ; Base case ; If the state has been solved before ; Marking the state as solved ; Reference to dp [ i ] [ j ] ; To store the sum of all the elements in the subarray arr [ i ... j ] ; Loop to iterate the recurrence ; Returning the solved value ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static final int N = 401 ; static int [ ] [ ] dp = new int [ N ] [ N ] ; static boolean [ ] [ ] v = new boolean [ N ] [ N ] ; static int minMergeCost ( int i , int j , int [ ] arr ) { if ( i == j ) return 0 ; if ( v [ i ] [ j ] ) return dp [ i ] [ j ] ; v [ i ] [ j ] = true ; int x = dp [ i ] [ j ] ; x = Integer . MAX_VALUE ; int tot = 0 ; for ( int k = i ; k <= j ; k ++ ) tot += arr [ k ] ; for ( int k = i + 1 ; k <= j ; k ++ ) { x = Math . min ( x , tot + minMergeCost ( i , k - 1 , arr ) + minMergeCost ( k , j , arr ) ) ; } return x ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 7 } ; int n = arr . length ; System . out . print ( minMergeCost ( 0 , n - 1 , arr ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Rearrange array such that sum of same indexed elements is atmost K | Java program for the above approach ; Reverse array ; Function to rearrange array such that sum of similar indexed elements does not exceed K ; Sort the array B [ ] in descending order ; If condition fails ; Print the array ; Driver Code ; Given arrays\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static int [ ] reverse ( int a [ ] ) { int i , n = a . length , t ; for ( i = 0 ; i < n \\/ 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } static void rearrangeArray ( int A [ ] , int B [ ] , int N , int K ) { Arrays . sort ( B ) ; B = reverse ( B ) ; boolean flag = true ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] + B [ i ] > K ) { flag = false ; break ; } } if ( ! flag ) { System . out . print ( \\\" - 1\\\" + \\\"\\n\\\"); } else { for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( B [ i ] + \\\" \u2581 \\\" ) ; } } } public static void main ( String [ ] args ) { int A [ ] = { 1 , 2 , 3 , 4 , 2 } ; int B [ ] = { 1 , 2 , 3 , 1 , 1 } ; int N = A . length ; int K = 5 ; rearrangeArray ( A , B , N , K ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Calculate 7 n \\/ 8 without using division and multiplication operators | C program to evaluate 7 n \\/ 8 without using * and \\/ ; Step 1 ) First multiply number by 7 i . e . 7 n = ( n << 3 ) - n * Step 2 ) Divide result by 8 ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint multiplyBySevenByEight ( unsigned int n ) { return ( ( n << 3 ) - n ) >> 3 ; } int main ( ) { unsigned int n = 15 ; printf ( \\\" % u \\\" , multiplyBySevenByEight ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of triangles formed from a set of points on three lines | Returns factorial of a number ; calculate c ( n , r ) ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def factorial ( n ) :\\n\\tfact = 1\\n\\tfor i in range ( 2 , n + 1 ) :\\n\\t\\tfact = fact * i\\n\\treturn fact\\ndef ncr ( n , r ) :\\n\\treturn ( factorial ( n ) \\/\\/ ( factorial ( r ) * factorial ( n - r ) ) )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tm = 3\\n\\tn = 4\\n\\tk = 5\\n\\ttotalTriangles = ( ncr ( m + n + k , 3 ) - ncr ( m , 3 ) - ncr ( n , 3 ) - ncr ( k , 3 ) )\\n\\tprint ( totalTriangles )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Maximize minimum distance between repetitions from any permutation of the given Array | Javascript Program to implement the above approach ; Size of the array ; Stores the frequency of array elements ; Find the highest frequency in the array ; Increase count of max frequent element ; If no repetition is present ; Find the maximum distance ; Return the max distance ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function findMaxLen ( a ) { var n = a . length ; var freq = Array ( n + 1 ) . fill ( 0 ) ; var i ; for ( i = 0 ; i < n ; ++ i ) { freq [ a [ i ] ] ++ ; } var maxFreqElement = - 2147483648 ; var maxFreqCount = 1 ; for ( i = 1 ; i <= n ; ++ i ) { if ( freq [ i ] > maxFreqElement ) { maxFreqElement = freq [ i ] ; maxFreqCount = 1 ; } else if ( freq [ i ] == maxFreqElement ) maxFreqCount ++ ; } var ans ; if ( maxFreqElement == 1 ) ans = 0 ; else { ans = ( ( n - maxFreqCount ) \\/ ( maxFreqElement - 1 ) ) ; } return ans ; } var a = [ 1 , 2 , 1 , 2 ] ; document . write ( findMaxLen ( a ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find ( a ^ b ) % m where ' b ' is very large | Function to find power ; Update x if it is more than or equal to p ; If y is odd , multiply x with the result ; y must be even now y = y >> 1 y = y \\/ 2 ; Driver Code ; String input as b is very large ; Reduce the number B to a small number using Fermat Little\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def power ( x , y , p ) :\\n\\tx = x % p\\n\\twhile ( y > 0 ) :\\n\\t\\tif ( y & 1 ) :\\n\\t\\t\\tres = ( res * x ) % p\\n\\t\\tx = ( x * x ) % p\\n\\treturn res\\na = 3\\nb = \\\"100000000000000000000000000\\\"\\nremainderB = 0\\nMOD = 1000000007\\nfor i in range ( len ( b ) ) :\\n\\tremainderB = ( ( remainderB * 10 + ord ( b [ i ] ) - 48 ) % ( MOD - 1 ) )\\nprint ( power ( a , remainderB , MOD ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sentence Case of a given Camel cased string | Function to return the original string after converting it back from camelCase ; Print the first character as it is ; Traverse the rest of the characters one by one ; If current character is uppercase print space followed by the current character in lowercase ; Else print the current character ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function getOrgString ( s ) { document . write ( s [ 0 ] ) ; var i = 1 ; while ( i < s . length ) { if ( s [ i ] . charCodeAt ( 0 ) >= \\\" \\\" . charCodeAt ( 0 ) && s [ i ] . charCodeAt ( 0 ) <= \\\" \\\" . charCodeAt ( 0 ) ) document . write ( \\\" \\\" + s [ i ] . toLowerCase ( ) ) ; else document . write ( s [ i ] ) ; i ++ ; } } var s = \\\" \\\" ; getOrgString ( s ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check whether given degrees of vertices represent a Graph or Tree | Function returns true for tree false for graph ; Find sum of all degrees ; Graph is tree if sum is equal to 2 ( n - 1 ) ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function check ( & $ degree , $ n ) { $ deg_sum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ deg_sum += $ degree [ $ i ] ; return ( 2 * ( $ n - 1 ) == $ deg_sum ) ; } $ n = 5 ; $ degree = array ( 2 , 3 , 1 , 1 , 1 ) ; if ( check ( $ degree , $ n ) ) echo \\\" Tree \\\" ; else echo \\\" Graph \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to duplicate Vowels in String | Java program for printing string with duplicate vowels ; Function to check for the Vowel ; Function to get the resultant string with vowels duplicated ; Another string to store the resultant string ; Loop to check for each character ; Driver Code ; Print the original string ; Print the resultant string\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static boolean isVowel ( char ch ) { ch = Character . toUpperCase ( ch ) ; return ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) ; } static String duplicateVowels ( String str ) { int t = str . length ( ) ; String res = \\\" \\\" ; for ( int i = 0 ; i < t ; i ++ ) { if ( isVowel ( str . charAt ( i ) ) ) res += str . charAt ( i ) ; res += str . charAt ( i ) ; } return res ; } public static void main ( String [ ] args ) { String str = \\\" helloworld \\\" ; System . out . println ( \\\" Original \u2581 String : \u2581 \\\" + str ) ; String res = duplicateVowels ( str ) ; System . out . println ( \\\" String \u2581 with \u2581 Vowels \u2581 duplicated : \u2581 \\\" + res ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Angle between 3 given vertices in a n | C # implementation of the approach ; Function that checks whether given angle can be created using any 3 sides ; Initialize x and y ; Calculate the number of vertices between i and j , j and k ; Calculate the angle subtended at the circumference ; Angle subtended at j can be found using the fact that the sum of angles of a triangle is equal to 180 degrees ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static double calculate_angle ( int n , int i , int j , int k ) { int x , y ; if ( i < j ) x = j - i ; else x = j + n - i ; if ( j < k ) y = k - j ; else y = k + n - j ; double ang1 = ( 180 * x ) \\/ n ; double ang2 = ( 180 * y ) \\/ n ; double ans = 180 - ang1 - ang2 ; return ans ; } public static void Main ( ) { int n = 5 ; int a1 = 1 ; int a2 = 2 ; int a3 = 5 ; Console . WriteLine ( ( int ) calculate_angle ( n , a1 , a2 , a3 ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all elements between k1 ' th \u2581 and \u2581 k2' th smallest elements | C # program to find sum of all element between to K1 ' th \u2581 and \u2581 k2' th smallest elements in array ; Returns sum between two kth smallest element of array ; Sort the given array ; Below code is equivalent to ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int sumBetweenTwoKth ( int [ ] arr , int n , int k1 , int k2 ) { Array . Sort ( arr ) ; int result = 0 ; for ( int i = k1 ; i < k2 - 1 ; i ++ ) result += arr [ i ] ; return result ; } public static void Main ( ) { int [ ] arr = { 20 , 8 , 22 , 4 , 12 , 10 , 14 } ; int k1 = 3 , k2 = 6 ; int n = arr . Length ; Console . Write ( sumBetweenTwoKth ( arr , n , k1 , k2 ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Queries to calculate sum of array elements present at every Yth index starting from the index X | C # program for the above approach ; Function to sum of arr [ x ] + arr [ x + y ] + arr [ x + 2 * y ] + ... for all possible values of X and Y , where Y is less than or equal to Math . Sqrt ( N ) . ; Iterate over all possible values of X ; Precompute for all possible values of an expression such that y <= Math . Sqrt ( N ) ; If i + j less than N ; Update dp [ i , j ] ; Update dp [ i , j ] ; Function to Find the sum of arr [ x ] + arr [ x + y ] + arr [ x + 2 * y ] + ... for all queries ; dp [ x , y ] : Stores sum of arr [ x ] + arr [ x + y ] + arr [ x + 2 * y ] + ... ; Traverse the query array , Q [ , ] ; If y is less than or equal to Math . Sqrt ( N ) ; Stores the sum of arr [ x ] + arr [ x + y ] + arr [ x + 2 * y ] + ... ; Traverse the array , [ ] arr ; Update sum ; Update x ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int sz = 20 ; static int sqr = ( int ) ( Math . Sqrt ( sz ) ) + 1 ; static void precomputeExpressionForAllVal ( int [ ] arr , int N , int [ , ] dp ) { for ( int i = N - 1 ; i >= 0 ; i -- ) { for ( int j = 1 ; j <= Math . Sqrt ( N ) ; j ++ ) { if ( i + j < N ) { dp [ i , j ] = arr [ i ] + dp [ i + j , j ] ; } else { dp [ i , j ] = arr [ i ] ; } } } } static void querySum ( int [ ] arr , int N , int [ , ] Q , int M ) { int [ , ] dp = new int [ sz , sqr ] ; precomputeExpressionForAllVal ( arr , N , dp ) ; for ( int i = 0 ; i < M ; i ++ ) { int x = Q [ i , 0 ] ; int y = Q [ i , 1 ] ; if ( y <= Math . Sqrt ( N ) ) { Console . Write ( dp [ x , y ] + \\\" \u2581 \\\" ) ; continue ; } int sum = 0 ; while ( x < N ) { sum += arr [ x ] ; x += y ; } Console . Write ( sum + \\\" \u2581 \\\" ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 7 , 5 , 4 } ; int [ , ] Q = { { 2 , 1 } , { 3 , 2 } } ; int N = arr . Length ; int M = Q . GetLength ( 0 ) ; querySum ( arr , N , Q , M ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximum element in connected component of given node for Q queries | Function to perform the find operation to find the parent of a disjoint set ; FUnction to perform union operation of disjoint set union ; If the rank are the same ; Update the maximum value ; Function to find the maximum element of the set which belongs to the element queries [ i ] ; Stores the parent elements of the sets ; Stores the rank of the sets ; Stores the maxValue of the sets ; Update parent [ i ] and maxValue [ i ] to i ; Add arr [ i ] . first and arr [ i ] . second elements to the same set ; Find the parent element of the element queries [ i ] ; Print the maximum value of the set which belongs to the element P ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def Find ( parent , a ) :\\n\\tif ( parent [ parent [ a ] ] != parent [ a ] ) :\\n\\t\\tparent [ a ] = findParent ( parent , parent [ a ] )\\n\\treturn parent [ a ]\\ndef Union ( parent , rank , maxValue , a , b ) :\\n\\ta = Find ( parent , a )\\n\\tb = Find ( parent , b )\\n\\tif ( a == b ) :\\n\\t\\treturn\\n\\tif ( rank [ a ] == rank [ b ] ) :\\n\\t\\trank [ a ] += 1\\n\\tif ( rank [ a ] < rank [ b ] ) :\\n\\t\\ttemp = a\\n\\t\\ta = b\\n\\t\\tb = temp\\n\\tparent [ b ] = a\\n\\tmaxValue [ a ] = max ( maxValue [ a ] , maxValue [ b ] )\\ndef findMaxValueOfSet ( arr , queries , R , N , M ) :\\n\\tparent = [ 1 for i in range ( R + 1 ) ]\\n\\trank = [ 0 for i in range ( R + 1 ) ]\\n\\tmaxValue = [ 0 for i in range ( R + 1 ) ]\\n\\tfor i in range ( 1 , R + 1 , 1 ) :\\n\\t\\tparent [ i ] = maxValue [ i ] = i\\n\\tfor i in range ( N ) :\\n\\t\\tUnion ( parent , rank , maxValue , arr [ i ] [ 0 ] , arr [ i ] [ 1 ] )\\n\\tfor i in range ( M ) :\\n\\t\\tP = Find ( parent , queries [ i ] )\\n\\t\\tprint ( maxValue [ P ] , end = \\\" \u2581 \\\" )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tR = 5\\n\\tarr = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 4 , 5 ] ] ;\\n\\tqueries = [ 2 , 4 , 1 , 3 ]\\n\\tN = len ( arr )\\n\\tM = len ( queries )\\n\\tfindMaxValueOfSet ( arr , queries , R , N , M )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Increment a number without using ++ or + | function that increment the value . ; Invert bits and apply negative sign ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def increment ( i ) :\\n\\ti = - ( ~ ord ( i ) ) ;\\n\\treturn chr ( i ) ;\\nn = ' a ' ;\\nprint ( increment ( n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count of distinct pair sum between two 1 to N value Arrays | Function to find the distinct sums ; Set to store distinct sums ; Inserting every sum ; Returning distinct sums ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findDistinctSums ( n ) :\\n\\ts = set ( )\\n\\tfor i in range ( 1 , n + 1 ) :\\n\\t\\tfor j in range ( i , n + 1 ) :\\n\\t\\t\\ts . add ( i + j )\\n\\treturn len ( s )\\nN = 3\\nprint ( findDistinctSums ( N ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Color all boxes in line such that every M consecutive boxes are unique | C ++ implementation of the approach ; Function to return ( m ! % MOD ) ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; #define MOD 1000000007\\nint modFact ( int n , int m ) { int result = 1 ; for ( int i = 1 ; i <= m ; i ++ ) result = ( result * i ) % MOD ; return result ; } int main ( ) { int n = 3 , m = 2 ; cout << modFact ( n , m ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Sum of series with alternate signed squares of AP | function to calculate series sum ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function seiresSum ( $ n , $ a ) { return $ n * ( $ a [ 0 ] * $ a [ 0 ] - $ a [ 2 * $ n - 1 ] * $ a [ 2 * $ n - 1 ] ) \\/ ( 2 * $ n - 1 ) ; } $ n = 2 ; $ a = array ( 1 , 2 , 3 , 4 ) ; echo seiresSum ( $ n , $ a ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Cutting a Rod | DP | A Dynamic Programming solution for Rod cutting problem ; Returns the best obtainable price for a rod of length n and price [ ] as prices of different pieces ; Build the table val [ ] in bottom up manner and return the last entry from the table ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int cutRod ( int [ ] price , int n ) { int [ ] val = new int [ n + 1 ] ; val [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int max_val = int . MinValue ; for ( int j = 0 ; j < i ; j ++ ) max_val = Math . Max ( max_val , price [ j ] + val [ i - j - 1 ] ) ; val [ i ] = max_val ; } return val [ n ] ; } public static void Main ( ) { int [ ] arr = new int [ ] { 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 } ; int size = arr . Length ; Console . WriteLine ( \\\" Maximum \u2581 Obtainable \u2581 Value \u2581 is \u2581 \\\" + cutRod ( arr , size ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find two numbers with given sum and maximum possible LCM | Function that print two numbers with the sum X and maximum possible LCM ; If X is odd ; If X is even ; If floor ( X \\/ 2 ) is even ; If floor ( X \\/ 2 ) is odd ; Print the result ; Driver Code ; Given Number ; Function call\\\"\\nSolution in Python:\",\"targets\":\"def maxLCMWithGivenSum ( X ) :\\n\\tif X % 2 != 0 :\\n\\t\\tA = X \\/ 2\\n\\t\\tB = X \\/ 2 + 1\\n\\telse :\\n\\t\\tif ( X \\/ 2 ) % 2 == 0 :\\n\\t\\t\\tA = X \\/ 2 - 1\\n\\t\\t\\tB = X \\/ 2 + 1\\n\\t\\telse :\\n\\t\\t\\tA = X \\/ 2 - 2\\n\\t\\t\\tB = X \\/ 2 + 2\\n\\tprint ( int ( A ) , int ( B ) , end = \\\" \u2581 \\\" )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tX = 30\\n\\tmaxLCMWithGivenSum ( X )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Print all longest common sub | C # program to find all LCS of two strings in sorted order . ; length of lcs ; dp matrix to store result of sub calls for lcs ; A memoization based function that returns LCS of str1 [ i . . len1 - 1 ] and str2 [ j . . len2 - 1 ] ; base condition ; if lcs has been computed ; if characters are same return previous + 1 else max of two sequences after removing i ' th \u2581 and \u2581 j ' th char one by one ; Function to print all routes common sub - sequences of length lcslen ; if currlcs is equal to lcslen then print it ; if we are done with all the characters of both string ; here we have to print all sub - sequences lexicographically , that ' s \u2581 why \u2581 we \u2581 start \u2581 from \u2581 ' a ' to ' z ' if this character is present in both of them then append it in data[] and same remaining part ; done is a flag to tell that we have printed all the subsequences corresponding to current character ; if character ch is present in str1 then check if it is present in str2 ; if ch is present in both of them and remaining length is equal to remaining lcs length then add ch in sub - sequenece ; If we found LCS beginning with current character . ; This function prints all LCS of str1 and str2 in lexicographic order . ; Find lengths of both strings ; Find length of LCS ; Print all LCS using recursive backtracking data [ ] is used to store individual LCS . ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int MAX = 100 ; static int lcslen = 0 ; static int [ , ] dp = new int [ MAX , MAX ] ; static int lcs ( string str1 , string str2 , int len1 , int len2 , int i , int j ) { int ret = dp [ i , j ] ; if ( i == len1 j == len2 ) return ret = 0 ; if ( ret != - 1 ) return ret ; ret = 0 ; if ( str1 [ i ] == str2 [ j ] ) ret = 1 + lcs ( str1 , str2 , len1 , len2 , i + 1 , j + 1 ) ; else ret = Math . Max ( lcs ( str1 , str2 , len1 , len2 , i + 1 , j ) , lcs ( str1 , str2 , len1 , len2 , i , j + 1 ) ) ; return ret ; } static void printAll ( string str1 , string str2 , int len1 , int len2 , char [ ] data , int indx1 , int indx2 , int currlcs ) { if ( currlcs == lcslen ) { data [ currlcs ] = ' \\\\0' ; Console . WriteLine ( new string ( data ) ) ; return ; } if ( indx1 == len1 indx2 == len2 ) return ; for ( char ch = ' a ' ; ch <= ' z ' ; ch ++ ) { bool done = false ; for ( int i = indx1 ; i < len1 ; i ++ ) { if ( ch == str1 [ i ] ) { for ( int j = indx2 ; j < len2 ; j ++ ) { if ( ch == str2 [ j ] && lcs ( str1 , str2 , len1 , len2 , i , j ) == lcslen - currlcs ) { data [ currlcs ] = ch ; printAll ( str1 , str2 , len1 , len2 , data , i + 1 , j + 1 , currlcs + 1 ) ; done = true ; break ; } } } if ( done ) break ; } } } static void prinlAllLCSSorted ( string str1 , string str2 ) { int len1 = str1 . Length , len2 = str2 . Length ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { dp [ i , j ] = - 1 ; } } lcslen = lcs ( str1 , str2 , len1 , len2 , 0 , 0 ) ; char [ ] data = new char [ MAX ] ; printAll ( str1 , str2 , len1 , len2 , data , 0 , 0 , 0 ) ; } static void Main ( ) { string str1 = \\\" abcabcaa \\\" , str2 = \\\" acbacba \\\" ; prinlAllLCSSorted ( str1 , str2 ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Smallest power of 2 greater than or equal to n | Java program to find smallest power of 2 greater than or equal to n ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int nextPowerOf2 ( int n ) { int p = 1 ; if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ; while ( p < n ) p <<= 1 ; return p ; } public static void main ( String args [ ] ) { int n = 5 ; System . out . println ( nextPowerOf2 ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count occurrences of substring X before every occurrence of substring Y in a given string | Function to count occurrences of the string Y in the string S for every occurrence of X in S ; Stores the count of occurrences of X ; Stores the lengths of the three strings ; Traverse the string S ; If the current substring is Y , then increment the value of count by 1 ; If the current substring is X , then print the count ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function countOccurrences ( S , X , Y ) { let count = 0 ; let N = S . length , A = X . length ; let B = Y . length ; for ( let i = 0 ; i < N ; i ++ ) { if ( S . substr ( i , B ) == Y ) count ++ ; if ( S . substr ( i , A ) == X ) document . write ( count , \\\" \\\" ) ; } } let S = \\\" \\\" , X = \\\" \\\" , Y = \\\" \\\" ; countOccurrences ( S , X , Y ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximum triplet sum in array | This function assumes that there are at least three elements in arr [ ] . ; Initialize Maximum , second maximum and third maximum element ; Update Maximum , second maximum and third maximum element ; Update second maximum and third maximum element ; Update third maximum element ; Driven code\\\"\\nSolution in php:\",\"targets\":\"< ? php function maxTripletSum ( $ arr , $ n ) { $ maxA = PHP_INT_MIN ; $ maxB = PHP_INT_MIN ; $ maxC = PHP_INT_MIN ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] > $ maxA ) { $ maxC = $ maxB ; $ maxB = $ maxA ; $ maxA = $ arr [ $ i ] ; } else if ( $ arr [ $ i ] > $ maxB ) { $ maxC = $ maxB ; $ maxB = $ arr [ $ i ] ; } else if ( $ arr [ $ i ] > $ maxC ) $ maxC = $ arr [ $ i ] ; } return ( $ maxA + $ maxB + $ maxC ) ; } $ arr = array ( 1 , 0 , 8 , 6 , 4 , 2 ) ; $ n = count ( $ arr ) ; echo maxTripletSum ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximum possible prime divisors that can exist in numbers having exactly N divisors | C # implementation to find the maximum possible prime divisor of a number can have N divisors ; Function to find the maximum possible prime divisors of a number can have with N divisors ; Number of time number divided by 2 ; Divide by other prime numbers ; If the last number of also prime then also include it ; Driver Code ; Function Call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void findMaxPrimeDivisor ( int n ) { int max_possible_prime = 0 ; while ( n % 2 == 0 ) { max_possible_prime ++ ; n = n \\/ 2 ; } for ( int i = 3 ; i * i <= n ; i = i + 2 ) { while ( n % i == 0 ) { max_possible_prime ++ ; n = n \\/ i ; } } if ( n > 2 ) { max_possible_prime ++ ; } Console . Write ( max_possible_prime + \\\" \\n \\\" ) ; } public static void Main ( String [ ] args ) { int n = 4 ; findMaxPrimeDivisor ( n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the Area and Perimeter of a Semicircle | C program to find the Area and Perimeter of a Semicircle ; Function for calculating the area ; Formula for finding the area ; Function for calculating the perimeter ; Formula for finding the perimeter ; driver code ; Get the radius ; Find the area ; Find the perimeter\\\"\\nSolution in C:\",\"targets\":\"#include \\nfloat area ( float r ) { return ( 0.5 ) * ( 3.14 ) * ( r * r ) ; } float perimeter ( float r ) { return ( 3.14 ) * ( r ) ; } int main ( ) { float r = 10 ; printf ( \\\" The \u2581 Area \u2581 of \u2581 Semicircle : \u2581 % f \\n \\\" , area ( r ) ) ; printf ( \\\" The \u2581 Perimeter \u2581 of \u2581 Semicircle : \u2581 % f \\n \\\" , perimeter ( r ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Numbers in a Range with given Digital Root | Function to return the count of required numbers ; Count of numbers present in given range ; Number of groups of 9 elements starting from L ; Left over elements not covered in factor 9 ; One Number in each group of 9 ; To check if any number in rem satisfy the property ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function countNumbers ( L , R , K ) { if ( K == 9 ) { K = 0 ; } var totalnumbers = R - L + 1 ; var factor9 = totalnumbers \\/ 9 ; var rem = totalnumbers % 9 ; var ans = factor9 ; for ( var i = R ; i > R - rem ; i -- ) { var rem1 = i % 9 ; if ( rem1 == K ) { ans ++ ; } } return ans ; } var L = 10 ; var R = 22 ; var K = 3 ; document . write ( Math . round ( countNumbers ( L , R , K ) ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find n | Program to calculate nth term of a series ; func for calualtion ; for summation of square of first n - natural nos . ; summation of first n natural nos . ; return result ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int seriesFunc ( int n ) { int sumSquare = ( n * ( n + 1 ) * ( 2 * n + 1 ) ) \\/ 6 ; int sumNatural = ( n * ( n + 1 ) \\/ 2 ) ; return ( sumSquare + sumNatural + 1 ) ; } int main ( ) { int n = 8 ; cout << seriesFunc ( n ) << endl ; n = 13 ; cout << seriesFunc ( 13 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Search , insert and delete in an unsorted array | C program to implement delete operation in a unsorted array ; Function to implement search operation ; Function to delete an element ; Find position of element to be deleted ; Deleting element ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\nint findElement ( int arr [ ] , int n , int key ) { int i ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] == key ) return i ; return - 1 ; } int deleteElement ( int arr [ ] , int n , int key ) { int pos = findElement ( arr , n , key ) ; if ( pos == - 1 ) { printf ( \\\" Element \u2581 not \u2581 found \\\" ) ; return n ; } int i ; for ( i = pos ; i < n - 1 ; i ++ ) arr [ i ] = arr [ i + 1 ] ; return n - 1 ; } int main ( ) { int i ; int arr [ ] = { 10 , 50 , 30 , 40 , 20 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int key = 30 ; printf ( \\\" Array \u2581 before \u2581 deletion \\n \\\" ) ; for ( i = 0 ; i < n ; i ++ ) printf ( \\\" % d \u2581 \\\" , arr [ i ] ) ; n = deleteElement ( arr , n , key ) ; printf ( \\\" Array after deletion \\\" for ( i = 0 ; i < n ; i ++ ) printf ( \\\" % d \u2581 \\\" , arr [ i ] ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count of Binary Digit numbers smaller than N | method returns count of binary digit numbers smaller than N ; queue to store all intermediate binary digit numbers ; binary digits start with 1 ; loop until we have element in queue ; push next binary digit numbers only if current popped element is N ; uncomment below line to print actual number in sorted order ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function countOfBinaryNumberLessThanN ( N ) { var q = [ ] ; q . push ( 1 ) ; var cnt = 0 ; var t ; while ( q . length > 0 ) { t = q . pop ( ) ; if ( t <= N ) { cnt ++ ; q . push ( t * 10 ) ; q . push ( t * 10 + 1 ) ; } } return cnt ; } var N = 200 ; document . write ( countOfBinaryNumberLessThanN ( N ) + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all substrings of a string representing a number | Set 1 | C ++ program to print sum of all substring of a number represented as a string ; Utility method to convert character digit to integer digit ; Returns sum of all substring of num ; allocate memory equal to length of string ; initialize first value with first digit ; loop over all digits of string ; update each sumofdigit from previous value ; add current value to the result ; Driver code to test above methods\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int toDigit ( char ch ) { return ( ch - '0' ) ; } int sumOfSubstrings ( string num ) { int n = num . length ( ) ; int sumofdigit [ n ] ; sumofdigit [ 0 ] = toDigit ( num [ 0 ] ) ; int res = sumofdigit [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { int numi = toDigit ( num [ i ] ) ; sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ; res += sumofdigit [ i ] ; } return res ; } int main ( ) { string num = \\\"1234\\\" ; cout << sumOfSubstrings ( num ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Move all digits to the beginning of a given string | Java program for the above approach ; Function to move all the digit to the beginning of the string ; Calculate the string length ; Stores the digits ; Stores the non - numeric character ; Traverse the string and check if there is a digit ; If character is a digit , add it to the string digits ; Otherwise , add it to the string nonNumericCharacter ; Append both the strings ; Print the string ; Driver Code ; Given String str\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static void moveAllDigitAtBeginning ( String str ) { int len = str . length ( ) ; StringBuilder digits = new StringBuilder ( ) ; StringBuilder nonNumericCharacter = new StringBuilder ( ) ; for ( char c : str . toCharArray ( ) ) { if ( c >= 48 && c <= 57 ) { digits . append ( c ) ; } else { nonNumericCharacter . append ( c ) ; } } digits . append ( nonNumericCharacter . toString ( ) ) ; System . out . print ( digits . toString ( ) + \\\" \u2581 \\\" ) ; } public static void main ( String args [ ] ) { String str = \\\" GeeksforGeeks123\\\" ; moveAllDigitAtBeginning ( str ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find the Missing Number in a sorted array | A binary search based program to find the only missing number in a sorted array of distinct elements within limited range . ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function search ( $ ar , $ size ) { $ a = 0 ; $ b = $ size - 1 ; $ mid ; while ( ( $ b - $ a ) > 1 ) { $ mid = ( int ) ( ( $ a + $ b ) \\/ 2 ) ; if ( ( $ ar [ $ a ] - $ a ) != ( $ ar [ $ mid ] - $ mid ) ) $ b = $ mid ; else if ( ( $ ar [ $ b ] - $ b ) != ( $ ar [ $ mid ] - $ mid ) ) $ a = $ mid ; } return ( $ ar [ $ a ] + 1 ) ; } $ ar = array ( 1 , 2 , 3 , 4 , 5 , 6 , 8 ) ; $ size = sizeof ( $ ar ) ; echo \\\" Missing \u2581 number : \u2581 \\\" , search ( $ ar , $ size ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to reach a score using 1 and 2 with no consecutive 2 s | Bottom up approach for counting ways to reach a score using 1 and 2 with consecutive 2 allowed ; noOfWays [ i ] will store count for last 3 values before i . ; Loop till \\\" n + 1\\\" to compute value for \\\" n \\\" ; number of ways if first run is 1 ; number of ways if first run is 2 and second run is 1 ; Remember last 3 values ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static int CountWays ( int n ) { int noOfWays [ ] = new int [ n + 3 ] ; noOfWays [ 0 ] = 1 ; noOfWays [ 1 ] = 1 ; noOfWays [ 2 ] = 1 + 1 ; for ( int i = 3 ; i < n + 1 ; i ++ ) { noOfWays [ i ] = noOfWays [ 3 - 1 ] + noOfWays [ 3 - 3 ] ; noOfWays [ 0 ] = noOfWays [ 1 ] ; noOfWays [ 1 ] = noOfWays [ 2 ] ; noOfWays [ 2 ] = noOfWays [ i ] ; } return noOfWays [ n ] ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( CountWays ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sort a Bitonic Array | Python3 program for the above approach ; Function to sort bitonic array in constant space ; Initialize thevalue of k ; In each iteration compare elements k distance apart and swap it they are not in order ; k is reduced to half after every iteration ; Print the array elements ; Given array ; Function call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import math\\ndef sortArr ( a , n ) :\\n\\tk = int ( math . log ( n , 2 ) )\\n\\tk = int ( pow ( 2 , k ) )\\n\\twhile ( k > 0 ) :\\n\\t\\ti = 0\\n\\t\\twhile i + k < n :\\n\\t\\t\\tif a [ i ] > a [ i + k ] :\\n\\t\\t\\t\\ta [ i ] , a [ i + k ] = a [ i + k ] , a [ i ]\\n\\t\\t\\ti = i + 1\\n\\t\\tk = k \\/\\/ 2\\n\\tfor i in range ( n ) :\\n\\t\\tprint ( a [ i ] , end = \\\" \u2581 \\\" )\\na = [ 5 , 20 , 30 , 40 , 36 , 33 , 25 , 15 , 10 ]\\nn = len ( a )\\nsortArr ( a , n )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count consonants in a string ( Iterative and recursive methods ) | Iterative Java program to count total number of consonants ; Function to check for consonant ; To handle lower case ; To check is character is Consonant ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static boolean isConsonant ( char ch ) { ch = Character . toUpperCase ( ch ) ; return ! ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) && ch >= 65 && ch <= 90 ; } static int totalConsonants ( String str ) { int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) if ( isConsonant ( str . charAt ( i ) ) ) ++ count ; return count ; } public static void main ( String args [ ] ) { String str = \\\" abc \u2581 de \\\" ; System . out . println ( totalConsonants ( str ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all the Composite Numbers from Odd indices of the given array | Function to check for composite numbers ; Check if the factors are greater than 2 ; Check if the number is composite or not ; Function to print the sum of all composite numbers in the array ; Iterate for odd indices in the array ; Check if the number is composite then add it to sum ; return the sum ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function composite ( n ) { let flag = 0 ; let c = 0 ; for ( let j = 1 ; j <= n ; j ++ ) { if ( n % j == 0 ) { c += 1 ; } } if ( c >= 3 ) flag = 1 ; return flag ; } function odd_indices ( arr , n ) { let sum = 0 ; for ( let k = 0 ; k < n ; k += 2 ) { let check = composite ( arr [ k ] ) ; if ( check == 1 ) sum += arr [ k ] ; } document . write ( sum + \\\" \\\" ) ; } let arr = [ 13 , 5 , 8 , 16 , 25 ] ; let n = arr . length odd_indices ( arr , n ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find sum of odd factors of a number | Returns sum of all factors of n . ; Traversing through all prime factors . ; ignore even factors by removing all powers of 2 ; While i divides n , print i and divide n ; This condition is to handle the case when n is a prime number . ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function sumofoddFactors ( $ n ) { $ res = 1 ; while ( $ n % 2 == 0 ) $ n = $ n \\/ 2 ; for ( $ i = 3 ; $ i <= sqrt ( $ n ) ; $ i ++ ) { $ count = 0 ; $ curr_sum = 1 ; $ curr_term = 1 ; while ( $ n % $ i == 0 ) { $ count ++ ; $ n = $ n \\/ $ i ; $ curr_term *= $ i ; $ curr_sum += $ curr_term ; } $ res *= $ curr_sum ; } if ( $ n >= 2 ) $ res *= ( 1 + $ n ) ; return $ res ; } $ n = 30 ; echo sumofoddFactors ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Convert a String to an Integer using Recursion | C # implementation of the approach ; Recursive function to convert string to integer ; If the number represented as a string contains only a single digit then returns its value ; Recursive call for the sub - string starting at the second character ; First digit of the number ; First digit multiplied by the appropriate power of 10 and then add the recursive result For example , xy = ( ( x * 10 ) + y ) ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int stringToInt ( String str ) { if ( str . Length == 1 ) return ( str [ 0 ] - '0' ) ; double y = stringToInt ( str . Substring ( 1 ) ) ; double x = str [ 0 ] - '0' ; x = x * Math . Pow ( 10 , str . Length - 1 ) + y ; return ( int ) ( x ) ; } public static void Main ( String [ ] args ) { String str = \\\"1235\\\" ; Console . Write ( stringToInt ( str ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Probability that the sum of all numbers obtained on throwing a dice N times lies between two given integers | Javascript program of the above approach ; Function to calculate probability that the sum of numbers on N throws of dice lies between A and B ; Base case ; Add the probability for all the numbers between a and b ; Driver Code ; Print the answer\\\"\\nSolution in Javascript:\",\"targets\":\"let dp = new Array ( 105 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < dp . length ; i ++ ) { for ( var j = 0 ; j < dp . length ; j ++ ) { dp [ i ] [ j ] = 0 ; } } function find ( N , a , b ) { let probability = 0.0 ; for ( let i = 1 ; i <= 6 ; i ++ ) dp [ 1 ] [ i ] = ( 1.0 \\/ 6 ) ; for ( let i = 2 ; i <= N ; i ++ ) { for ( let j = i ; j <= 6 * i ; j ++ ) { for ( let k = 1 ; k <= 6 && k <= j ; k ++ ) { dp [ i ] [ j ] = dp [ i ] [ j ] + dp [ i - 1 ] [ j - k ] \\/ 6 ; } } } for ( let sum = a ; sum <= b ; sum ++ ) probability = probability + dp [ N ] [ sum ] ; return probability ; } let N = 4 , a = 13 , b = 17 ; let probability = find ( N , a , b ) ; document . write ( probability ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum LCM and GCD possible among all possible sub | Python3 implementation of the approach ; Function to return minimum GCD among all subarrays ; Minimum GCD among all sub - arrays will be the GCD of all the elements of the array ; Function to return minimum LCM among all subarrays ; Minimum LCM among all sub - arrays will be the minimum element from the array ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"from math import gcd\\ndef minGCD ( arr , n ) :\\n\\tminGCD = 0 ;\\n\\tfor i in range ( n ) :\\n\\t\\tminGCD = gcd ( minGCD , arr [ i ] ) ;\\n\\treturn minGCD ;\\ndef minLCM ( arr , n ) :\\n\\tminLCM = arr [ 0 ] ;\\n\\tfor i in range ( 1 , n ) :\\n\\t\\tminLCM = min ( minLCM , arr [ i ] ) ;\\n\\treturn minLCM ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ 2 , 66 , 14 , 521 ] ;\\n\\tn = len ( arr ) ;\\n\\tprint ( \\\" LCM \u2581 = \u2581 \\\" , minLCM ( arr , n ) , \\\" , \u2581 GCD \u2581 = \\\" , minGCD ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Calculate Bitwise OR of two integers from their given Bitwise AND and Bitwise XOR values | C # program to implement the above approach ; Function to calculate Bitwise OR from given bitwise XOR and bitwise AND values ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int findBitwiseORGivenXORAND ( int X , int Y ) { return X + Y ; } public static void Main ( string [ ] args ) { int X = 5 , Y = 2 ; Console . Write ( findBitwiseORGivenXORAND ( X , Y ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Make the string lexicographically smallest and non palindromic by replacing exactly one character | Function to find the required string ; Length of the string ; Iterate till half of the string ; Replacing a non ' a ' char with 'a ; Check if there is no ' a ' in string we replace last char of string by 'b ; If the input is a single character ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findStr ( S ) :\\n\\tS = list ( S )\\n\\tn = len ( S )\\n\\tfor i in range ( 0 , n \\/\\/ 2 ) :\\n'\\n\\tif S [ i ] != ' a ' :\\n\\t\\tS [ i ] = ' a '\\n\\t\\treturn ( ' ' . join ( S ) )\\n'\\n\\tS [ n - 1 ] = ' b '\\n\\tif n < 2 :\\n\\t\\treturn ' - 1'\\n\\telse :\\n\\t\\treturn ( ' ' . join ( S ) )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tstr1 = ' a '\\n\\tprint ( findStr ( str1 ) )\\n\\tstr2 = ' abccba '\\n\\tprint ( findStr ( str2 ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Number with maximum number of prime factors | Java program to find integer having maximum number of prime factor in first N natural numbers ; Return smallest number having maximum prime factors . ; default value of boolean is false ; Sieve of eratosthenes ; Storing prime numbers . ; Generating number having maximum prime factors . ; Driver program\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . Vector ; public class GFG { static int maxPrimefactorNum ( int N ) { boolean arr [ ] = new boolean [ N + 5 ] ; for ( int i = 3 ; i * i <= N ; i += 2 ) { if ( ! arr [ i ] ) { for ( int j = i * i ; j <= N ; j += i ) { arr [ j ] = true ; } } } Vector < Integer > prime = new Vector < > ( ) ; prime . add ( prime . size ( ) , 2 ) ; for ( int i = 3 ; i <= N ; i += 2 ) { if ( ! arr [ i ] ) { prime . add ( prime . size ( ) , i ) ; } } int i = 0 , ans = 1 ; while ( ans * prime . get ( i ) <= N && i < prime . size ( ) ) { ans *= prime . get ( i ) ; i ++ ; } return ans ; } public static void main ( String [ ] args ) { int N = 40 ; System . out . println ( maxPrimefactorNum ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Dynamic Programming | A Dynamic Programming solution for subset sum problem ; Returns true if there is a subset of set [ ] with sum equal to given sum ; The value of subset [ i ] [ j ] will be true if there is a subset of set [ 0. . j - 1 ] with sum equal to i ; If sum is 0 , then answer is true ; If sum is not 0 and set is empty , then answer is false ; Fill the subset table in bottom up manner ; uncomment this code to print table ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static boolean isSubsetSum ( int set [ ] , int n , int sum ) { boolean subset [ ] [ ] = new boolean [ sum + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) subset [ 0 ] [ i ] = true ; for ( int i = 1 ; i <= sum ; i ++ ) subset [ i ] [ 0 ] = false ; for ( int i = 1 ; i <= sum ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { subset [ i ] [ j ] = subset [ i ] [ j - 1 ] ; if ( i >= set [ j - 1 ] ) subset [ i ] [ j ] = subset [ i ] [ j ] || subset [ i - set [ j - 1 ] ] [ j - 1 ] ; } } for ( int i = 0 ; i <= sum ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) System . out . println ( subset [ i ] [ j ] ) ; } return subset [ sum ] [ n ] ; } public static void main ( String args [ ] ) { int set [ ] = { 3 , 34 , 4 , 12 , 5 , 2 } ; int sum = 9 ; int n = set . length ; if ( isSubsetSum ( set , n , sum ) == true ) System . out . println ( \\\" Found \u2581 a \u2581 subset \\\" + \\\" \u2581 with \u2581 given \u2581 sum \\\" ) ; else System . out . println ( \\\" No \u2581 subset \u2581 with \\\" + \\\" \u2581 given \u2581 sum \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if a subsequence of length K with odd sum exists | Function to check if any required subsequence exists or not ; Store count of odd and even elements in the array ; Calculate the count of odd and even elements ; If no odd elements exists or no even elements exists when K is even ; Subsequence is not possible ; Possible otherwise ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function isSubseqPossible ( arr , N , K ) { let i ; let odd = 0 , even = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) odd ++ ; else even ++ ; } if ( odd == 0 || ( even == 0 && K % 2 == 0 ) ) return false ; return true ; } let arr = [ 2 , 3 , 5 , 7 , 4 ] ; let N = arr . length ; let K = 3 ; document . write ( isSubseqPossible ( arr , N , K ) ? \\\" \\\" : \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Modify given array to a non | Java program for the above approach ; Function to check if a non - decreasing array can be obtained by rotating the original array ; Stores copy of original array ; Sort the given vector ; Traverse the array ; Rotate the array by 1 ; If array is sorted ; If it is not possible to sort the array ; Driver Code ; Given array ; Size of the array ; Function call to check if it is possible to make array non - decreasing by rotating\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static void rotateArray ( int [ ] arr , int N ) { int [ ] v = arr ; Arrays . sort ( v ) ; for ( int i = 1 ; i <= N ; ++ i ) { int x = arr [ N - 1 ] ; i = N - 1 ; while ( i > 0 ) { arr [ i ] = arr [ i - 1 ] ; arr [ 0 ] = x ; i -= 1 ; } if ( arr == v ) { System . out . print ( \\\" YES \\\" ) ; return ; } } System . out . print ( \\\" NO \\\" ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 4 , 5 , 1 , 2 } ; int N = arr . length ; rotateArray ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Pell Number | calculate nth pell number ; driver function\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def pell ( n ) :\\n\\tif ( n <= 2 ) :\\n\\t\\treturn n\\n\\ta = 1\\n\\tb = 2\\n\\tfor i in range ( 3 , n + 1 ) :\\n\\t\\tc = 2 * b + a\\n\\t\\ta = b\\n\\t\\tb = c\\n\\treturn b\\nn = 4\\nprint ( pell ( n ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Pell Number | Pell Number Series using Recursion in C ; calculate nth pell number ; driver function\\\"\\nSolution in C:\",\"targets\":\"#include \\nint pell ( int n ) { if ( n <= 2 ) return n ; return 2 * pell ( n - 1 ) + pell ( n - 2 ) ; } int main ( ) { int n = 4 ; printf ( \\\" % d \\\" , pell ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count occurrences of a character in a repeated string | Java program to find the occurrences of character x in the infinite repeated string upto length n ; Function to count the character ' a ' ; atleast k repetition are required ; if n is not the multiple of the string size check for the remaining repeating character . ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; import java . lang . * ; class GFG { static int countChar ( String str , char x ) { int count = 0 ; int n = 10 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) if ( str . charAt ( i ) == x ) count ++ ; int repetitions = n \\/ str . length ( ) ; count = count * repetitions ; for ( int i = 0 ; i < n % str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == x ) count ++ ; } return count ; } public static void main ( String args [ ] ) { String str = \\\" abcac \\\" ; System . out . println ( countChar ( str , ' a ' ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count minimum number of moves to front or end to sort an array | Java program for the above approach ; Function that counts the minimum moves required to covert arr [ ] to brr [ ] ; Base Case ; If arr [ i ] < arr [ j ] ; Include the current element ; Otherwise , excluding the current element ; Function that counts the minimum moves required to sort the array ; If both the arrays are equal ; No moves required ; Otherwise ; Print minimum operations required ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; import java . io . * ; import java . lang . Math ; class GFG { static int minOperations ( int arr1 [ ] , int arr2 [ ] , int i , int j ) { if ( arr1 . equals ( arr2 ) ) return 0 ; if ( i >= arr1 . length j >= arr2 . length ) return 0 ; if ( arr1 [ i ] < arr2 [ j ] ) return 1 + minOperations ( arr1 , arr2 , i + 1 , j + 1 ) ; return Math . max ( minOperations ( arr1 , arr2 , i , j + 1 ) , minOperations ( arr1 , arr2 , i + 1 , j ) ) ; } static void minOperationsUtil ( int [ ] arr ) { int brr [ ] = new int [ arr . length ] ; for ( int i = 0 ; i < arr . length ; i ++ ) brr [ i ] = arr [ i ] ; Arrays . sort ( brr ) ; if ( arr . equals ( brr ) ) System . out . print ( \\\"0\\\" ) ; else System . out . println ( minOperations ( arr , brr , 0 , 0 ) ) ; } public static void main ( final String [ ] args ) { int arr [ ] = { 4 , 7 , 2 , 3 , 9 } ; minOperationsUtil ( arr ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Segregate 0 s and 1 s in an array | Function to put all 0 s on left and all 1 s on right ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function segregate0and1 ( & $ arr , $ size ) { $ type0 = 0 ; $ type1 = $ size - 1 ; while ( $ type0 < $ type1 ) { if ( $ arr [ $ type0 ] == 1 ) { $ temp = $ arr [ $ type0 ] ; $ arr [ $ type0 ] = $ arr [ $ type1 ] ; $ arr [ $ type1 ] = $ temp ; $ type1 -- ; } else $ type0 ++ ; } } $ arr = array ( 0 , 1 , 0 , 1 , 1 , 1 ) ; $ arr_size = sizeof ( $ arr ) ; segregate0and1 ( $ arr , $ arr_size ) ; echo ( \\\" Array \u2581 after \u2581 segregation \u2581 is \u2581 \\\" ) ; for ( $ i = 0 ; $ i < $ arr_size ; $ i ++ ) echo ( $ arr [ $ i ] . \\\" \u2581 \\\" ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Rearrange array to maximize sum of GCD of array elements with their respective indices | Function to find the maximum sum of GCD ( arr [ i ] , i ) by rearranging the array ; Stores maximum sum of GCD ( arr [ i ] , i ) by rearranging the array elements ; Update res ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findMaxValByRearrArr ( arr , N ) :\\n\\tres = 0 ;\\n\\tres = ( N * ( N + 1 ) ) \\/\\/ 2 ;\\n\\treturn res ;\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 3 , 2 , 1 ] ;\\n\\tN = len ( arr ) ;\\n\\tprint ( findMaxValByRearrArr ( arr , N ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find the smallest and second smallest elements in an array | Java program to find smallest and second smallest elements ; Function to print first smallest and second smallest elements ; There should be atleast two elements ; If current element is smaller than first then update both first and second ; If arr [ i ] is in between first and second then update second ; Driver program to test above functions\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class SecondSmallest { static void print2Smallest ( int arr [ ] ) { int first , second , arr_size = arr . length ; if ( arr_size < 2 ) { System . out . println ( \\\" \u2581 Invalid \u2581 Input \u2581 \\\" ) ; return ; } first = second = Integer . MAX_VALUE ; for ( int i = 0 ; i < arr_size ; i ++ ) { if ( arr [ i ] < first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] < second && arr [ i ] != first ) second = arr [ i ] ; } if ( second == Integer . MAX_VALUE ) System . out . println ( \\\" There \u2581 is \u2581 no \u2581 second \\\" + \\\" smallest \u2581 element \\\" ) ; else System . out . println ( \\\" The \u2581 smallest \u2581 element \u2581 is \u2581 \\\" + first + \\\" \u2581 and \u2581 second \u2581 Smallest \\\" + \\\" \u2581 element \u2581 is \u2581 \\\" + second ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 13 , 1 , 10 , 34 , 1 } ; print2Smallest ( arr ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count of replacements required to make the sum of all Pairs of given type from the Array equal | Python3 program to implement the above approach ; Function to find the minimum replacements required ; Stores the maximum and minimum values for every pair of the form arr [ i ] , arr [ n - i - 1 ] ; Map for storing frequencies of every sum formed by pairs ; Minimum element in the pair ; Maximum element in the pair ; Incrementing the frequency of sum encountered ; Insert minimum and maximum values ; Sorting the vectors ; Iterate over all possible values of x ; Count of pairs for which x > x + k ; Count of pairs for which x < mn + 1 ; Count of pairs requiring 2 replacements ; Count of pairs requiring no replacements ; Count of pairs requiring 1 replacement ; Update the answer ; Return the answer ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"inf = 10 ** 18\\ndef firstOccurance ( numbers , length , searchnum ) :\\n\\tanswer = - 1\\n\\tstart = 0\\n\\tend = length - 1\\n\\twhile start <= end :\\n\\t\\tmiddle = ( start + end ) \\/\\/ 2\\n\\t\\tif numbers [ middle ] == searchnum :\\n\\t\\t\\tanswer = middle\\n\\t\\t\\tend = middle - 1\\n\\t\\telif numbers [ middle ] > searchnum :\\n\\t\\t\\tend = middle - 1\\n\\t\\telse :\\n\\t\\t\\tstart = middle + 1\\n\\treturn answer\\ndef minimumReplacement ( arr , N , K ) :\\n\\tans = inf\\n\\tmax_values = [ ]\\n\\tmin_values = [ ]\\n\\tsum_equal_to_x = dict ( )\\n\\tfor i in range ( N \\/\\/ 2 ) :\\n\\t\\tmn = min ( arr [ i ] , arr [ N - i - 1 ] )\\n\\t\\tmx = max ( arr [ i ] , arr [ N - i - 1 ] )\\n\\t\\tif ( arr [ i ] + arr [ N - i - 1 ] not in sum_equal_to_x ) :\\n\\t\\t\\tsum_equal_to_x [ arr [ i ] + arr [ N - i - 1 ] ] = 0\\n\\t\\tsum_equal_to_x [ arr [ i ] + arr [ N - i - 1 ] ] += 1\\n\\t\\tmin_values . append ( mn )\\n\\t\\tmax_values . append ( mx )\\n\\tmax_values . sort ( )\\n\\tmin_values . sort ( )\\n\\tfor x in range ( 2 , 2 * K + 1 ) :\\n\\t\\tmp1 = firstOccurance ( max_values , len ( max_values ) , x - K )\\n\\t\\tmp2 = firstOccurance ( min_values , len ( min_values ) , x )\\n\\t\\trep2 = mp1 + ( N \\/\\/ 2 - mp2 )\\n\\t\\tif x in sum_equal_to_x :\\n\\t\\t\\trep0 = sum_equal_to_x [ x ]\\n\\t\\telse :\\n\\t\\t\\trep0 = 0\\n\\t\\trep1 = ( N \\/\\/ 2 - rep2 - rep0 )\\n\\t\\tans = min ( ans , rep2 * 2 + rep1 )\\n\\treturn ans\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 4\\n\\tK = 3\\n\\tarr = [ 1 , 2 , 2 , 1 ]\\n\\tprint ( minimumReplacement ( arr , N , K ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"How to swap two bits in a given integer ? | C code for swapping given bits of a number ; left - shift 1 p1 and p2 times and using XOR ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint swapBits ( int n , int p1 , int p2 ) { n ^= 1 << p1 ; n ^= 1 << p2 ; return n ; } int main ( ) { printf ( \\\" Result \u2581 = \u2581 % d \\\" , swapBits ( 28 , 0 , 3 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Case | Java implementation of the approach ; To store the frequencies of the lowercase and the uppercase characters in the given string ; If current character is lowercase then increment its frequency in the lower [ ] array ; Else increment in the upper [ ] array ; Pointers that point to the smallest lowercase and the smallest uppercase characters respectively in the given string ; For every character in the given string ; If the current character is lowercase then replace it with the smallest lowercase character available ; Decrement the frequency of the used character ; Else replace it with the smallest uppercase character available ; Decrement the frequency of the used character ; Return the sorted string ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . lang . Character ; class GFG { static int MAX = 26 ; public static String getSortedString ( StringBuilder s , int n ) { int [ ] lower = new int [ MAX ] ; int [ ] upper = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( Character . isLowerCase ( s . charAt ( i ) ) ) lower [ s . charAt ( i ) - ' a ' ] ++ ; else if ( Character . isUpperCase ( s . charAt ( i ) ) ) upper [ s . charAt ( i ) - ' A ' ] ++ ; } int i = 0 , j = 0 ; while ( i < MAX && lower [ i ] == 0 ) i ++ ; while ( j < MAX && upper [ j ] == 0 ) j ++ ; for ( int k = 0 ; k < n ; k ++ ) { if ( Character . isLowerCase ( s . charAt ( k ) ) ) { while ( lower [ i ] == 0 ) i ++ ; s . setCharAt ( k , ( char ) ( i + ' a ' ) ) ; lower [ i ] -- ; } else if ( Character . isUpperCase ( s . charAt ( k ) ) ) { while ( upper [ j ] == 0 ) j ++ ; s . setCharAt ( k , ( char ) ( j + ' A ' ) ) ; upper [ j ] -- ; } } return s . toString ( ) ; } public static void main ( String [ ] args ) { StringBuilder s = new StringBuilder ( \\\" gEeksfOrgEEkS \\\" ) ; int n = s . length ( ) ; System . out . println ( getSortedString ( s , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Count number of ways to reach a given score in a game | A C program to count number of possible ways to a given score can be reached in a game where a move can earn 3 or 5 or 10 ; Returns number of ways to reach score n ; table [ i ] will store count of solutions for value i . ; Initialize all table values as 0 ; Base case ( If given value is 0 ) ; One by one consider given 3 moves and update the table [ ] values after the index greater than or equal to the value of the picked move ; Driver program\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint count ( int n ) { int table [ n + 1 ] , i ; memset ( table , 0 , sizeof ( table ) ) ; table [ 0 ] = 1 ; for ( i = 3 ; i <= n ; i ++ ) table [ i ] += table [ i - 3 ] ; for ( i = 5 ; i <= n ; i ++ ) table [ i ] += table [ i - 5 ] ; for ( i = 10 ; i <= n ; i ++ ) table [ i ] += table [ i - 10 ] ; return table [ n ] ; } int main ( void ) { int n = 20 ; printf ( \\\" Count \u2581 for \u2581 % d \u2581 is \u2581 % d \\n \\\" , n , count ( n ) ) ; n = 13 ; printf ( \\\" Count \u2581 for \u2581 % d \u2581 is \u2581 % d \\\" , n , count ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of squares of side length required to cover an N * M rectangle | CPP program to find number of squares of a * a required to cover n * m rectangle ; function to find number of squares of a * a required to cover n * m rectangle ; Driver code ; function call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int Squares ( int n , int m , int a ) { return ( ( m + a - 1 ) \\/ a ) * ( ( n + a - 1 ) \\/ a ) ; } int main ( ) { int n = 6 , m = 6 , a = 4 ; cout << Squares ( n , m , a ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximize the diamonds by choosing different colour diamonds from adjacent boxes | Function to return the maximized value ; Number of rows and columns ; Creating the Dp array ; Populating the first column ; Iterating over all the rows ; Getting the ( i - 1 ) th max value ; Adding it to the current cell ; Getting the max sum from the last column ; Driver code ; Columns are indexed 1 - based\\\"\\nSolution in Python:\",\"targets\":\"def maxSum ( arr ) :\\n\\tm = len ( arr )\\n\\tn = len ( arr [ 0 ] ) - 1\\n\\tdp = [ [ 0 for i in range ( n + 1 ) ] for j in range ( m ) ]\\n\\tfor i in range ( 1 , m , 1 ) :\\n\\t\\tdp [ i ] [ 1 ] = arr [ i ] [ 1 ]\\n\\tfor i in range ( 1 , n + 1 , 1 ) :\\n\\t\\tfor j in range ( 1 , m , 1 ) :\\n\\t\\t\\tmx = 0\\n\\t\\t\\tfor k in range ( 1 , m , 1 ) :\\n\\t\\t\\t\\tif ( k != j ) :\\n\\t\\t\\t\\t\\tif ( dp [ k ] [ i - 1 ] > mx ) :\\n\\t\\t\\t\\t\\t\\tmx = dp [ k ] [ i - 1 ]\\n\\t\\t\\tif ( mx and arr [ j ] [ i ] ) :\\n\\t\\t\\t\\tdp [ j ] [ i ] = arr [ j ] [ i ] + mx\\n\\tans = - 1\\n\\tfor i in range ( 1 , m , 1 ) :\\n\\t\\tif ( dp [ i ] [ n ] ) :\\n\\t\\t\\tans = max ( ans , dp [ i ] [ n ] )\\n\\treturn ans\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ [ 0 , 0 , 0 , 0 , 0 ] , [ 0 , 10 , 2 , 20 , 0 ] , [ 0 , 0 , 0 , 5 , 0 ] , [ 0 , 0 , 0 , 0 , 6 ] , [ 0 , 4 , 0 , 11 , 5 ] , [ 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 ] ]\\n\\tprint ( maxSum ( arr ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Number of pairs of lines having integer intersection points | C ++ program to Number of pairs of lines having integer intersection points ; Count number of pairs of lines having integer intersection point ; Initialize arrays to store counts ; Count number of odd and even Pi ; Count number of odd and even Qi ; Return the count of pairs ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int countPairs ( int * P , int * Q , int N , int M ) { int A [ 2 ] = { 0 } , B [ 2 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) A [ P [ i ] % 2 ] ++ ; for ( int i = 0 ; i < M ; i ++ ) B [ Q [ i ] % 2 ] ++ ; return ( A [ 0 ] * B [ 0 ] + A [ 1 ] * B [ 1 ] ) ; } int main ( ) { int P [ ] = { 1 , 3 , 2 } , Q [ ] = { 3 , 0 } ; int N = sizeof ( P ) \\/ sizeof ( P [ 0 ] ) ; int M = sizeof ( Q ) \\/ sizeof ( Q [ 0 ] ) ; cout << countPairs ( P , Q , N , M ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find the quadratic equation from the given roots | Java implementation of the above approach ; Function to find the quadratic equation whose roots are a and b ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static void findEquation ( int a , int b ) { int sum = ( a + b ) ; int product = ( a * b ) ; System . out . println ( \\\" x ^ 2 \u2581 - \u2581 ( \\\" + sum + \\\" x ) \u2581 + \u2581 ( \\\" + product + \\\" ) \u2581 = \u2581 0\\\" ) ; } public static void main ( String args [ ] ) { int a = 2 , b = 3 ; findEquation ( a , b ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Split array into minimum number of subarrays having GCD of its first and last element exceeding 1 | C # program for the above approach ; Function to find the minimum number of subarrays ; Right pointer ; Left pointer ; Count of subarrays ; Find GCD ( left , right ) ; Found a valid large subarray between arr [ left , right ] ; Searched the arr [ 0. . right ] and found no subarray having size > 1 and having gcd ( left , right ) > 1 ; Driver Code ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int minSubarrays ( int [ ] arr , int n ) { int right = n - 1 ; int left = 0 ; int subarrays = 0 ; while ( right >= 0 ) { for ( left = 0 ; left <= right ; left += 1 ) { if ( __gcd ( arr [ left ] , arr [ right ] ) > 1 ) { subarrays += 1 ; right = left - 1 ; break ; } if ( left == right && __gcd ( arr [ left ] , arr [ right ] ) == 1 ) { return 0 ; } } } return subarrays ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void Main ( ) { int N = 6 ; int [ ] arr = { 2 , 3 , 4 , 4 , 4 , 3 } ; Console . Write ( minSubarrays ( arr , N ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"One line function for factorial of a number | C ++ program to find factorial of given number ; single line to find factorial ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nint factorial ( int n ) { return ( n == 1 n == 0 ) ? 1 : n * factorial ( n - 1 ) ; } int main ( ) { int num = 5 ; printf ( \\\" Factorial \u2581 of \u2581 % d \u2581 is \u2581 % d \\\" , num , factorial ( num ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Gold Mine Problem | Python program to solve Gold Mine problem ; Returns maximum amount of gold that can be collected when journey started from first column and moves allowed are right , right - up and right - down ; Create a table for storing intermediate results and initialize all cells to 0. The first row of goldMineTable gives the maximum gold that the miner can collect when starts that row ; Gold collected on going to the cell on the right ( -> ) ; Gold collected on going to the cell to right up ( \\/ ) ; Gold collected on going to the cell to right down ( \\\\ ) ; Max gold collected from taking either of the above 3 paths ; The max amount of gold collected will be the max value in first column of all rows ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"MAX = 100\\ndef getMaxGold ( gold , m , n ) :\\n\\tgoldTable = [ [ 0 for i in range ( n ) ] for j in range ( m ) ]\\n\\tfor col in range ( n - 1 , - 1 , - 1 ) :\\n\\t\\tfor row in range ( m ) :\\n\\t\\t\\tif ( col == n - 1 ) :\\n\\t\\t\\t\\tright = 0\\n\\t\\t\\telse :\\n\\t\\t\\t\\tright = goldTable [ row ] [ col + 1 ]\\n\\t\\t\\tif ( row == 0 or col == n - 1 ) :\\n\\t\\t\\t\\tright_up = 0\\n\\t\\t\\telse :\\n\\t\\t\\t\\tright_up = goldTable [ row - 1 ] [ col + 1 ]\\n\\t\\t\\tif ( row == m - 1 or col == n - 1 ) :\\n\\t\\t\\t\\tright_down = 0\\n\\t\\t\\telse :\\n\\t\\t\\t\\tright_down = goldTable [ row + 1 ] [ col + 1 ]\\n\\t\\t\\tgoldTable [ row ] [ col ] = gold [ row ] [ col ] + max ( right , right_up , right_down )\\n\\tres = goldTable [ 0 ] [ 0 ]\\n\\tfor i in range ( 1 , m ) :\\n\\t\\tres = max ( res , goldTable [ i ] [ 0 ] )\\n\\treturn res\\ngold = [ [ 1 , 3 , 1 , 5 ] , [ 2 , 2 , 4 , 1 ] , [ 5 , 0 , 2 , 3 ] , [ 0 , 6 , 1 , 2 ] ]\\nm = 4\\nn = 4\\nprint ( getMaxGold ( gold , m , n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count trailing zero bits using lookup table | Simple PHP code for counting trailing zeros in binary representation of a number ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function countTrailingZero ( $ x ) { $ count = 0 ; while ( ( $ x & 1 ) == 0 ) { $ x = $ x >> 1 ; $ count ++ ; } return $ count ; } echo countTrailingZero ( 11 ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximum sum possible from given Matrix by performing given operations | Java program for the above approach ; Function to print the maximum sum ; Dp table ; Initializing dp array with 0 s ; Base case ; Traverse each column ; Update answer for both rows ; Print the maximum sum ; Driver Code ; Given array ; Number of Columns ; Function calls\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { static void maxSum ( int [ ] [ ] arr , int n , int m ) { int [ ] [ ] dp = new int [ n ] [ m + 1 ] ; for ( int i = 0 ; i < 2 ; i ++ ) { for ( int j = 0 ; j <= m ; j ++ ) { dp [ i ] [ j ] = 0 ; } } dp [ 0 ] [ m - 1 ] = arr [ 0 ] [ m - 1 ] ; dp [ 1 ] [ m - 1 ] = arr [ 1 ] [ m - 1 ] ; for ( int j = m - 2 ; j >= 0 ; j -- ) { for ( int i = 0 ; i < 2 ; i ++ ) { if ( i == 1 ) { dp [ i ] [ j ] = Math . max ( arr [ i ] [ j ] + dp [ 0 ] [ j + 1 ] , arr [ i ] [ j ] + dp [ 0 ] [ j + 2 ] ) ; } else { dp [ i ] [ j ] = Math . max ( arr [ i ] [ j ] + dp [ 1 ] [ j + 1 ] , arr [ i ] [ j ] + dp [ 1 ] [ j + 2 ] ) ; } } } System . out . println ( Math . max ( dp [ 0 ] [ 0 ] , dp [ 1 ] [ 0 ] ) ) ; } public static void main ( String [ ] args ) { int [ ] [ ] arr = { { 1 , 50 , 21 , 5 } , { 2 , 10 , 10 , 5 } } ; int N = arr [ 0 ] . length ; maxSum ( arr , 2 , N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find maximum subset sum formed by partitioning any subset of array into 2 partitions with equal sum | Java implementation for the above mentioned recursive approach ; Function to find the maximum subset sum ; Ignore the current element ; including element in partition 1 ; including element in partition 2 ; Driver code ; size of the array\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int maxSum ( int p0 , int p1 , int a [ ] , int pos , int n ) { if ( pos == n ) { if ( p0 == p1 ) return p0 ; else return 0 ; } int ans = maxSum ( p0 , p1 , a , pos + 1 , n ) ; ans = Math . max ( ans , maxSum ( p0 + a [ pos ] , p1 , a , pos + 1 , n ) ) ; ans = Math . max ( ans , maxSum ( p0 , p1 + a [ pos ] , a , pos + 1 , n ) ) ; return ans ; } public static void main ( String [ ] args ) { int n = 4 ; int a [ ] = { 1 , 2 , 3 , 6 } ; System . out . println ( maxSum ( 0 , 0 , a , 0 , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sum of two numbers where one number is represented as array of digits | C ++ implementation of the approach ; Function to return the vector containing the answer ; Vector v is to store each digits sum and vector ans is to store the answer ; No carry in the beginning ; Start loop from the end and take element one by one ; Array index and last digit of number ; Maintain carry of summation ; Push the digit value into the array ; K value is greater then 0 ; Push digits of K one by one in the array ; Also maintain carry with summation ; Reverse the elements of vector v and store it in vector ans ; Driver code ; Print the answer\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; vector < int > addToArrayForm ( vector < int > & A , int K ) { vector < int > v , ans ; int rem = 0 ; int i = 0 ; for ( i = A . size ( ) - 1 ; i >= 0 ; i -- ) { int my = A [ i ] + K % 10 + rem ; if ( my > 9 ) { rem = 1 ; v . push_back ( my % 10 ) ; } else { v . push_back ( my ) ; rem = 0 ; } K = K \\/ 10 ; } while ( K > 0 ) { int my = K % 10 + rem ; v . push_back ( my % 10 ) ; if ( my \\/ 10 > 0 ) rem = 1 ; else rem = 0 ; K = K \\/ 10 ; } if ( rem > 0 ) v . push_back ( rem ) ; for ( int i = v . size ( ) - 1 ; i >= 0 ; i -- ) ans . push_back ( v [ i ] ) ; return ans ; } int main ( ) { vector < int > A { 2 , 7 , 4 } ; int K = 181 ; vector < int > ans = addToArrayForm ( A , K ) ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) cout << ans [ i ] ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count total set bits in all numbers from 1 to n | A O ( Logn ) complexity program to count set bits in all numbers from 1 to n ; Returns position of leftmost set bit . The rightmost position is considered as 0 ; Given the position of previous leftmost set bit in n ( or an upper bound on leftmost position ) returns the new position of leftmost set bit in n ; The main recursive function used by countSetBits ( ) ; Get the position of leftmost set bit in n . This will be used as an upper bound for next set bit function ; Use the position ; Base Case : if n is 0 , then set bit count is 0 ; get position of next leftmost set bit ; If n is of the form 2 ^ x - 1 , i . e . , if n is like 1 , 3 , 7 , 15 , 31 , . . etc , then we are done . Since positions are considered starting from 0 , 1 is added to m ; update n for next recursive call ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\nunsigned int getLeftmostBit ( int n ) { int m = 0 ; while ( n > 1 ) { n = n >> 1 ; m ++ ; } return m ; } unsigned int getNextLeftmostBit ( int n , int m ) { unsigned int temp = 1 << m ; while ( n < temp ) { temp = temp >> 1 ; m -- ; } return m ; } unsigned int _countSetBits ( unsigned int n , int m ) ; unsigned int countSetBits ( unsigned int n ) { int m = getLeftmostBit ( n ) ; return _countSetBits ( n , m ) ; } unsigned int _countSetBits ( unsigned int n , int m ) { if ( n == 0 ) return 0 ; m = getNextLeftmostBit ( n , m ) ; if ( n == ( ( unsigned int ) 1 << ( m + 1 ) ) - 1 ) return ( unsigned int ) ( m + 1 ) * ( 1 << m ) ; n = n - ( 1 << m ) ; return ( n + 1 ) + countSetBits ( n ) + m * ( 1 << ( m - 1 ) ) ; } int main ( ) { int n = 17 ; printf ( \\\" Total \u2581 set \u2581 bit \u2581 count \u2581 is \u2581 % d \\\" , countSetBits ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Count set bits in an integer | C program to Count set bits in an integer ; Function to get no of set bits in binary representation of positive integer n ; Program to test function countSetBits\\nHow can the above be solved in C?\",\"targets\":\"#include \\nunsigned int countSetBits ( unsigned int n ) { unsigned int count = 0 ; while ( n ) { count += n & 1 ; n >>= 1 ; } return count ; } int main ( ) { int i = 9 ; printf ( \\\" % d \\\" , countSetBits ( i ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Pair formation such that maximum pair sum is minimized | Python 3 Program to divide the array into N pairs such that maximum pair is minimized ; After Sorting Maintain two variables i and j pointing to start and end of array Such that smallest element of array pairs with largest element ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findOptimalPairs ( arr , N ) :\\n\\tarr . sort ( reverse = False )\\n\\ti = 0\\n\\tj = N - 1\\n\\twhile ( i <= j ) :\\n\\t\\tprint ( \\\" ( \\\" , arr [ i ] , \\\" , \\\" , arr [ j ] , \\\" ) \\\" , end = \\\" \u2581 \\\" )\\n\\t\\ti += 1\\n\\t\\tj -= 1\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 9 , 6 , 5 , 1 ]\\n\\tN = len ( arr )\\n\\tfindOptimalPairs ( arr , N )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if frequency of each character is equal to its position in English Alphabet | Javascript program for the above approach ; Initialise frequency array ; Traverse the String ; Update the frequency ; Check for valid String ; If frequency is non - zero ; If freq is not equals to ( i + 1 ) , then return false ; Return true ; ; Given String str\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function checkValidString ( str ) { var freq = new Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < str . length ; i ++ ) { freq [ str [ i ] . charCodeAt ( 0 ) - \\\" \\\" . charCodeAt ( 0 ) ] ++ ; } for ( var i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] !== 0 ) { if ( freq [ i ] !== i + 1 ) { return false ; } } } return true ; } var str = \\\" \\\" ; if ( checkValidString ( str ) ) { document . write ( \\\" \\\" ) ; } else { document . write ( \\\" \\\" ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count of contiguous subarrays possible for every index by including the element at that index | C ++ program to find the number of contiguous subarrays including the element at every index of the array of size N ; Function to find the number of subarrays including the element at every index of the array ; Creating an array of size N ; The loop is iterated till half the length of the array ; Condition to avoid overwriting the middle element for the array with even length . ; Computing the number of subarrays ; The ith element from the beginning and the ending have the same number of possible subarrays ; Function to print the vector ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; vector < int > calculateWays ( int N ) { int x = 0 ; vector < int > v ; for ( int i = 0 ; i < N ; i ++ ) v . push_back ( 0 ) ; for ( int i = 0 ; i <= N \\/ 2 ; i ++ ) { if ( N % 2 == 0 && i == N \\/ 2 ) break ; x = N * ( i + 1 ) - ( i + 1 ) * i ; v [ i ] = x ; v [ N - i - 1 ] = x ; } return v ; } void printArray ( vector < int > v ) { for ( int i = 0 ; i < v . size ( ) ; i ++ ) cout << v [ i ] << \\\" \u2581 \\\" ; } int main ( ) { vector < int > v ; v = calculateWays ( 4 ) ; printArray ( v ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if factorial of N is divisible by the sum of squares of first N natural numbers | C ++ implementation of the approach ; Function to count number of times prime P divide factorial N ; Lengendre Formula ; Function to find count number of times all prime P divide summation ; Formula for summation of square after removing n and constant 6 ; Loop to traverse over all prime P which divide summation ; If Number itself is a Prime Number ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\n#define ll long long int\\nusing namespace std ; bool checkfact ( int N , int countprime , int prime ) { int countfact = 0 ; if ( prime == 2 prime == 3 ) countfact ++ ; int divide = prime ; while ( N \\/ divide != 0 ) { countfact += N \\/ divide ; divide = divide * divide ; } if ( countfact >= countprime ) return true ; else return false ; } bool check ( int N ) { int sumsquares = ( N + 1 ) * ( 2 * N + 1 ) ; int countprime = 0 ; for ( int i = 2 ; i <= sqrt ( sumsquares ) ; i ++ ) { int flag = 0 ; while ( sumsquares % i == 0 ) { flag = 1 ; countprime ++ ; sumsquares \\/= i ; } if ( flag ) { if ( ! checkfact ( N - 1 , countprime , i ) ) return false ; countprime = 0 ; } } if ( sumsquares != 1 ) if ( ! checkfact ( N - 1 , 1 , sumsquares ) ) return false ; return true ; } int main ( ) { int N = 5 ; if ( check ( N ) ) cout << \\\" Yes \\\" ; else cout << \\\" No \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Queries to find the count of shortest paths in a Tree that contains a given edge | C ++ implementation for the above approach ; Adjacency list to represent the tree ; Number of vertices ; Mark visited \\/ unvisited vertices ; Stores the subtree size of the corresponding nodes ; Function to create an edge between two vertices ; Add a to b 's list ; Add b to a 's list ; Function to perform DFS ; Mark the vertex visited ; Include the node in the subtree ; Traverse all its children ; Function to print the required number of paths ; Driver Code ; Number of vertices ; Calling modified dfs function ; Count pairs of vertices in the tree\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; const int sz = 1e5 ; vector < int > tree [ sz ] ; int n ; bool vis [ sz ] ; int subtreeSize [ sz ] ; void addEdge ( int a , int b ) { tree [ a ] . push_back ( b ) ; tree [ b ] . push_back ( a ) ; } void dfs ( int x ) { vis [ x ] = true ; subtreeSize [ x ] = 1 ; for ( auto i : tree [ x ] ) { if ( ! vis [ i ] ) { dfs ( i ) ; subtreeSize [ x ] += subtreeSize [ i ] ; } } } void countPairs ( int a , int b ) { int sub = min ( subtreeSize [ a ] , subtreeSize [ b ] ) ; cout << sub * ( n - sub ) << endl ; } int main ( ) { n = 6 ; addEdge ( 0 , 1 ) ; addEdge ( 0 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 3 , 4 ) ; addEdge ( 3 , 5 ) ; dfs ( 0 ) ; countPairs ( 1 , 3 ) ; countPairs ( 0 , 2 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimize cost to empty given array where cost of removing an element is its absolute difference with Time instant | Python3 program for the above approach ; Function to find the minimum cost to delete all array elements ; Sort the input array ; Store the maximum time to delete the array in the worst case ; Store the result in cost [ ] [ ] table ; Base Case ; Store the minimum of all cost values of the previous index ; Iterate from range [ 1 , n ] using variable i ; Update prev ; Iterate from range [ 1 , m ] using variable j ; Update cost [ i ] [ j ] ; Update the prev ; Store the minimum cost to delete all elements ; Find the minimum of all values of cost [ n ] [ j ] ; Print minimum cost ; Driver Code ; Function Call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"INF = 10000\\ndef minCost ( arr , n ) :\\n\\tarr = sorted ( arr )\\n\\tm = 2 * n\\n\\tcost = [ [ INF for i in range ( m + 1 ) ] for i in range ( n + 1 ) ]\\n\\tcost [ 0 ] [ 0 ] = 0\\n\\tprev = 0\\n\\tfor i in range ( 1 , n + 1 ) :\\n\\t\\tprev = cost [ i - 1 ] [ 0 ]\\n\\t\\tfor j in range ( 1 , m + 1 ) :\\n\\t\\t\\tcost [ i ] [ j ] = min ( cost [ i ] [ j ] , prev + abs ( j - arr [ i - 1 ] ) )\\n\\t\\t\\tprev = min ( prev , cost [ i - 1 ] [ j ] )\\n\\tminCost = INF\\n\\tfor j in range ( 1 , m + 1 ) :\\n\\t\\tminCost = min ( minCost , cost [ n ] [ j ] )\\n\\tprint ( minCost )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 4 , 2 , 4 , 4 , 5 , 2 ]\\n\\tN = len ( arr )\\n\\tminCost ( arr , N )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sort an array according to count of set bits | a utility function that returns total set bits count in an integer ; Function to simultaneously sort both arrays using insertion sort ( https : www . geeksforgeeks . org \\/ insertion - sort \\/ ) ; use 2 keys because we need to sort both arrays simultaneously ; Move elements of arr [ 0. . i - 1 ] and aux [ 0. . i - 1 ] , such that elements of aux [ 0. . i - 1 ] are greater than key1 , to one position ahead of their current position ; Function to sort according to bit count using an auxiliary array ; Create an array and store count of set bits in it . ; Sort arr [ ] according to values in aux [ ] ; Utility function to print an array ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function countBits ( a ) { let count = 0 ; while ( a > 0 ) { if ( ( a & 1 ) > 0 ) count += 1 ; a = a >> 1 ; } return count ; } function insertionSort ( arr , aux , n ) { for ( let i = 1 ; i < n ; i ++ ) { let key1 = aux [ i ] ; let key2 = arr [ i ] ; let j = i - 1 ; while ( j >= 0 && aux [ j ] < key1 ) { aux [ j + 1 ] = aux [ j ] ; arr [ j + 1 ] = arr [ j ] ; j = j - 1 ; } aux [ j + 1 ] = key1 ; arr [ j + 1 ] = key2 ; } } function sortBySetBitCount ( arr , n ) { let aux = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) aux [ i ] = countBits ( arr [ i ] ) ; insertionSort ( arr , aux , n ) ; } function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + \\\" \\\" ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; sortBySetBitCount ( arr , n ) ; printArr ( arr , n ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"k | PHP program to find k - th element in the Odd - Even sequence . ; insert all the odd numbers from 1 to n . ; insert all the even numbers from 1 to n . ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findK ( $ n , $ k ) { $ a ; $ index = 0 ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) if ( $ i % 2 == 1 ) $ a [ $ index ++ ] = $ i ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) if ( $ i % 2 == 0 ) $ a [ $ index ++ ] = $ i ; return ( $ a [ $ k - 1 ] ) ; } $ n = 10 ; $ k = 3 ; echo findK ( $ n , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"All about Bit Manipulation | Function to clear the ith bit of the given number N ; Create the mask for the ith bit unset ; Return the update value\\\"\\nSolution in C++:\",\"targets\":\"int clearBit ( int num , int i ) { int mask = ~ ( 1 << i ) ; return num & mask ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if Decimal representation of an Octal number is divisible by 7 | C # program to check if Decimal representation of an Octal number is divisible by 7 or not ; Function to check Divisibility ; Sum of all individual digits ; Condition ; Driver Code ; Octal number\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int check ( int n ) { int sum = 0 ; while ( n != 0 ) { sum += n % 10 ; n = n \\/ 10 ; } if ( sum % 7 == 0 ) return 1 ; else return 0 ; } public static void Main ( String [ ] args ) { int n = 25 ; String s = ( check ( n ) == 1 ) ? \\\" YES \\\" : \\\" NO \\\" ; Console . WriteLine ( s ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sentinel Linear Search | Function to search x in the given array ; Last element of the array ; Element to be searched is placed at the last index ; Put the last element back ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function sentinelSearch ( arr , n , key ) { var last = arr [ n - 1 ] ; arr [ n - 1 ] = key ; var i = 0 ; while ( arr [ i ] != key ) i ++ ; arr [ n - 1 ] = last ; if ( ( i < n - 1 ) || ( arr [ n - 1 ] == key ) ) document . write ( key + \\\" \\\" + i ) ; else document . write ( \\\" \\\" ) ; } var arr = [ 10 , 20 , 180 , 30 , 60 , 50 , 110 , 100 , 70 ] ; var n = arr . length ; var key = 180 ; sentinelSearch ( arr , n , key ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximize a given unsigned number number by swapping bits at it 's extreme positions. | Java program to find maximum number by swapping extreme bits . ; Traverse bits from both extremes ; Obtaining i - th and j - th bits ; Swapping the bits if lesser significant is greater than higher significant bit and accordingly modifying the number ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int findMax ( int num ) { byte size_of_int = 4 ; int num_copy = num ; int j = size_of_int * 8 - 1 ; int i = 0 ; while ( i < j ) { int m = ( num_copy >> i ) & 1 ; int n = ( num_copy >> j ) & 1 ; if ( m > n ) { int x = ( 1 << i 1 << j ) ; num = num ^ x ; } i ++ ; j -- ; } return num ; } static public void main ( String [ ] args ) { int num = 4 ; System . out . println ( findMax ( num ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Reduce a given number to form a key by the given operations | C ++ program of the above approach ; Function to find the key of the given number ; Convert the integer to String ; Iterate the num - string to get the result ; Check if digit is even or odd ; Iterate until odd sum is obtained by adding consecutive digits ; Check if sum becomes odd ; Add the result in ans ; Assign the digit index to num string ; If the number is odd ; Iterate until odd sum is obtained by adding consecutive digits ; Check if sum becomes even ; Add the result in ans ; assign the digit index to main numstring ; Check if all digits are visited or not ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int key ( int N ) { string num = \\\" \\\" + to_string ( N ) ; int ans = 0 ; int j = 0 ; for ( j = 0 ; j < num . length ( ) ; j ++ ) { if ( ( num [ j ] - 48 ) % 2 == 0 ) { int add = 0 ; int i ; for ( i = j ; j < num . length ( ) ; j ++ ) { add += num [ j ] - 48 ; if ( add % 2 == 1 ) break ; } if ( add == 0 ) { ans *= 10 ; } else { int digit = ( int ) floor ( log10 ( add ) + 1 ) ; ans *= ( pow ( 10 , digit ) ) ; ans += add ; } i = j ; } else { int add = 0 ; int i ; for ( i = j ; j < num . length ( ) ; j ++ ) { add += num [ j ] - 48 ; if ( add % 2 == 0 ) { break ; } } if ( add == 0 ) { ans *= 10 ; } else { int digit = ( int ) floor ( log10 ( add ) + 1 ) ; ans *= ( pow ( 10 , digit ) ) ; ans += add ; } i = j ; } } if ( j + 1 >= num . length ( ) ) { return ans ; } else { return ans += num [ num . length ( ) - 1 ] - 48 ; } } int main ( ) { int N = 1667848271 ; cout << key ( N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to reach the nth stair using step 1 , 2 or 3 | A Java program to count number of ways to reach nth stair when ; A recursive function used by countWays ; Declaring three variables and holding the ways for first three stairs ; Fourth variable ; Starting from 4 as already counted for 3 stairs ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int countWays ( int n ) { int a = 1 , b = 2 , c = 4 ; int d = 0 ; if ( n == 0 n == 1 n == 2 ) return n ; if ( n == 3 ) return c ; for ( int i = 4 ; i <= n ; i ++ ) { d = c + b + a ; a = b ; b = c ; c = d ; } return d ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( countWays ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Compare two strings considering only alphanumeric characters | Java implementation of the approach ; Function to check alphanumeric equality of both strings ; variable declaration ; Length of first string ; Length of second string ; To check each and every characters of both string ; If the current character of the first string is not an alphanumeric character , increase the pointer i ; If the current character of the second string is not an alphanumeric character , increase the pointer j ; if all alphanumeric characters of both strings are same then return true ; if any alphanumeric characters of both strings are not same then return false ; If current character matched , increase both pointers to check the next character ; If not same , then return false ; Function to print Equal or Unequal if strings are same or not ; check alphanumeric equality of both strings ; if both are alphanumeric equal , print Equal ; otherwise print Unequal ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static boolean CompareAlphanumeric ( char [ ] str1 , char [ ] str2 ) { int i , j ; i = 0 ; j = 0 ; int len1 = str1 . length ; int len2 = str2 . length ; while ( i <= len1 && j <= len2 ) { while ( i < len1 && ( ! ( ( str1 [ i ] >= ' a ' && str1 [ i ] <= ' z ' ) || ( str1 [ i ] >= ' A ' && str1 [ i ] <= ' Z ' ) || ( str1 [ i ] >= '0' && str1 [ i ] <= '9' ) ) ) ) { i ++ ; } while ( j < len2 && ( ! ( ( str2 [ j ] >= ' a ' && str2 [ j ] <= ' z ' ) || ( str2 [ j ] >= ' A ' && str2 [ j ] <= ' Z ' ) || ( str2 [ j ] >= '0' && str2 [ j ] <= '9' ) ) ) ) { j ++ ; } if ( i == len1 && j == len2 ) { return true ; } else if ( str1 [ i ] != str2 [ j ] ) { return false ; } else { i ++ ; j ++ ; } } return false ; } static void CompareAlphanumericUtil ( String str1 , String str2 ) { boolean res ; res = CompareAlphanumeric ( str1 . toCharArray ( ) , str2 . toCharArray ( ) ) ; if ( res == true ) { System . out . println ( \\\" Equal \\\" ) ; } else { System . out . println ( \\\" Unequal \\\" ) ; } } public static void main ( String [ ] args ) { String str1 , str2 ; str1 = \\\" Ram , \u2581 Shyam \\\" ; str2 = \\\" \u2581 Ram \u2581 - \u2581 Shyam . \\\" ; CompareAlphanumericUtil ( str1 , str2 ) ; str1 = \\\" abc123\\\" ; str2 = \\\"123abc \\\" ; CompareAlphanumericUtil ( str1 , str2 ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check whether given string can be generated after concatenating given strings | C ++ implementation of the approach ; Function that return true if pre is a prefix of str ; While there are characters to match ; If characters differ at any position ; str starts with pre ; Function that return true if suff is a suffix of str ; While there are characters to match ; If characters differ at any position ; str ends with suff ; Function that returns true if str = a + b or str = b + a ; str cannot be generated by concatenating a and b ; If str starts with a i . e . a is a prefix of str ; Check if the rest of the characters are equal to b i . e . b is a suffix of str ; If str starts with b i . e . b is a prefix of str ; Check if the rest of the characters are equal to a i . e . a is a suffix of str ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool startsWith ( string str , string pre ) { int strLen = str . length ( ) ; int preLen = pre . length ( ) ; int i = 0 , j = 0 ; while ( i < strLen && j < preLen ) { if ( str [ i ] != pre [ j ] ) return false ; i ++ ; j ++ ; } return true ; } bool endsWith ( string str , string suff ) { int i = str . length ( ) - 0 ; int j = suff . length ( ) - 0 ; while ( i >= 0 && j >= 0 ) { if ( str [ i ] != suff [ j ] ) return false ; i -- ; j -- ; } return true ; } bool checkString ( string str , string a , string b ) { if ( str . length ( ) != a . length ( ) + b . length ( ) ) return false ; if ( startsWith ( str , a ) ) { if ( endsWith ( str , b ) ) return true ; } if ( startsWith ( str , b ) ) { if ( endsWith ( str , a ) ) return true ; } return false ; } int main ( ) { string str = \\\" GeeksforGeeks \\\" ; string a = \\\" Geeksfo \\\" ; string b = \\\" rGeeks \\\" ; if ( checkString ( str , a , b ) ) cout << \\\" Yes \\\" ; else cout << \\\" No \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimum cost of purchasing at least X chocolates | C ++ program for the above approach ; Function to calculate minimum cost of buying least X chocolates ; Base Case ; Include the i - th box ; Exclude the i - th box ; Return the minimum of the above two cases ; Driver Code ; Given array and value of X ; Store the size of the array ; Print the answer\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int findMinCost ( pair < int , int > arr [ ] , int X , int n , int i = 0 ) { if ( X <= 0 ) return 0 ; if ( i >= n ) return INT_MAX ; int inc = findMinCost ( arr , X - arr [ i ] . first , n , i + 1 ) ; if ( inc != INT_MAX ) inc += arr [ i ] . second ; int exc = findMinCost ( arr , X , n , i + 1 ) ; return min ( inc , exc ) ; } int main ( ) { pair < int , int > arr [ ] = { { 4 , 3 } , { 3 , 2 } , { 2 , 4 } , { 1 , 3 } , { 4 , 2 } } ; int X = 7 ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int ans = findMinCost ( arr , X , n ) ; if ( ans != INT_MAX ) cout << ans ; else cout << -1 ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum area of quadrilateral | CPP program to find maximum are of a quadrilateral ; Calculating the semi - perimeter of the given quadrilateral ; Applying Brahmagupta 's formula to get maximum area of quadrilateral ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\ndouble maxArea ( double a , double b , double c , double d ) { double semiperimeter = ( a + b + c + d ) \\/ 2 ; return sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ; } int main ( ) { double a = 1 , b = 2 , c = 1 , d = 2 ; printf ( \\\" % .2f \\n \\\" , maxArea ( a , b , c , d ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Write a program to reverse digits of a number | C program to reverse digits of a number ; Recursive function to reverse digits of num ; Driver program to test reversDigits\\nHow can the above be solved in C?\",\"targets\":\"#include ; int reversDigits ( int num ) { static int rev_num = 0 ; static int base_pos = 1 ; if ( num > 0 ) { reversDigits ( num \\/ 10 ) ; rev_num += ( num % 10 ) * base_pos ; base_pos *= 10 ; } return rev_num ; } int main ( ) { int num = 4562 ; printf ( \\\" Reverse \u2581 of \u2581 no . \u2581 is \u2581 % d \\\" , reversDigits ( num ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Biggest Reuleaux Triangle within a Square which is inscribed within a Circle | Java Program to find the biggest Reuleaux triangle inscribed within in a square which in turn is inscribed within a circle ; Function to find the Area of the Reuleaux triangle ; radius cannot be negative ; Area of the Reuleaux triangle ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static double ReuleauxArea ( double r ) { if ( r < 0 ) return - 1 ; double A = 0.70477 * 2 * Math . pow ( r , 2 ) ; return A ; } public static void main ( String args [ ] ) { double r = 6 ; System . out . println ( ReuleauxArea ( r ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximum equlibrium sum in an array | CPP program to find maximum equilibrium sum . ; Function to find maximum equilibrium sum . ; Array to store prefix sum . ; Array to store suffix sum . ; Variable to store maximum sum . ; Calculate prefix sum . ; Calculate suffix sum and compare it with prefix sum . Update ans accordingly . ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int findMaxSum ( int arr [ ] , int n ) { int preSum [ n ] ; int suffSum [ n ] ; int ans = INT_MIN ; preSum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) preSum [ i ] = preSum [ i - 1 ] + arr [ i ] ; suffSum [ n - 1 ] = arr [ n - 1 ] ; if ( preSum [ n - 1 ] == suffSum [ n - 1 ] ) ans = max ( ans , preSum [ n - 1 ] ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) { suffSum [ i ] = suffSum [ i + 1 ] + arr [ i ] ; if ( suffSum [ i ] == preSum [ i ] ) ans = max ( ans , preSum [ i ] ) ; } return ans ; } int main ( ) { int arr [ ] = { -2 , 5 , 3 , 1 , 2 , 6 , -4 , 2 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << findMaxSum ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if at least half array is reducible to zero by performing some operations | Function to print the desired result after computation ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def isHalfReducible ( arr , n , m ) :\\n\\tfrequencyHash = [ 0 ] * ( m + 1 ) ;\\n\\ti = 0 ;\\n\\twhile ( i < n ) :\\n\\t\\tfrequencyHash [ ( arr [ i ] % ( m + 1 ) ) ] += 1 ;\\n\\t\\ti += 1 ;\\n\\ti = 0 ;\\n\\twhile ( i <= m ) :\\n\\t\\tif ( frequencyHash [ i ] >= ( n \\/ 2 ) ) :\\n\\t\\t\\tbreak ;\\n\\t\\ti += 1 ;\\n\\tif ( i <= m ) :\\n\\t\\tprint ( \\\" Yes \\\" ) ;\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" ) ;\\narr = [ 8 , 16 , 32 , 3 , 12 ] ;\\nn = len ( arr ) ;\\nm = 7 ;\\nisHalfReducible ( arr , n , m ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Probability for three randomly chosen numbers to be in AP | function to calculate probability ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function procal ( n ) { return ( 3.0 * n ) \\/ ( 4.0 * ( n * n ) - 1 ) ; } let a = [ 1 , 2 , 3 , 4 , 5 ] ; let n = a . length ; document . write ( procal ( n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"Segregate 0 s and 1 s in an array | C program to sort a binary array in one pass ; Function to put all 0 s on left and all 1 s on right ; Initialize left and right indexes ; Increment left index while we see 0 at left ; Decrement right index while we see 1 at right ; If left is smaller than right then there is a 1 at left and a 0 at right . Exchange arr [ left ] and arr [ right ] ; driver program to test\\nHow can the above be solved in C?\",\"targets\":\"#include \\nvoid segregate0and1 ( int arr [ ] , int size ) { int left = 0 , right = size - 1 ; while ( left < right ) { while ( arr [ left ] == 0 && left < right ) left ++ ; while ( arr [ right ] == 1 && left < right ) right -- ; if ( left < right ) { arr [ left ] = 0 ; arr [ right ] = 1 ; left ++ ; right -- ; } } } int main ( ) { int arr [ ] = { 0 , 1 , 0 , 1 , 1 , 1 } ; int i , arr_size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; segregate0and1 ( arr , arr_size ) ; printf ( \\\" Array \u2581 after \u2581 segregation \u2581 \\\" ) ; for ( i = 0 ; i < 6 ; i ++ ) printf ( \\\" % d \u2581 \\\" , arr [ i ] ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximize count of Decreasing Consecutive Subsequences from an Array | Function to find the maximum number number of required subsequences ; Dictionary to store number of arrows available with height of arrow as key ; Stores the maximum count of possible subsequences ; Stores the count of possible subsequences ; Check if i - th element can be part of any of the previous subsequence ; Count of subsequences possible with arr [ i ] as the next element ; If more than one such subsequence exists ; Include arr [ i ] in a subsequence ; Otherwise ; Increase count of subsequence possible with arr [ i ] - 1 as the next element ; Start a new subsequence ; Increase count of subsequence possible with arr [ i ] - 1 as the next element ; Return the answer ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function maxSubsequences ( arr , n ) { let map = new Map ( ) ; let maxCount = 0 ; let count ; for ( let i = 0 ; i < n ; i ++ ) { if ( map . has ( arr [ i ] ) ) { count = map [ arr [ i ] ] ; if ( count > 1 ) { map . add ( arr [ i ] , count - 1 ) ; } else map . delete ( arr [ i ] ) ; if ( arr [ i ] - 1 > 0 ) if ( map . has ( arr [ i ] - 1 ) ) map [ arr [ i ] - 1 ] ++ ; else map . set ( arr [ i ] - 1 , 1 ) ; } else { maxCount ++ ; if ( arr [ i ] - 1 > 0 ) if ( map . has ( arr [ i ] - 1 ) ) map [ arr [ i ] - 1 ] ++ ; else map . set ( arr [ i ] - 1 , 1 ) ; } } return maxCount ; } let n = 5 ; let arr = [ 4 , 5 , 2 , 1 , 4 ] ; document . write ( maxSubsequences ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find numbers a and b that satisfy the given conditions | C # implementation of the above approach ; Function to print the required numbers ; Suppose b = n and we want a % b = 0 and also ( a \\/ b ) < n so a = b * ( n - 1 ) ; Special case if n = 1 we get a = 0 so ( a * b ) < n ; If no pair satisfies the conditions ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void find ( int n ) { int b = n ; int a = b * ( n - 1 ) ; if ( a * b > n && a \\/ b < n ) { Console . Write ( \\\" a \u2581 = \u2581 \\\" + a + \\\" , \u2581 b \u2581 = \u2581 \\\" + b ) ; } else Console . WriteLine ( - 1 ) ; } public static void Main ( ) { int n = 10 ; find ( n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Probability of A winning the match when individual probabilities of hitting the target given | Function to return the probability of A winning ; p and q store the values of fractions a \\/ b and c \\/ d ; To store the winning probability of A ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def getProbability ( a , b , c , d ) :\\n\\tp = a \\/ b ;\\n\\tq = c \\/ d ;\\n\\tans = p * ( 1 \\/ ( 1 - ( 1 - q ) * ( 1 - p ) ) ) ;\\n\\treturn round ( ans , 5 ) ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\ta = 1 ; b = 2 ; c = 10 ; d = 11 ;\\n\\tprint ( getProbability ( a , b , c , d ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"Count ways to reach the nth stair using step 1 , 2 or 3 | A C program to count number of ways to reach n 't stair when ; A recursive function used by countWays ; Driver program to test above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint countWays ( int n ) { int res [ n + 1 ] ; res [ 0 ] = 1 ; res [ 1 ] = 1 ; res [ 2 ] = 2 ; for ( int i = 3 ; i <= n ; i ++ ) res [ i ] = res [ i - 1 ] + res [ i - 2 ] + res [ i - 3 ] ; return res [ n ] ; } int main ( ) { int n = 4 ; printf ( \\\" % d \\\" , countWays ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Given an array arr [ ] , find the maximum j | CPP program for the above approach ; For a given array arr [ ] , returns the maximum j a i such that arr [ j ] > arr [ i ] ; Driver program to test above functions\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int maxIndexDiff ( int arr [ ] , int n ) { int maxDiff = -1 ; int i , j ; for ( i = 0 ; i < n ; ++ i ) { for ( j = n - 1 ; j > i ; -- j ) { if ( arr [ j ] > arr [ i ] && maxDiff < ( j - i ) ) maxDiff = j - i ; } } return maxDiff ; } int main ( ) { int arr [ ] = { 9 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 18 , 0 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int maxDiff = maxIndexDiff ( arr , n ) ; cout << \\\" \\n \\\" << maxDiff ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum element between two nodes of BST | C # program to find maximum element in the path between two Nodes of Binary Search Tree . ; Create and return a pointer of new Node . ; Insert a new Node in Binary Search Tree . ; Return the maximum element between a Node and its given ancestor . ; Traversing the path between ansector and Node and finding maximum element . ; Return maximum element in the path between two given Node of BST . ; Finding the LCA of Node x and Node y ; Checking if both the Node lie on the left side of the parent p . ; Checking if both the Node lie on the right side of the parent p . ; Return the maximum of maximum elements occur in path from ancestor to both Node . ; Driver Code ; Creating the root of Binary Search Tree ; Inserting Nodes in Binary Search Tree\\\"\\nSolution in C#:\",\"targets\":\"public class Solution { public class Node { public Node left , right ; public int data ; } public static Node createNode ( int x ) { Node p = new Node ( ) ; p . data = x ; p . left = p . right = null ; return p ; } public static void insertNode ( Node root , int x ) { Node p = root , q = null ; while ( p != null ) { q = p ; if ( p . data < x ) { p = p . right ; } else { p = p . left ; } } if ( q == null ) { p = createNode ( x ) ; } else { if ( q . data < x ) { q . right = createNode ( x ) ; } else { q . left = createNode ( x ) ; } } } public static int maxelpath ( Node q , int x ) { Node p = q ; int mx = - 1 ; while ( p . data != x ) { if ( p . data > x ) { mx = Math . Max ( mx , p . data ) ; p = p . left ; } else { mx = Math . Max ( mx , p . data ) ; p = p . right ; } } return Math . Max ( mx , x ) ; } public static int maximumElement ( Node root , int x , int y ) { Node p = root ; while ( ( x < p . data && y < p . data ) || ( x > p . data && y > p . data ) ) { if ( x < p . data && y < p . data ) { p = p . left ; } else if ( x > p . data && y > p . data ) { p = p . right ; } } return Math . Max ( maxelpath ( p , x ) , maxelpath ( p , y ) ) ; } public static void Main ( string [ ] args ) { int [ ] arr = new int [ ] { 18 , 36 , 9 , 6 , 12 , 10 , 1 , 8 } ; int a = 1 , b = 10 ; int n = arr . Length ; Node root = createNode ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { insertNode ( root , arr [ i ] ) ; } Console . WriteLine ( maximumElement ( root , a , b ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Exponential factorial of N | Function to find exponential factorial of a given number ; Stores the exponetial factor of N ; Iterare over the range [ 2 , N ] ; Update res ; Return res ; Input ; Function call\\\"\\nSolution in Javascript:\",\"targets\":\"function ExpoFactorial ( N ) { let res = 1 ; let mod = 1000000007 ; for ( let i = 2 ; i < N + 1 ; i ++ ) res = Math . pow ( i , res ) % mod ; return res ; } let N = 4 ; document . write ( ( ExpoFactorial ( N ) ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Indexed Sequential Search | C # program for Indexed Sequential Search ; Storing element ; Storing the index ; Driver code ; Element to search ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void indexedSequentialSearch ( int [ ] arr , int n , int k ) { int [ ] elements = new int [ 20 ] ; int [ ] indices = new int [ 20 ] ; int i ; int j = 0 , ind = 0 , start = 0 , end = 0 , set = 0 ; for ( i = 0 ; i < n ; i += 3 ) { elements [ ind ] = arr [ i ] ; indices [ ind ] = i ; ind ++ ; } if ( k < elements [ 0 ] ) { Console . Write ( \\\" Not \u2581 found \\\" ) ; return ; } else { for ( i = 1 ; i <= ind ; i ++ ) if ( k <= elements [ i ] ) { start = indices [ i - 1 ] ; set = 1 ; end = indices [ i ] ; break ; } } if ( set == 0 ) { start = indices [ i - 1 ] ; end = n - 1 ; } for ( i = start ; i <= end ; i ++ ) { if ( k == arr [ i ] ) { j = 1 ; break ; } } if ( j == 1 ) Console . WriteLine ( \\\" Found \u2581 at \u2581 index \u2581 \\\" + i ) ; else Console . WriteLine ( \\\" Not \u2581 found \\\" ) ; } public static void Main ( ) { int [ ] arr = { 6 , 7 , 8 , 9 , 10 } ; int n = arr . Length ; int k = 8 ; indexedSequentialSearch ( arr , n , k ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Program to check if N is a Hendecagonal Number | Java program for the above approach ; Function to check if N is a hendecagonal number ; Condition to check if the number is a hendecagonal number ; Driver code ; Given number ; Function call\\\"\\nSolution in Java:\",\"targets\":\"import java . lang . Math ; class GFG { public static boolean ishendecagonal ( int N ) { double n = ( 7 + Math . sqrt ( 72 * N + 49 ) ) \\/ 18 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 11 ; if ( ishendecagonal ( N ) ) { System . out . println ( \\\" Yes \\\" ) ; } else { System . out . println ( \\\" No \\\" ) ; } } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find a triplet ( A , B , C ) such that 3 * A + 5 * B + 7 * C is equal to N | Function to find a triplet ( A , B , C ) such that 3 * A + 5 * B + 7 * C is N ; Iterate over the range [ 0 , N7 ] ; Iterate over the range [ 0 , N5 ] ; Find the value of A ; If A is greater than or equal to 0 and divisible by 3 ; Otherwise , print - 1 ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def CalculateValues ( N ) :\\n\\tfor C in range ( 0 , N \\/\\/ 7 + 1 ) :\\n\\t\\tfor B in range ( 0 , N \\/\\/ 5 + 1 ) :\\n\\t\\t\\tA = N - 7 * C - 5 * B\\n\\t\\t\\tif ( A >= 0 and A % 3 == 0 ) :\\n\\t\\t\\t\\tprint ( \\\" A \u2581 = \\\" , A \\/ 3 , \\\" , \u2581 B \u2581 = \\\" , B , \\\" , \u2581 \\\\ \u2581 C \u2581 = \\\" , C , sep = \\\" \u2581 \\\" )\\n\\t\\t\\t\\treturn\\n\\tprint ( - 1 )\\n\\treturn\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 19\\n\\tCalculateValues ( 19 )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Print all possible combinations of r elements in a given array of size n | C # program to print all combination of size r in an array of size n ; The main function that prints all combinations of size r in arr [ ] of size n . This function mainly uses combinationUtil ( ) ; A temporary array to store all combination one by one ; Print all combination using temprary array ' data [ ] ' ; arr [ ] -- -> Input Array data [ ] -- -> Temporary array to store current combination start & end -- -> Staring and Ending indexes in arr [ ] index -- -> Current index in data [ ] r -- -> Size of a combination to be printed ; Current combination is ready to be printed , print it ; When no more elements are there to put in data [ ] ; current is included , put next at next location ; current is excluded , replace it with next ( Note that i + 1 is passed , but index is not changed ) ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void printCombination ( int [ ] arr , int n , int r ) { int [ ] data = new int [ r ] ; combinationUtil ( arr , n , r , 0 , data , 0 ) ; } static void combinationUtil ( int [ ] arr , int n , int r , int index , int [ ] data , int i ) { if ( index == r ) { for ( int j = 0 ; j < r ; j ++ ) Console . Write ( data [ j ] + \\\" \u2581 \\\" ) ; Console . WriteLine ( \\\" \\\" ) ; return ; } if ( i >= n ) return ; data [ index ] = arr [ i ] ; combinationUtil ( arr , n , r , index + 1 , data , i + 1 ) ; combinationUtil ( arr , n , r , index , data , i + 1 ) ; } static public void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int r = 3 ; int n = arr . Length ; printCombination ( arr , n , r ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Mean of array generated by products of all pairs of the given array | Function to find the mean of pair product array of arr ; Store product of pairs ; Generate all unordered pairs ; Store product of pairs ; Size of pairArray ; Store sum of pairArray ; Stores the mean of pairArray ; Find mean of pairArray ; Return the resultant mean ; Driver Code ; Given array arr ; Function Call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def pairProductMean ( arr , N ) :\\n\\tpairArray = [ ] ;\\n\\tfor i in range ( N ) :\\n\\t\\tfor j in range ( i + 1 , N ) :\\n\\t\\t\\tpairProduct = arr [ i ] * arr [ j ] ;\\n\\t\\t\\tpairArray . append ( pairProduct ) ;\\n\\tlength = len ( pairArray ) ;\\n\\tsum = 0 ;\\n\\tfor i in range ( length ) :\\n\\t\\tsum += pairArray [ i ] ;\\n\\tmean = 0 ;\\n\\tif ( length != 0 ) :\\n\\t\\tmean = sum \\/ length ;\\n\\telse :\\n\\t\\tmean = 0 ;\\n\\treturn mean ;\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 1 , 2 , 4 , 8 ] ;\\n\\tN = len ( arr ) ;\\n\\tprint ( \\\" { 0 : . 2f } \\\" . format ( pairProductMean ( arr , N ) ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Ways to arrange Balls such that adjacent balls are of different types | Returns count of arrangements where last placed ball is ' last ' . ' last ' is 0 for ' p ' , 1 for ' q ' and 2 for ' r ' ; if number of balls of any color becomes less than 0 the number of ways arrangements is 0. ; If last ball required is of type P and the number of balls of P type is 1 while number of balls of other color is 0 the number of ways is 1. ; Same case as above for ' q ' and ' r ' ; if last ball required is P and the number of ways is the sum of number of ways to form sequence with ' p - 1' P balls , q Q Balls and r R balls ending with Q and R . ; Same as above case for ' q ' and ' r ' ; Returns count of required arrangements ; Three cases arise : Last required balls is type P Last required balls is type Q Last required balls is type R ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function countWays ( $ p , $ q , $ r , $ last ) { if ( $ p < 0 $ q < 0 $ r < 0 ) return 0 ; if ( $ p == 1 && $ q == 0 && $ r == 0 && $ last == 0 ) return 1 ; if ( $ p == 0 && $ q == 1 && $ r == 0 && $ last == 1 ) return 1 ; if ( $ p == 0 && $ q == 0 && $ r == 1 && $ last == 2 ) return 1 ; if ( $ last == 0 ) return countWays ( $ p - 1 , $ q , $ r , 1 ) + countWays ( $ p - 1 , $ q , $ r , 2 ) ; if ( $ last == 1 ) return countWays ( $ p , $ q - 1 , $ r , 0 ) + countWays ( $ p , $ q - 1 , $ r , 2 ) ; if ( $ last == 2 ) return countWays ( $ p , $ q , $ r - 1 , 0 ) + countWays ( $ p , $ q , $ r - 1 , 1 ) ; } function countUtil ( $ p , $ q , $ r ) { return countWays ( $ p , $ q , $ r , 0 ) + countWays ( $ p , $ q , $ r , 1 ) + countWays ( $ p , $ q , $ r , 2 ) ; } $ p = 1 ; $ q = 1 ; $ r = 1 ; echo ( countUtil ( $ p , $ q , $ r ) ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the smallest and second smallest elements in an array | Function to print first smallest and second smallest elements ; There should be atleast two elements ; If current element is smaller than first then update both first and second ; If arr [ i ] is in between first and second then update second ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function print2Smallest ( $ arr , $ arr_size ) { $ INT_MAX = 2147483647 ; if ( $ arr_size < 2 ) { echo ( \\\" \u2581 Invalid \u2581 Input \u2581 \\\" ) ; return ; } $ first = $ second = $ INT_MAX ; for ( $ i = 0 ; $ i < $ arr_size ; $ i ++ ) { if ( $ arr [ $ i ] < $ first ) { $ second = $ first ; $ first = $ arr [ $ i ] ; } else if ( $ arr [ $ i ] < $ second && $ arr [ $ i ] != $ first ) $ second = $ arr [ $ i ] ; } if ( $ second == $ INT_MAX ) echo ( \\\" There \u2581 is \u2581 no \u2581 second \u2581 smallest \u2581 element \\n \\\" ) ; else echo \\\" The \u2581 smallest \u2581 element \u2581 is \u2581 \\\" , $ first , \\\" \u2581 and \u2581 second \u2581 Smallest \u2581 element \u2581 is \u2581 \\\" , $ second ; } $ arr = array ( 12 , 13 , 1 , 10 , 34 , 1 ) ; $ n = count ( $ arr ) ; print2Smallest ( $ arr , $ n ) ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if a given value can be reached from another value in a Circular Queue by K | Function to return GCD of two numbers a and b ; Base Case ; Recursively Find the GCD ; Function to check of B can be reaced from A with a jump of K elements in the circular queue ; Find GCD of N and K ; If A - B is divisible by gcd then prYes ; Otherwise ; Driver Code ; Function Call\\\"\\nSolution in Python:\",\"targets\":\"def GCD ( a , b ) :\\n\\tif ( b == 0 ) :\\n\\t\\treturn a\\n\\treturn GCD ( b , a % b )\\ndef canReach ( N , A , B , K ) :\\n\\tgcd = GCD ( N , K )\\n\\tif ( abs ( A - B ) % gcd == 0 ) :\\n\\t\\tprint ( \\\" Yes \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 5\\n\\tA = 2\\n\\tB = 1\\n\\tK = 2\\n\\tcanReach ( N , A , B , K )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Convert from any base to decimal and vice versa | To return value of a char . For example , 2 is returned for '2' . 10 is returned for ' A ' , 11 for ' B ' ; Function to convert a number from given base ' b ' to decimal ; Initialize power of base ; Initialize result ; Decimal equivalent is str [ len - 1 ] * 1 + str [ len - 2 ] * base + str [ len - 3 ] * ( base ^ 2 ) + ... ; A digit in input number must be less than number 's base ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function val ( $ c ) { if ( $ c >= '0' && $ c <= '9' ) return ord ( $ c ) - ord ( '0' ) ; else return ord ( $ c ) - ord ( ' A ' ) + 10 ; } function toDeci ( $ str , $ base ) { $ len = strlen ( $ str ) ; $ power = 1 ; $ num = 0 ; for ( $ i = $ len - 1 ; $ i >= 0 ; $ i -- ) { if ( val ( $ str [ $ i ] ) >= $ base ) { print ( \\\" Invalid \u2581 Number \\\" ) ; return -1 ; } $ num += val ( $ str [ $ i ] ) * $ power ; $ power = $ power * $ base ; } return $ num ; } $ str = \\\"11A \\\" ; $ base = 16 ; print ( \\\" Decimal \u2581 equivalent \u2581 of \u2581 $ str \u2581 \\\" . \\\" in \u2581 base \u2581 $ base \u2581 is \u2581 \\\" . toDeci ( $ str , $ base ) ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count of N | C ++ program for the above approach ; Function to count N - digit numbers having absolute difference between adjacent digits in non - increasing order ; If digit = n + 1 , a valid n - digit number has been formed ; If the state has already been computed ; If the current digit is 1 , then any digit from [ 1 - 9 ] can be placed ; If the current digit is 2 , any digit from [ 0 - 9 ] can be placed ; For other digits , any digit i can be placed which satisfies abs ( prev1 - i ) <= abs ( prev1 - prev2 ) ; If absolute difference is less than or equal to diff ; Function to count N - digit numbers with absolute difference between adjacent digits in non increasing order ; Initialize dp table with - 1 ; Function Call ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int dp [ 100 ] [ 10 ] [ 10 ] ; int countOfNumbers ( int digit , int prev1 , int prev2 , int n ) { if ( digit == n + 1 ) { return 1 ; } int & val = dp [ digit ] [ prev1 ] [ prev2 ] ; if ( val != -1 ) { return val ; } val = 0 ; if ( digit == 1 ) { for ( int i = ( n == 1 ? 0 : 1 ) ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , i , prev1 , n ) ; } } else if ( digit == 2 ) { for ( int i = 0 ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , i , prev1 , n ) ; } } else { int diff = abs ( prev2 - prev1 ) ; for ( int i = 0 ; i <= 9 ; ++ i ) { if ( abs ( prev1 - i ) <= diff ) { val += countOfNumbers ( digit + 1 , i , prev1 , n ) ; } } } return val ; } int countNumbersUtil ( int N ) { memset ( dp , -1 , sizeof dp ) ; cout << countOfNumbers ( 1 , 0 , 0 , N ) ; } int main ( ) { int N = 3 ; countNumbersUtil ( N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Coin Change | DP | Recursive C program for coin change problem . ; Returns the count of ways we can sum S [ 0. . . m - 1 ] coins to get sum n ; If n is 0 then there is 1 solution ( do not include any coin ) ; If n is less than 0 then no solution exists ; If there are no coins and n is greater than 0 , then no solution exist ; count is sum of solutions ( i ) including S [ m - 1 ] ( ii ) excluding S [ m - 1 ] ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint count ( int S [ ] , int m , int n ) { if ( n == 0 ) return 1 ; if ( n < 0 ) return 0 ; if ( m <= 0 && n >= 1 ) return 0 ; return count ( S , m - 1 , n ) + count ( S , m , n - S [ m - 1 ] ) ; } int main ( ) { int i , j ; int arr [ ] = { 1 , 2 , 3 } ; int m = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" % d \u2581 \\\" , count ( arr , m , 4 ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count the subarray with sum strictly greater than the sum of remaining elements | C ++ implementation of the above approach ; Function to count the number of sub - arrays with sum strictly greater than the remaining elements of array ; For loop for beginning point of a subarray ; For loop for ending point of the subarray ; Initialise subarray_sum and remaining_sum to 0 ; For loop to calculate the sum of generated subarray ; For loop to calculate the sum remaining array element ; Checking for condition when subarray sum is strictly greater than remaining sum of array element ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int Count_subarray ( int arr [ ] , int n ) { int subarray_sum , remaining_sum , count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { subarray_sum = 0 ; remaining_sum = 0 ; for ( int k = i ; k <= j ; k ++ ) { subarray_sum += arr [ k ] ; } for ( int l = 0 ; l < i ; l ++ ) { remaining_sum += arr [ l ] ; } for ( int l = j + 1 ; l < n ; l ++ ) { remaining_sum += arr [ l ] ; } if ( subarray_sum > remaining_sum ) { count += 1 ; } } } return count ; } int main ( ) { int arr [ ] = { 10 , 9 , 12 , 6 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << Count_subarray ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if N rectangles of equal area can be formed from ( 4 * N ) integers | C ++ implementation of the approach ; Function to check whether we can make n rectangles of equal area ; Sort the array ; Find the area of any one rectangle ; Check whether we have two equal sides for each rectangle and that area of each rectangle formed is the same ; Update the answer to false if any condition fails ; If possible ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool checkRectangles ( int * arr , int n ) { bool ans = true ; sort ( arr , arr + 4 * n ) ; int area = arr [ 0 ] * arr [ 4 * n - 1 ] ; for ( int i = 0 ; i < 2 * n ; i = i + 2 ) { if ( arr [ i ] != arr [ i + 1 ] arr [ 4 * n - i - 1 ] != arr [ 4 * n - i - 2 ] arr [ i ] * arr [ 4 * n - i - 1 ] != area ) { ans = false ; break ; } } if ( ans ) return true ; return false ; } int main ( ) { int arr [ ] = { 1 , 8 , 2 , 1 , 2 , 4 , 4 , 8 } ; int n = 2 ; if ( checkRectangles ( arr , n ) ) cout << \\\" Yes \\\" ; else cout << \\\" No \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to reach a score using 1 and 2 with no consecutive 2 s | A simple recursive implementation for counting ways to reach a score using 1 and 2 with consecutive 2 allowed ; base cases ; For cases n > 2 ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int CountWays ( int n ) { if ( n == 0 ) { return 1 ; } if ( n == 1 ) { return 1 ; } if ( n == 2 ) { return 1 + 1 ; } return CountWays ( n - 1 ) + CountWays ( n - 3 ) ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( CountWays ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find number of diagonals in n sided convex polygon | Javascript function to find number of diagonals in n sided convex polygon ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function numberOfDiagonals ( n ) { return n * ( n - 3 ) \\/ 2 ; } var n = 5 ; document . write ( n + \\\" \\\" ) ; document . write ( numberOfDiagonals ( n ) + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program to add two fractions | Function to return gcd of a and b ; Function to convert the obtained fraction into it 's simplest form ; Finding gcd of both terms ; Converting both terms into simpler terms by dividing them by common factor ; Function to add two fractions ; Finding gcd of den1 and den2 ; Denominator of final fraction obtained finding LCM of den1 and den2 LCM * GCD = a * b ; Changing the fractions to have same denominator Numerator of the final fraction obtained ; Calling function to convert final fraction into it 's simplest form ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function gcd ( $ a , $ b ) { if ( $ a == 0 ) return $ b ; return gcd ( $ b % $ a , $ a ) ; } function lowest ( & $ den3 , & $ num3 ) { $ common_factor = gcd ( $ num3 , $ den3 ) ; $ den3 = ( int ) $ den3 \\/ $ common_factor ; $ num3 = ( int ) $ num3 \\/ $ common_factor ; } function addFraction ( $ num1 , $ den1 , $ num2 , $ den2 , & $ num3 , & $ den3 ) { $ den3 = gcd ( $ den1 , $ den2 ) ; $ den3 = ( $ den1 * $ den2 ) \\/ $ den3 ; $ num3 = ( $ num1 ) * ( $ den3 \\/ $ den1 ) + ( $ num2 ) * ( $ den3 \\/ $ den2 ) ; lowest ( $ den3 , $ num3 ) ; } $ num1 = 1 ; $ den1 = 500 ; $ num2 = 2 ; $ den2 = 1500 ; $ den3 ; $ num3 ; addFraction ( $ num1 , $ den1 , $ num2 , $ den2 , $ num3 , $ den3 ) ; echo $ num1 , \\\" \\/ \\\" , $ den1 , \\\" \u2581 + \u2581 \\\" , $ num2 , \\\" \\/ \\\" , $ den2 , \\\" \u2581 is \u2581 equal \u2581 to \u2581 \\\" , $ num3 , \\\" \\/ \\\" , $ den3 , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Evaluate a boolean expression represented as string | C # program to evaluate value of an expression . ; Evaluates boolean expression and returns the result ; Traverse all operands by jumping a character after every iteration . ; If operator next to current operand is AND . ; If operator next to current operand is OR . ; If operator next to current operand is XOR ( Assuming a valid input ) ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Text ; class GFG { public static int evaluateBoolExpr ( StringBuilder s ) { int n = s . Length ; for ( int i = 0 ; i < n ; i += 2 ) { if ( i + 1 < n && i + 2 < n ) { if ( s [ i + 1 ] == ' A ' ) { if ( s [ i + 2 ] == '0' s [ i ] == 0 ) { s [ i + 2 ] = '0' ; } else { s [ i + 2 ] = '1' ; } } else if ( ( i + 1 ) < n && s [ i + 1 ] == ' B ' ) { if ( s [ i + 2 ] == '1' s [ i ] == '1' ) { s [ i + 2 ] = '1' ; } else { s [ i + 2 ] = '0' ; } } else { if ( s [ i + 2 ] == s [ i ] ) { s [ i + 2 ] = '0' ; } else { s [ i + 2 ] = '1' ; } } } } return s [ n - 1 ] - '0' ; } public static void Main ( string [ ] args ) { string s = \\\"1C1B1B0A0\\\" ; StringBuilder sb = new StringBuilder ( s ) ; Console . WriteLine ( evaluateBoolExpr ( sb ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find the resulting Colour Combination | Java program to find the resultant colour combination ; Function to return Colour Combination ; Check for B * G = Y ; Check for B * Y = G ; Check for Y * G = B ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GfG { static char Colour_Combination ( String s ) { char temp = s . charAt ( 0 ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { if ( temp != s . charAt ( i ) ) { if ( ( temp == ' B ' temp == ' G ' ) && ( s . charAt ( i ) == ' G ' || s . charAt ( i ) == ' B ' ) ) temp = ' Y ' ; else if ( ( temp == ' B ' temp == ' Y ' ) && ( s . charAt ( i ) == ' Y ' || s . charAt ( i ) == ' B ' ) ) temp = ' G ' ; else temp = ' B ' ; } } return temp ; } public static void main ( String [ ] args ) { String s = \\\" GBYGB \\\" ; System . out . println ( Colour_Combination ( s ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Lexicographically smallest string of maximum length made up of first K alphabets that does not contain any repeating substring | Function to find the lexicographically smallest string of the first K lower case alphabets having unique substrings ; Stores the resultant string ; Iterate through all the characters ; Inner Loop for making pairs and adding them into string ; Adding first character so that substring consisting of the last the first alphabet is present ; Print the resultant string ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function generateString ( K ) { var s = \\\" \\\" ; for ( var i = 97 ; i < 97 + K ; i ++ ) { s = s + String . fromCharCode ( i ) ; for ( var j = i + 1 ; j < 97 + K ; j ++ ) { s += String . fromCharCode ( i ) ; s += String . fromCharCode ( j ) ; } } s += String . fromCharCode ( 97 ) ; document . write ( s ) ; } var K = 4 ; generateString ( K ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum cost to modify a string | Function to return the minimum cost ; Initialize result ; To store the frequency of characters of the string Initialize array with 0 ; Update the frequencies of the characters of the string ; Loop to check all windows from a - z where window size is K ; Starting index of window ; Ending index of window ; Check if the string contains character ; Check if the character is on left side of window find the cost of modification for character add value to count calculate nearest distance of modification ; Check if the character is on right side of window find the cost of modification for character add value to count calculate nearest distance of modification ; Find the minimum of all costs for modifying the string ; Loop to check all windows Here window contains characters before z and after z of window size K ; Starting index of window ; Ending index of window ; Check if the string contains character ; If characters are outside window find the cost for modifying character add value to count ; Find the minimum of all costs for modifying the string ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function minCost ( $ str , $ K ) { $ n = strlen ( $ str ) ; $ res = 999999999 ; $ count = 0 ; $ cnt = array_fill ( 0 , 27 , 0 ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ cnt [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) + 1 ] ++ ; for ( $ i = 1 ; $ i < ( 26 - $ K + 1 ) ; $ i ++ ) { $ a = $ i ; $ b = $ i + $ K ; $ count = 0 ; for ( $ j = 1 ; $ j <= 26 ; $ j ++ ) { if ( $ cnt [ $ j ] > 0 ) { if ( $ j >= $ a && $ j >= $ b ) $ count = $ count + ( min ( $ j - $ b , 25 - $ j + $ a + 1 ) ) * $ cnt [ $ j ] ; else if ( $ j <= $ a && $ j <= $ b ) $ count = $ count + ( min ( $ a - $ j , 25 + $ j - $ b + 1 ) ) * $ cnt [ $ j ] ; } } $ res = min ( $ res , $ count ) ; } for ( $ i = 26 - $ K + 1 ; $ i <= 26 ; $ i ++ ) { $ a = $ i ; $ b = ( $ i + $ K ) % 26 ; $ count = 0 ; for ( $ j = 1 ; $ j <= 26 ; $ j ++ ) { if ( $ cnt [ $ j ] > 0 ) { if ( $ j >= $ b and $ j <= $ a ) $ count = $ count + ( min ( $ j - $ b , $ a - $ j ) ) * $ cnt [ $ j ] ; } } $ res = min ( $ res , $ count ) ; } return $ res ; } $ str = \\\" abcdefghi \\\" ; $ K = 2 ; echo minCost ( $ str , $ K ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Queries to evaluate the given equation in a range [ L , R ] | Java Program to implement the above approach ; Function to obtain the middle index of the range ; Recursive function to get the sum of values in the given range from the array . The following are parameters for this function . st . Pointer to segment tree node . Index of current node in the segment tree ss & se . Starting and ending indexes of the segment represented by current node , i . e . , st [ node ] l & r . Starting and ending indexes of range query ; If the segment of this node lies completely within the given range ; Return maximum in the segment ; If the segment of this node lies outside the given range ; If segment of this node lies partially in the given range ; Function to return the maximum in the range from [ l , r ] ; Check for erroneous input values ; Function to conSegment Tree for the subarray [ ss . . se ] ; For a single element ; Otherwise ; Recur for left subtree ; Recur for right subtree ; Function to conSegment Tree from the given array ; Height of Segment Tree ; Maximum size of Segment Tree ; Allocate memory ; Fill the allocated memory ; Return the constructed Segment Tree ; Driver Code ; Build the Segment Tree from the given array\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static int getMid ( int s , int e ) { return s + ( e - s ) \\/ 2 ; } static int MaxUtil ( int [ ] st , int ss , int se , int l , int r , int node ) { if ( l <= ss && r >= se ) return st [ node ] ; if ( se < l ss > r ) return - 1 ; int mid = getMid ( ss , se ) ; return Math . max ( MaxUtil ( st , ss , mid , l , r , 2 * node + 1 ) , MaxUtil ( st , mid + 1 , se , l , r , 2 * node + 2 ) ) ; } static int getMax ( int [ ] st , int n , int l , int r ) { if ( l < 0 r > n - 1 l > r ) { System . out . printf ( \\\" Invalid \u2581 Input \\\" ) ; return - 1 ; } return MaxUtil ( st , 0 , n - 1 , l , r , 0 ) ; } static int constructSTUtil ( int arr [ ] , int ss , int se , int [ ] st , int si ) { if ( ss == se ) { st [ si ] = arr [ ss ] ; return arr [ ss ] ; } int mid = getMid ( ss , se ) ; st [ si ] = Math . max ( constructSTUtil ( arr , ss , mid , st , si * 2 + 1 ) , constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 ) ) ; return st [ si ] ; } static int [ ] constructST ( int arr [ ] , int n ) { int x = ( int ) ( Math . ceil ( Math . log ( n ) ) ) ; int max_size = 2 * ( int ) Math . pow ( 2 , x ) - 1 ; int [ ] st = new int [ max_size ] ; constructSTUtil ( arr , 0 , n - 1 , st , 0 ) ; return st ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 2 , 3 , 0 } ; int n = arr . length ; int [ ] st = constructST ( arr , n ) ; int [ ] [ ] Q = { { 1 , 3 } , { 0 , 2 } } ; for ( int i = 0 ; i < Q . length ; i ++ ) { int max = getMax ( st , n , Q [ i ] [ 0 ] , Q [ i ] [ 1 ] ) ; int ok = 0 ; for ( int j = 30 ; j >= 0 ; j -- ) { if ( ( max & ( 1 << j ) ) != 0 ) ok = 1 ; if ( ok <= 0 ) continue ; max |= ( 1 << j ) ; } System . out . print ( max + \\\" \u2581 \\\" ) ; } } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Find the smallest and second smallest elements in an array | C program to find smallest and second smallest elements ; For INT_MAX ; There should be atleast two elements ; If current element is smaller than first then update both first and second ; If arr [ i ] is in between first and second then update second ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nvoid print2Smallest ( int arr [ ] , int arr_size ) { int i , first , second ; if ( arr_size < 2 ) { printf ( \\\" \u2581 Invalid \u2581 Input \u2581 \\\" ) ; return ; } first = second = INT_MAX ; for ( i = 0 ; i < arr_size ; i ++ ) { if ( arr [ i ] < first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] < second && arr [ i ] != first ) second = arr [ i ] ; } if ( second == INT_MAX ) printf ( \\\" There \u2581 is \u2581 no \u2581 second \u2581 smallest \u2581 element \\n \\\" ) ; else printf ( \\\" The \u2581 smallest \u2581 element \u2581 is \u2581 % d \u2581 and \u2581 second \u2581 \\\" \\\" Smallest \u2581 element \u2581 is \u2581 % d \\n \\\" , first , second ) ; } int main ( ) { int arr [ ] = { 12 , 13 , 1 , 10 , 34 , 1 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; print2Smallest ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number which has the maximum number of distinct prime factors in the range M to N | Function to return the maximum number ; array to store the number of distinct primes ; true if index ' i ' is a prime ; initializing the number of factors to 0 and ; Used in Sieve ; condition works only when ' i ' is prime , hence for factors of all prime number , the prime status is changed to false ; Number is prime ; number of factor of a prime number is 1 ; incrementing factorCount all the factors of i ; and changing prime status to false ; Initialize the max and num ; Gets the maximum number ; Gets the maximum number ; Driver code ; Calling function\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function maximumNumberDistinctPrimeRange ( $ m , $ n ) { $ factorCount = array ( ) ; $ prime = array ( ) ; for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) { $ factorCount [ $ i ] = 0 ; $ prime [ $ i ] = true ; } for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) { if ( $ prime [ $ i ] == true ) { $ factorCount [ $ i ] = 1 ; for ( $ j = $ i * 2 ; $ j <= $ n ; $ j += $ i ) { $ factorCount [ $ j ] ++ ; $ prime [ $ j ] = false ; } } } $ max = $ factorCount [ $ m ] ; $ num = $ m ; for ( $ i = $ m ; $ i <= $ n ; $ i ++ ) { if ( $ factorCount [ $ i ] > $ max ) { $ max = $ factorCount [ $ i ] ; $ num = $ i ; } } return $ num ; } $ m = 4 ; $ n = 6 ; echo maximumNumberDistinctPrimeRange ( $ m , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if any permutation of string is a K times repeated string | Function to check that permutation of the given string is a K times repeating String ; If length of string is not divisible by K ; Frequency Array ; Initially frequency of each character is 0 ; Computing the frequency of each character in the string ; Loop to check that frequency of every character of the string is divisible by K ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def repeatingString ( s , n , k ) :\\n\\tif ( n % k != 0 ) :\\n\\t\\treturn False\\n\\tfrequency = [ 0 for i in range ( 123 ) ]\\n\\tfor i in range ( 123 ) :\\n\\t\\tfrequency [ i ] = 0\\n\\tfor i in range ( n ) :\\n\\t\\tfrequency [ s [ i ] ] += 1\\n\\trepeat = n \\/\\/ k\\n\\tfor i in range ( 123 ) :\\n\\t\\tif ( frequency [ i ] % repeat != 0 ) :\\n\\t\\t\\treturn False\\n\\treturn True\\nif __name__ == ' _ _ main _ _ ' :\\n\\ts = \\\" abcdcba \\\"\\n\\tn = len ( s )\\n\\tk = 3\\n\\tif ( repeatingString ( s , n , k ) ) :\\n\\t\\tprint ( \\\" Yes \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Length of the Longest Consecutive 1 s in Binary Representation | C ++ program to find length of the longest consecutive 1 s in binary representation of a number . ; Function to find length of the longest consecutive 1 s in binary representation of a number ; Initialize result ; Count the number of iterations to reach x = 0. ; This operation reduces length of every sequence of 1 s by one . ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int maxConsecutiveOnes ( int x ) { int count = 0 ; while ( x != 0 ) { x = ( x & ( x << 1 ) ) ; count ++ ; } return count ; } int main ( ) { cout << maxConsecutiveOnes ( 14 ) << endl ; cout << maxConsecutiveOnes ( 222 ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to make sum of odd and even indexed elements equal by removing an array element | Java program to implement the above approach ; Function to count array indices whose removal makes sum of odd and even indexed elements equal ; If size of the array is 1 ; If size of the array is 2 ; Stores sum of even - indexed elements of the given array ; Stores sum of odd - indexed elements of the given array ; Traverse the array ; If i is an even number ; Update sumEven ; If i is an odd number ; Update sumOdd ; Stores sum of even - indexed array elements till i - th index ; Stores sum of odd - indexed array elements till i - th index ; Stores count of indices whose removal makes sum of odd and even indexed elements equal ; Stores sum of even - indexed elements after removing the i - th element ; Stores sum of odd - indexed elements after removing the i - th element ; Traverse the array ; If i is an odd number ; Update currOdd ; Update newEvenSum ; Update newOddSum ; If i is an even number ; Update currEven ; Update newOddSum ; Update newEvenSum ; If newEvenSum is equal to newOddSum ; Increase the count ; If sum of even - indexed and odd - indexed elements is equal by removing the first element ; Increase the count ; If length of the array is an odd number ; If sum of even - indexed and odd - indexed elements is equal by removing the last element ; Increase the count ; If length of the array is an even number ; If sum of even - indexed and odd - indexed elements is equal by removing the last element ; Increase the count ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int cntIndexesToMakeBalance ( int arr [ ] , int n ) { if ( n == 1 ) { return 1 ; } if ( n == 2 ) return 0 ; int sumEven = 0 ; int sumOdd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { sumEven += arr [ i ] ; } else { sumOdd += arr [ i ] ; } } int currOdd = 0 ; int currEven = arr [ 0 ] ; int res = 0 ; int newEvenSum = 0 ; int newOddSum = 0 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( i % 2 != 0 ) { currOdd += arr [ i ] ; newEvenSum = currEven + sumOdd - currOdd ; newOddSum = currOdd + sumEven - currEven - arr [ i ] ; } else { currEven += arr [ i ] ; newOddSum = currOdd + sumEven - currEven ; newEvenSum = currEven + sumOdd - currOdd - arr [ i ] ; } if ( newEvenSum == newOddSum ) { res ++ ; } } if ( sumOdd == sumEven - arr [ 0 ] ) { res ++ ; } if ( n % 2 == 1 ) { if ( sumOdd == sumEven - arr [ n - 1 ] ) { res ++ ; } } else { if ( sumEven == sumOdd - arr [ n - 1 ] ) { res ++ ; } } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 1 } ; int n = arr . length ; System . out . println ( cntIndexesToMakeBalance ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sum of bit differences for numbers from 0 to N | C ++ program for the above approach ; Function to implement fast exponentiation ; Function to return the value for powers of 2 ; Function to convert N into binary ; To store binary representation ; Iterate each digit of n ; Return binary representation ; Function to find difference in bits ; Get binary representation ; total number of bit differences from 0 to N ; Iterate over each binary bit ; If current bit is '1' then add the count of current bit ; Driver Code ; Given Number ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int binpow ( int a , int b ) { int res = 1 ; while ( b ) { if ( b & 1 ) res = res * a ; a = a * a ; b \\/= 2 ; } return res ; } int find ( int x ) { if ( x == 0 ) return 0 ; int p = log2 ( x ) ; return binpow ( 2 , p + 1 ) - 1 ; } string getBinary ( int n ) { string ans = \\\" \\\" ; while ( n ) { int dig = n % 2 ; ans += to_string ( dig ) ; n \\/= 2 ; } return ans ; } int totalCountDifference ( int n ) { string ans = getBinary ( n ) ; int req = 0 ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { if ( ans [ i ] == '1' ) { req += find ( binpow ( 2 , i ) ) ; } } return req ; } int main ( ) { int N = 5 ; cout << totalCountDifference ( N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Print characters and their frequencies in order of occurrence | PHP implementation to print the character and its frequency in order of its occurrence ; function to print the character and its frequency in order of its occurrence ; size of the string ' str ' ; ' freq [ ] ' implemented as hash table ; accumulate frequency of each character in ' str ' ; traverse ' str ' from left to right ; if frequency of character str [ i ] is not equal to 0 ; print the character along with its frequency ; update frequency of str [ i ] to 0 so that the same character is not printed again ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ SIZE = 26 ; function printCharWithFreq ( $ str ) { global $ SIZE ; $ n = strlen ( $ str ) ; $ freq = array_fill ( 0 , $ SIZE , NULL ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ freq [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) ] ++ ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ freq [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) ] != 0 ) { echo $ str [ $ i ] . $ freq [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) ] . \\\" \\\" ; $ freq [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) ] = 0 ; } } } $ str = \\\" geeksforgeeks \\\" ; printCharWithFreq ( $ str ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Threaded Binary Search Tree | Deletion | ; True if left pointer points to predecessor in Inorder Traversal ; True if right pointer points to predecessor in Inorder Traversal\\\"\\nSolution in C#:\",\"targets\":\"public class Node { public Node left , right ; public int info ; public bool lthread ; public bool rthread ; } ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check if lowercase and uppercase characters are in same order | Java program to check if lowercase and uppercase characters are in same order ; Function to check if both the case follow the same order ; Traverse the string ; Store both lowercase and uppercase in two different strings ; transform lowerStr1 to upper ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"public class GFG { static boolean isCheck ( String str ) { int len = str . length ( ) ; String lowerStr = \\\" \\\" , upperStr = \\\" \\\" ; char [ ] str1 = str . toCharArray ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( ( int ) ( str1 [ i ] ) >= 65 && ( int ) str1 [ i ] <= 91 ) upperStr = upperStr + str1 [ i ] ; else lowerStr = lowerStr + str1 [ i ] ; } String transformStr = lowerStr . toUpperCase ( ) ; return ( transformStr . equals ( upperStr ) ) ; } public static void main ( String [ ] args ) { String str = \\\" geeGkEEsKS \\\" ; if ( isCheck ( str ) ) System . out . println ( \\\" Yes \\\" ) ; else System . out . println ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Threaded Binary Search Tree | Deletion | ; True if left pointer points to predecessor in Inorder Traversal ; True if right pointer points to predecessor in Inorder Traversal\\\"\\nHow can the above be solved in JS?\",\"targets\":\"class Node { constructor ( ) { this . left = null , this . right = null ; this . info = 0 ; this . lthread = false ; this . rthread = false ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Lexicographically largest possible String after removal of K characters | JavaScript program to implement the above approach ; Final result String ; If the current char exceeds the character at the top of the stack ; Remove from the end of the String ; Decrease k for the removal ; Insert current character ; Perform remaining K deletions from the end of the String ; Return the String ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function largestString ( num , k ) { var ans = \\\" \\\" ; var str = num . split ( \\\" \\\" ) ; for ( const i of str ) { while ( ans . length > 0 && ans [ ans . length - 1 ] < i && k > 0 ) { ans = ans . substring ( 0 , ans . length - 1 ) ; k -- ; } ans += i ; } while ( ans . length > 0 && k -- > 0 ) { ans = ans . substring ( 0 , ans . length - 1 ) ; } return ans ; } var str = \\\" \\\" ; var k = 1 ; document . write ( largestString ( str , k ) + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Babylonian method for square root | C # Porgram for Babylonian method of square root ; Returns the square root of n . Note that the function ; We are using n itself as initial approximation This can definitely be improved ; e decides the accuracy level ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static float squareRoot ( float n ) { float x = n ; float y = 1 ; double e = 0.000001 ; while ( x - y > e ) { x = ( x + y ) \\/ 2 ; y = n \\/ x ; } return x ; } public static void Main ( ) { int n = 50 ; Console . Write ( \\\" Square \u2581 root \u2581 of \u2581 \\\" + n + \\\" \u2581 is \u2581 \\\" + squareRoot ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Magic Square | Even Order | Java program to print Magic square of Doubly even order ; Function for calculating Magic square ; filling matrix with its count value starting from 1 ; ; change value of Array elements at fix location as per rule ( n * n + 1 ) - arr [ i ] [ j ] Top Left corner of Matrix ( order ( n \\/ 4 ) * ( n \\/ 4 ) ) ; Top Right corner of Matrix ( order ( n \\/ 4 ) * ( n \\/ 4 ) ) ; Bottom Left corner of Matrix ( order ( n \\/ 4 ) * ( n \\/ 4 ) ) ; Bottom Right corner of Matrix ( order ( n \\/ 4 ) * ( n \\/ 4 ) ) ; Centre of Matrix ( order ( n \\/ 2 ) * ( n \\/ 2 ) ) ; Printing the magic - square ; driver program ; Function call\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static void doublyEven ( int n ) { int [ ] [ ] arr = new int [ n ] [ n ] ; int i , j ; for ( i = 0 ; i < n ; i ++ ) for ( j = 0 ; j < n ; j ++ ) arr [ i ] [ j ] = ( n * i ) + j + 1 ; for ( i = 0 ; i < n \\/ 4 ; i ++ ) for ( j = 0 ; j < n \\/ 4 ; j ++ ) arr [ i ] [ j ] = ( n * n + 1 ) - arr [ i ] [ j ] ; for ( i = 0 ; i < n \\/ 4 ; i ++ ) for ( j = 3 * ( n \\/ 4 ) ; j < n ; j ++ ) arr [ i ] [ j ] = ( n * n + 1 ) - arr [ i ] [ j ] ; for ( i = 3 * n \\/ 4 ; i < n ; i ++ ) for ( j = 0 ; j < n \\/ 4 ; j ++ ) arr [ i ] [ j ] = ( n * n + 1 ) - arr [ i ] [ j ] ; for ( i = 3 * n \\/ 4 ; i < n ; i ++ ) for ( j = 3 * n \\/ 4 ; j < n ; j ++ ) arr [ i ] [ j ] = ( n * n + 1 ) - arr [ i ] [ j ] ; for ( i = n \\/ 4 ; i < 3 * n \\/ 4 ; i ++ ) for ( j = n \\/ 4 ; j < 3 * n \\/ 4 ; j ++ ) arr [ i ] [ j ] = ( n * n + 1 ) - arr [ i ] [ j ] ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) System . out . print ( arr [ i ] [ j ] + \\\" \u2581 \\\" ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { int n = 8 ; doublyEven ( n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Insertion Sort | C program for insertion sort ; Function to sort an array using insertion sort ; Move elements of arr [ 0. . i - 1 ] , that are greater than key , to one position ahead of their current position ; A utility function to print an array of size n ; Driver program to test insertion sort\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nvoid insertionSort ( int arr [ ] , int n ) { int i , key , j ; for ( i = 1 ; i < n ; i ++ ) { key = arr [ i ] ; j = i - 1 ; while ( j >= 0 && arr [ j ] > key ) { arr [ j + 1 ] = arr [ j ] ; j = j - 1 ; } arr [ j + 1 ] = key ; } } void printArray ( int arr [ ] , int n ) { int i ; for ( i = 0 ; i < n ; i ++ ) printf ( \\\" % d \u2581 \\\" , arr [ i ] ) ; printf ( \\\" \\n \\\" ) ; } int main ( ) { int arr [ ] = { 12 , 11 , 13 , 5 , 6 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; insertionSort ( arr , n ) ; printArray ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Average of a stream of numbers | ; Returns the new average after including x ; Prints average of a stream of numbers ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; float getAvg ( int x ) { static int sum , n ; sum += x ; return ( ( ( float ) sum ) \\/ ++ n ) ; } void streamAvg ( float arr [ ] , int n ) { float avg = 0 ; for ( int i = 0 ; i < n ; i ++ ) { avg = getAvg ( arr [ i ] ) ; cout << \\\" Average \u2581 of \u2581 \\\" << i + 1 << \\\" \u2581 numbers \u2581 is \u2581 \\\" << fixed << setprecision ( 1 ) << avg << endl ; } return ; } int main ( ) { float arr [ ] = { 10 , 20 , 30 , 40 , 50 , 60 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; streamAvg ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find position of left most dis | C # to find the leftmost position of first dis - similar bit ; Function to find first dis - similar bit ; return zero for equal number ; count bit length of n1 and n2 ; find bit difference and maxBit ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int bitPos ( int n1 , int n2 ) { if ( n1 == n2 ) return 0 ; int bitCount1 = ( int ) Math . Floor ( Math . Log ( n1 ) \\/ Math . Log ( 2 ) ) + 1 ; int bitCount2 = ( int ) Math . Floor ( Math . Log ( n2 ) \\/ Math . Log ( 2 ) ) + 1 ; int bitDiff = Math . Abs ( bitCount1 - bitCount2 ) ; int maxBitCount = Math . Max ( bitCount1 , bitCount2 ) ; if ( bitCount1 > bitCount2 ) { n2 = n2 * ( int ) Math . Pow ( 2 , bitDiff ) ; } else { n1 = n1 * ( int ) Math . Pow ( 2 , bitDiff ) ; } int xorValue = n1 ^ n2 ; int bitCountXorValue = ( int ) Math . Floor ( Math . Log ( xorValue ) \\/ Math . Log ( 2 ) ) + 1 ; int disSimilarBitPosition = maxBitCount - bitCountXorValue + 1 ; return disSimilarBitPosition ; } public static void Main ( ) { int n1 = 53 , n2 = 55 ; Console . Write ( bitPos ( n1 , n2 ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Space and time efficient Binomial Coefficient | Returns value of Binomial Coefficient C ( n , k ) ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] \\/ [ k * ( k - 1 ) * -- -- * 1 ] ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function binomialCoeff ( $ n , $ k ) { $ res = 1 ; if ( $ k > $ n - $ k ) $ k = $ n - $ k ; for ( $ i = 0 ; $ i < $ k ; ++ $ i ) { $ res *= ( $ n - $ i ) ; $ res \\/= ( $ i + 1 ) ; } return $ res ; } $ n = 8 ; $ k = 2 ; echo \\\" \u2581 Value \u2581 of \u2581 C \u2581 ( $ n , \u2581 $ k ) \u2581 is \u2581 \\\" , binomialCoeff ( $ n , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Sorting without comparison of elements | Represents node of a doubly linked list ; Count of elements in given range ; Count frequencies of all elements ; Traverse through range . For every element , print it its count times . ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function sortArr ( arr , n , min , max ) { let m = max - min + 1 ; let c = new Array ( m ) ; c . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { c [ arr [ i ] - min ] ++ ; } for ( let i = 0 ; i < m ; i ++ ) { for ( let j = 0 ; j < c [ i ] ; j ++ ) { document . write ( ( i + min ) + \\\" \\\" ) ; } } } let arr = [ 10 , 10 , 1 , 4 , 4 , 100 , 0 ] ; let min = 0 , max = 100 ; let n = arr . length ; sortArr ( arr , n , min , max ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Largest lexicographic triplet from a given Array that forms a triangle | Function to find lexicographically largest triplet that forms a triangle in the given array ; Sort the array ; Iterate from the end of the array ; If the triplet forms a triangle ; If triplet found ; Print the triplet ; Otherwise ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function findTriplet ( arr , N ) { arr . sort ( ( a , b ) => a - b ) ; var flag = 0 , i ; for ( i = N - 1 ; i - 2 >= 0 ; i -- ) { if ( arr [ i - 2 ] + arr [ i - 1 ] > arr [ i ] ) { flag = 1 ; break ; } } if ( flag ) { document . write ( arr [ i - 2 ] + \\\" \\\" + arr [ i - 1 ] + \\\" \\\" + arr [ i ] + \\\" \\\" ) ; } else { document . write ( - 1 + \\\" \\\" ) ; } } var arr = [ 4 , 2 , 10 , 3 , 5 ] ; var N = arr . length ; findTriplet ( arr , N ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check whether a given string is Heterogram or not | C ++ Program to check whether the given string is Heterogram or not . ; traversing the string . ; ignore the space ; if already encountered ; else return false . ; Driven Program\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool isHeterogram ( char s [ ] , int n ) { int hash [ 26 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] != ' \u2581 ' ) { if ( hash [ s [ i ] - ' a ' ] == 0 ) hash [ s [ i ] - ' a ' ] = 1 ; else return false ; } } return true ; } int main ( ) { char s [ ] = \\\" the \u2581 big \u2581 dwarf \u2581 only \u2581 jumps \\\" ; int n = strlen ( s ) ; ( isHeterogram ( s , n ) ) ? ( cout << \\\" YES \\\" ) : ( cout << \\\" NO \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum frequency of a remainder modulo 2 i | Binary representation of the digits ; Function to return the maximum frequency of s modulo with a power of 2 ; Store the binary representation ; Convert the octal to binary ; Remove the LSB ; If there is 1 in the binary representation ; Find the number of zeroes in between two 1 's in the binary representation ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"bin = [ \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" ] ; function maxFreq ( s ) { var binary = \\\" \\\" ; for ( var i = 0 ; i < s . length ; i ++ ) { binary += bin [ s . charAt ( i ) - ' ' ] ; } binary = binary . substr ( 0 , binary . length - 1 ) ; var count = 1 , prev = - 1 , i , j = 0 ; for ( i = binary . length - 1 ; i >= 0 ; i -- , j ++ ) if ( binary . charAt ( i ) == ' ' ) { count = Math . max ( count , j - prev ) ; prev = j ; } return count ; } var octal = \\\" \\\" ; document . write ( maxFreq ( octal ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Dynamic Programming | High | A naive recursive C program to find maximum tasks . ; Returns the maximum among the 2 numbers ; Returns maximum amount of task that can be done till day n ; If n is less than equal to 0 , then no solution exists ; Determines which task to choose on day n , then returns the maximum till that day ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\nint max ( int x , int y ) { return ( x > y ? x : y ) ; } int maxTasks ( int high [ ] , int low [ ] , int n ) { if ( n <= 0 ) return 0 ; return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ; } int main ( ) { int n = 5 ; int high [ ] = { 3 , 6 , 8 , 7 , 6 } ; int low [ ] = { 1 , 5 , 4 , 5 , 3 } ; printf ( \\\" % dn \\\" , maxTasks ( high , low , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if sum Y can be obtained from the Array by the given operations | Function to check if it is possible to obtain sum Y from a sequence of sum X from the array arr [ ] ; Store the difference ; Iterate over the array ; If diff reduced to 0 ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function solve ( arr , n , X , Y ) { var diff = Y - X ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != 1 ) { diff = diff % ( arr [ i ] - 1 ) ; } } if ( diff == 0 ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ; } var arr = [ 1 , 2 , 7 , 9 , 10 ] ; var n = arr . length ; var X = 11 , Y = 13 ; solve ( arr , n , X , Y ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Pascal 's Triangle | A O ( n ^ 2 ) time and O ( n ^ 2 ) extra space method for Pascal 's Triangle ; An auxiliary array to store generated pscal triangle values ; Iterate through every line and print integer ( s ) in it ; Every line has number of integers equal to line number ; First and last values in every row are 1 ; Other values are sum of values just above and left of above ; Driver code\\\"\\nSolution in C:\",\"targets\":\"void printPascal ( int n ) { int arr [ n ] [ n ] ; for ( int line = 0 ; line < n ; line ++ ) { for ( int i = 0 ; i <= line ; i ++ ) { if ( line == i i == 0 ) arr [ line ] [ i ] = 1 ; else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ; printf ( \\\" % d \u2581 \\\" , arr [ line ] [ i ] ) ; } printf ( \\\" \\n \\\" ) ; } } int main ( ) { int n = 5 ; printPascal ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Reverse words in a given string | JavaScript program to reverse a string\\\"\\nHow can the above be solved in JS?\",\"targets\":\"var s = [ \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" ] ; var ans = \\\" \\\" ; for ( var i = 5 ; i >= 0 ; i -- ) { ans += s [ i ] + \\\" \\\" ; } document . write ( \\\" \\\" + \\\" \\\" ) ; document . write ( ans . slice ( 0 , ans . length - 1 ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Coin Change | DP | Returns the count of ways we can sum S [ 0. . . m - 1 ] coins to get sum n ; If n is 0 then there is 1 solution ( do not include any coin ) ; If n is less than 0 then no solution exists ; If there are no coins and n is greater than 0 , then no solution exist ; count is sum of solutions ( i ) including S [ m - 1 ] ( ii ) excluding S [ m - 1 ] ; Driver program to test above function\\\"\\nSolution in Javascript:\",\"targets\":\"function count ( S , m , n ) { if ( n == 0 ) return 1 ; if ( n < 0 ) return 0 ; if ( m <= 0 && n >= 1 ) return 0 ; return count ( S , m - 1 , n ) + count ( S , m , n - S [ m - 1 ] ) ; } var arr = [ 1 , 2 , 3 ] ; var m = arr . length ; document . write ( count ( arr , m , 4 ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all products of the Binomial Coefficients of two numbers up to K | C # implementation of the above approach ; Function returns nCr i . e . Binomial Coefficient ; Initialize res with 1 ; Since C ( n , r ) = C ( n , n - r ) ; Evaluating expression ; Function to calculate and return the sum of the products ; Initialize sum to 0 ; Traverse from 0 to k ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int nCr ( int n , int r ) { int res = 1 ; if ( r > n - r ) r = n - r ; for ( int i = 0 ; i < r ; ++ i ) { res *= ( n - i ) ; res \\/= ( i + 1 ) ; } return res ; } static int solve ( int n , int m , int k ) { int sum = 0 ; for ( int i = 0 ; i <= k ; i ++ ) sum += nCr ( n , i ) * nCr ( m , k - i ) ; return sum ; } public static void Main ( String [ ] args ) { int n = 3 , m = 2 , k = 2 ; Console . Write ( solve ( n , m , k ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Compare two Version numbers | Java program to compare two version number ; Method to compare two versions . Returns 1 if v2 is smaller , - 1 if v1 is smaller , 0 if equal ; vnum stores each numeric part of version ; loop until both String are processed ; Storing numeric part of version 1 in vnum1 ; storing numeric part of version 2 in vnum2 ; if equal , reset variables and go for next numeric part ; Driver method to check above comparison function\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static int versionCompare ( String v1 , String v2 ) { int vnum1 = 0 , vnum2 = 0 ; for ( int i = 0 , j = 0 ; ( i < v1 . length ( ) || j < v2 . length ( ) ) ; ) { while ( i < v1 . length ( ) && v1 . charAt ( i ) != ' . ' ) { vnum1 = vnum1 * 10 + ( v1 . charAt ( i ) - '0' ) ; i ++ ; } while ( j < v2 . length ( ) && v2 . charAt ( j ) != ' . ' ) { vnum2 = vnum2 * 10 + ( v2 . charAt ( j ) - '0' ) ; j ++ ; } if ( vnum1 > vnum2 ) return 1 ; if ( vnum2 > vnum1 ) return - 1 ; vnum1 = vnum2 = 0 ; i ++ ; j ++ ; } return 0 ; } public static void main ( String [ ] args ) { String version1 = \\\"1.0.3\\\" ; String version2 = \\\"1.0.7\\\" ; if ( versionCompare ( version1 , version2 ) < 0 ) System . out . println ( version1 + \\\" \u2581 is \u2581 smaller \\\" ) ; else if ( versionCompare ( version1 , version2 ) > 0 ) System . out . println ( version2 + \\\" \u2581 is \u2581 smaller \\\" ) ; else System . out . println ( \\\" Both \u2581 version \u2581 are \u2581 equal \\\" ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Compare two strings considering only alphanumeric characters | Java implementation of the approach ; Function to check alphanumeric equality of both strings ; variable declaration ; Length of first string ; Length of second string ; To check each and every characters of both string ; If the current character of the first string is not an alphanumeric character , increase the pointer i ; If the current character of the second string is not an alphanumeric character , increase the pointer j ; if all alphanumeric characters of both strings are same then return true ; if any alphanumeric characters of both strings are not same then return false ; If current character matched , increase both pointers to check the next character ; If not same , then return false ; Function to print Equal or Unequal if strings are same or not ; check alphanumeric equality of both strings ; if both are alphanumeric equal , print Equal ; otherwise print Unequal ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static boolean CompareAlphanumeric ( char [ ] str1 , char [ ] str2 ) { int i , j ; i = 0 ; j = 0 ; int len1 = str1 . length ; int len2 = str2 . length ; while ( i <= len1 && j <= len2 ) { while ( i < len1 && ( ! ( ( str1 [ i ] >= ' a ' && str1 [ i ] <= ' z ' ) || ( str1 [ i ] >= ' A ' && str1 [ i ] <= ' Z ' ) || ( str1 [ i ] >= '0' && str1 [ i ] <= '9' ) ) ) ) { i ++ ; } while ( j < len2 && ( ! ( ( str2 [ j ] >= ' a ' && str2 [ j ] <= ' z ' ) || ( str2 [ j ] >= ' A ' && str2 [ j ] <= ' Z ' ) || ( str2 [ j ] >= '0' && str2 [ j ] <= '9' ) ) ) ) { j ++ ; } if ( i == len1 && j == len2 ) { return true ; } else if ( str1 [ i ] != str2 [ j ] ) { return false ; } else { i ++ ; j ++ ; } } return false ; } static void CompareAlphanumericUtil ( String str1 , String str2 ) { boolean res ; res = CompareAlphanumeric ( str1 . toCharArray ( ) , str2 . toCharArray ( ) ) ; if ( res == true ) { System . out . println ( \\\" Equal \\\" ) ; } else { System . out . println ( \\\" Unequal \\\" ) ; } } public static void main ( String [ ] args ) { String str1 , str2 ; str1 = \\\" Ram , \u2581 Shyam \\\" ; str2 = \\\" \u2581 Ram \u2581 - \u2581 Shyam . \\\" ; CompareAlphanumericUtil ( str1 , str2 ) ; str1 = \\\" abc123\\\" ; str2 = \\\"123abc \\\" ; CompareAlphanumericUtil ( str1 , str2 ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Number of coloured 0 's in an N | C # implementation of the approach ; Function to return the count of coloured 0 s in an n - level hexagon ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int count ( int n ) { return n * ( 3 * n - 1 ) \\/ 2 ; } public static void Main ( String [ ] args ) { int n = 3 ; Console . WriteLine ( count ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"A Sum Array Puzzle | Java implementation of above approach ; Allocate memory for temporary arrays leftSum [ ] , rightSum [ ] and Sum [ ] ; Left most element of left array is always 0 ; Right most element of right array is always 0 ; Construct the left array ; Construct the right array ; Construct the sum array using left [ ] and right [ ] ; print the sum array ; Driver function to test above function\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; import java . lang . * ; import java . io . * ; class Geeks { public static void sumArray ( int arr [ ] , int n ) { int leftSum [ ] = new int [ n ] ; int rightSum [ ] = new int [ n ] ; int Sum [ ] = new int [ n ] ; int i = 0 , j = 0 ; leftSum [ 0 ] = 0 ; rightSum [ n - 1 ] = 0 ; for ( i = 1 ; i < n ; i ++ ) leftSum [ i ] = arr [ i - 1 ] + leftSum [ i - 1 ] ; for ( j = n - 2 ; j >= 0 ; j -- ) rightSum [ j ] = arr [ j + 1 ] + rightSum [ j + 1 ] ; for ( i = 0 ; i < n ; i ++ ) Sum [ i ] = leftSum [ i ] + rightSum [ i ] ; for ( i = 0 ; i < n ; i ++ ) System . out . print ( Sum [ i ] + \\\" \u2581 \\\" ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 6 , 4 , 8 , 9 } ; int n = arr . length ; sumArray ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Decimal to Binary using recursion and without using power operator | Recursive function to convert n to its binary equivalent ; Base case ; Recursive call ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function decimalToBinary ( n ) { if ( n == 0 ) { document . write ( \\\" \\\" ) ; return ; } decimalToBinary ( parseInt ( n \\/ 2 ) ) ; document . write ( n % 2 ) ; } var n = 13 ; decimalToBinary ( n ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"Write a program to calculate pow ( x , n ) | Extended version of power function that can work for float x and negative y ; Program to test function power\\nHow can the above be solved in C?\",\"targets\":\"#include \\nfloat power ( float x , int y ) { float temp ; if ( y == 0 ) return 1 ; temp = power ( x , y \\/ 2 ) ; if ( y % 2 == 0 ) return temp * temp ; else { if ( y > 0 ) return x * temp * temp ; else return ( temp * temp ) \\/ x ; } } int main ( ) { float x = 2 ; int y = -3 ; printf ( \\\" % f \\\" , power ( x , y ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum cost to remove the spaces between characters of a String by rearranging the characters | C # program to gather characters of a string in minimum cost ; Function to calculate the minimum cost ; Stores the minimum cost ; Stores the count of characters found ; Stores the count of blank spaces found ; Stores the count of total characters ; If the count of characters is equal to 1 ; Iterate over the string ; Consider the previous character together with current character ; If not together already ; Add the cost to group them together ; Increase count of characters found ; Otherwise ; Increase count of spaces found ; Return the total cost obtained ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int min_cost ( String S ) { int cost = 0 ; int F = 0 ; int B = 0 ; int count = 0 ; foreach ( char c in S . ToCharArray ( ) ) if ( c == ' \u2581 ' ) count ++ ; int n = S . Length - count ; if ( n == 1 ) return cost ; foreach ( char inn in S . ToCharArray ( ) ) { if ( inn != ' \u2581 ' ) { if ( B != 0 ) { cost += Math . Min ( n - F , F ) * B ; B = 0 ; } F += 1 ; } else { B += 1 ; } } return cost ; } public static void Main ( String [ ] args ) { String S = \\\" \u2581 @ \\t $ \\\" ; Console . WriteLine ( min_cost ( S ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find a common element in all rows of a given row | A C program to find a common element in all rows of a row wise sorted array ; Specify number of rows and columns ; Returns common element in all rows of mat [ M ] [ N ] . If there is no common element , then - 1 is returned ; An array to store indexes of current last column ; To store index of row whose current last element is minimum ; Initialize current last element of all rows ; Initialize min_row as first row ; Keep finding min_row in current last column , till either all elements of last column become same or we hit first column . ; Find minimum in current last column ; eq_count is count of elements equal to minimum in current last column . ; Traverse current last column elements again to update it ; Decrease last column index of a row whose value is more than minimum . ; Reduce last column index by 1 ; If equal count becomes M , return the value ; driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\n#define M 4\\n#define N 5\\nint findCommon ( int mat [ M ] [ N ] ) { int column [ M ] ; int min_row ; int i ; for ( i = 0 ; i < M ; i ++ ) column [ i ] = N - 1 ; min_row = 0 ; while ( column [ min_row ] >= 0 ) { for ( i = 0 ; i < M ; i ++ ) { if ( mat [ i ] [ column [ i ] ] < mat [ min_row ] [ column [ min_row ] ] ) min_row = i ; } int eq_count = 0 ; for ( i = 0 ; i < M ; i ++ ) { if ( mat [ i ] [ column [ i ] ] > mat [ min_row ] [ column [ min_row ] ] ) { if ( column [ i ] == 0 ) return -1 ; column [ i ] -= 1 ; } else eq_count ++ ; } if ( eq_count == M ) return mat [ min_row ] [ column [ min_row ] ] ; } return -1 ; } int main ( ) { int mat [ M ] [ N ] = { { 1 , 2 , 3 , 4 , 5 } , { 2 , 4 , 5 , 8 , 10 } , { 3 , 5 , 7 , 9 , 11 } , { 1 , 3 , 5 , 7 , 9 } , } ; int result = findCommon ( mat ) ; if ( result == -1 ) printf ( \\\" No \u2581 common \u2581 element \\\" ) ; else printf ( \\\" Common \u2581 element \u2581 is \u2581 % d \\\" , result ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if a given string can be converted to another by given possible swaps | Python3 program to implement the above approach ; Stores length of str1 ; Stores length of str2 ; Stores distinct characters of str1 ; Stores distinct characters of str2 ; Stores frequency of each character of str1 ; Traverse the string str1 ; Update frequency of str1 [ i ] ; Traverse the string str1 ; Insert str1 [ i ] into st1 ; Traverse the string str2 ; Insert str1 [ i ] into st1 ; If distinct characters in str1 and str2 are not same ; Stores frequency of each character of str2 ; Traverse the string str2 ; Update frequency of str2 [ i ] ; Sort hash1 [ ] array ; Sort hash2 [ ] array ; Traverse hash1 [ ] and hash2 [ ] ; If hash1 [ i ] not equal to hash2 [ i ] ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def checkStr1CanConStr2 ( str1 , str2 ) :\\n\\tN = len ( str1 )\\n\\tM = len ( str2 )\\n\\tst1 = set ( [ ] )\\n\\tst2 = set ( [ ] )\\n\\thash1 = [ 0 ] * 256\\n\\tfor i in range ( N ) :\\n\\t\\thash1 [ ord ( str1 [ i ] ) ] += 1\\n\\tfor i in range ( N ) :\\n\\t\\tst1 . add ( str1 [ i ] )\\n\\tfor i in range ( M ) :\\n\\t\\tst2 . add ( str2 [ i ] )\\n\\tif ( st1 != st2 ) :\\n\\t\\treturn False\\n\\thash2 = [ 0 ] * 256\\n\\tfor i in range ( M ) :\\n\\t\\thash2 [ ord ( str2 [ i ] ) ] += 1\\n\\thash1 . sort ( )\\n\\thash2 . sort ( )\\n\\tfor i in range ( 256 ) :\\n\\t\\tif ( hash1 [ i ] != hash2 [ i ] ) :\\n\\t\\t\\treturn False\\n\\treturn True\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tstr1 = \\\" xyyzzlll \\\"\\n\\tstr2 = \\\" yllzzxxx \\\"\\n\\tif ( checkStr1CanConStr2 ( str1 , str2 ) ) :\\n\\t\\tprint ( \\\" True \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" False \\\" )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count Balanced Binary Trees of Height h | C # program to count number of balanced binary trees of height h . ; base cases ; Driver program\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int MOD = 1000000007 ; public static long countBT ( int h ) { long [ ] dp = new long [ h + 1 ] ; dp [ 0 ] = 1 ; dp [ 1 ] = 1 ; for ( int i = 2 ; i <= h ; ++ i ) dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD ; return dp [ h ] ; } static void Main ( ) { int h = 3 ; Console . WriteLine ( \\\" No . \u2581 of \u2581 balanced \u2581 binary \u2581 trees \u2581 of \u2581 height \u2581 \\\" + h + \\\" \u2581 is : \u2581 \\\" + countBT ( h ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Convert X into Y by repeatedly multiplying X with 2 or appending 1 at the end | Function to check if X can be converted to Y by multiplying X by 2 or appending 1 at the end ; Iterate until Y is at least X ; If Y is even ; If the last digit of Y is 1 ; Otherwise ; Check if X is equal to Y ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function convertXintoY ( X , Y ) { while ( Y > X ) { if ( Y % 2 == 0 ) Y = parseInt ( Y \\/ 2 ) ; else if ( Y % 10 == 1 ) Y = parseInt ( Y \\/= 10 ) ; else break ; } if ( X == Y ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ; } let X = 100 , Y = 40021 ; convertXintoY ( X , Y ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Construct an N | Javascript program to implement the above approach ; Keep track of visited nodes ; Function to construct a tree such that there are no two adjacent nodes with the same weight ; If minimum and maximum elements are equal , i . e . array contains one distinct element ; Tree cannot be constructed ; Otherwise ; Tree can be constructed ; Choose weights [ 0 ] as root ; First Node is visited ; Traverse the array ; Otherwise , make an edge ; Mark this node as visited ; Find a weight not same as the root & make edges with that node ; Join non - roots with remaining nodes ; Check if current node ' s \u2581 weight \u2581 \u2581 is \u2581 same \u2581 as \u2581 root \u2581 node ' s weight and if it is not visited or not ; Driver code ; Function Call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"let N = 100000 + 5 ; let visited = new Array ( N ) ; visited . fill ( 0 ) ; function construct_tree ( weights , n ) { let minimum = Number . MAX_VALUE ; let maximum = Number . MIN_VALUE ; for ( let i = 0 ; i < weights . length ; i ++ ) { minimum = Math . min ( minimum , weights [ i ] ) ; maximum = Math . max ( maximum , weights [ i ] ) ; } if ( minimum == maximum ) { document . write ( \\\" \\\" ) ; return ; } else { document . write ( \\\" \\\" + \\\" \\\" ) ; } let root = weights [ 0 ] ; visited [ 1 ] = 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( weights [ i ] != root && visited [ i + 1 ] == 0 ) { document . write ( 1 + \\\" \\\" + ( i + 1 ) + \\\" \\\" ) ; visited [ i + 1 ] = 1 ; } } let notroot = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( weights [ i ] != root ) { notroot = i + 1 ; break ; } } for ( let i = 0 ; i < n ; i ++ ) { if ( weights [ i ] == root && visited [ i + 1 ] == 0 ) { document . write ( notroot + \\\" \\\" + ( i + 1 ) + \\\" \\\" ) ; visited [ i + 1 ] = 1 ; } } } let weights = [ 1 , 2 , 1 , 2 , 5 ] ; let n = weights . length ; construct_tree ( weights , n ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Largest Square in a Binary Matrix with at most K 1 s for multiple Queries | Function to find the largest square in the matrix such that it contains atmost K 1 's ; Precomputation of the countDP prefix sum of the matrix ; Loop to solve each query ; Binary Search to the side which have atmost in K 1 's in square ; Count total number of 1 s in the sub square considered ; If the count is less than or equals to the maximum move to right half ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function largestSquare ( matrix , R , C , q_i , q_j , K , Q ) { let countDP = new Array ( R ) ; for ( let i = 0 ; i < R ; i ++ ) { countDP [ i ] = new Array ( C ) ; for ( let j = 0 ; j < C ; j ++ ) countDP [ i ] [ j ] = 0 ; } countDP [ 0 ] [ 0 ] = matrix [ 0 ] [ 0 ] ; for ( let i = 1 ; i < R ; i ++ ) countDP [ i ] [ 0 ] = countDP [ i - 1 ] [ 0 ] + matrix [ i ] [ 0 ] ; for ( let j = 1 ; j < C ; j ++ ) countDP [ 0 ] [ j ] = countDP [ 0 ] [ j - 1 ] + matrix [ 0 ] [ j ] ; for ( let i = 1 ; i < R ; i ++ ) for ( let j = 1 ; j < C ; j ++ ) countDP [ i ] [ j ] = matrix [ i ] [ j ] + countDP [ i - 1 ] [ j ] + countDP [ i ] [ j - 1 ] - countDP [ i - 1 ] [ j - 1 ] ; for ( let q = 0 ; q < Q ; q ++ ) { let i = q_i [ q ] ; let j = q_j [ q ] ; let min_dist = Math . min ( Math . min ( i , j ) , Math . min ( R - i - 1 , C - j - 1 ) ) ; let ans = - 1 , l = 0 , u = min_dist ; while ( l <= u ) { let mid = Math . floor ( ( l + u ) \\/ 2 ) ; let x1 = i - mid , x2 = i + mid ; let y1 = j - mid , y2 = j + mid ; let count = countDP [ x2 ] [ y2 ] ; if ( x1 > 0 ) count -= countDP [ x1 - 1 ] [ y2 ] ; if ( y1 > 0 ) count -= countDP [ x2 ] [ y1 - 1 ] ; if ( x1 > 0 && y1 > 0 ) count += countDP [ x1 - 1 ] [ y1 - 1 ] ; if ( count <= K ) { ans = 2 * mid + 1 ; l = mid + 1 ; } else u = mid - 1 ; } document . write ( ans + \\\" \\\" ) ; } } let matrix = [ [ 1 , 0 , 1 , 0 , 0 ] , [ 1 , 0 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] , [ 1 , 0 , 0 , 1 , 0 ] ] ; let K = 9 , Q = 1 ; let q_i = [ 1 ] ; let q_j = [ 2 ] ; largestSquare ( matrix , 4 , 5 , q_i , q_j , K , Q ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Generate all the binary strings of N bits | Function to print the output ; Function to generate all binary strings ; First assign \\\"0\\\" at ith position and try for all other permutations for remaining positions ; And then assign \\\"1\\\" at ith position and try for all other permutations for remaining positions ; Driver Code ; Print all binary strings\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function printTheArray ( $ arr , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { echo $ arr [ $ i ] , \\\" \\\" ; } echo \\\" \\n \\\" ; } function generateAllBinaryStrings ( $ n , $ arr , $ i ) { if ( $ i == $ n ) { printTheArray ( $ arr , $ n ) ; return ; } $ arr [ $ i ] = 0 ; generateAllBinaryStrings ( $ n , $ arr , $ i + 1 ) ; $ arr [ $ i ] = 1 ; generateAllBinaryStrings ( $ n , $ arr , $ i + 1 ) ; } $ n = 4 ; $ arr = array_fill ( 0 , $ n , 0 ) ; generateAllBinaryStrings ( $ n , $ arr , 0 ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to check if input is an integer or a string | Returns true if s is a number else false ; Saving the input in a string ; Function returns 1 if all elements are in range '0-9' ; Function returns 0 if the input is not an integer\\\"\\nSolution in php:\",\"targets\":\"< ? php function isNumber ( $ s ) { for ( $ i = 0 ; $ i < strlen ( $ s ) ; $ i ++ ) if ( is_numeric ( $ s [ $ i ] ) == false ) return false ; return true ; } $ str = \\\"6790\\\" ; if ( isNumber ( $ str ) ) echo \\\" Integer \\\" ; else echo \\\" String \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Average of a stream of numbers | Returns the new average after including x ; Prints average of a stream of numbers ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function getAvg ( $ x ) { static $ sum ; static $ n ; $ sum += $ x ; return ( ( ( float ) $ sum ) \\/ ++ $ n ) ; } function streamAvg ( $ arr , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ avg = getAvg ( $ arr [ $ i ] ) ; echo \\\" Average \u2581 of \u2581 \\\" . ( $ i + 1 ) . \\\" \u2581 numbers \u2581 is \u2581 \\\" . $ avg . \\\" \u2581 \\n \\\" ; } return ; } $ arr = array ( 10 , 20 , 30 , 40 , 50 , 60 ) ; $ n = sizeof ( $ arr ) \\/ sizeof ( $ arr [ 0 ] ) ; streamAvg ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the number of men initially | Function to return the number of men initially ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function numberOfMen ( D , m , d ) { var Men = ( m * ( D - d ) ) \\/ d ; return Men ; } var D = 5 , m = 4 , d = 4 ; document . write ( numberOfMen ( D , m , d ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Longest subsequence with at least one character appearing in every string | Javascript implementation of the approach ; Function to return the length of the longest sub - sequence with at least one common character in every string ; count [ 0 ] will store the number of strings which contain ' a ' , count [ 1 ] will store the number of strings which contain ' b ' and so on . . ; For every string ; Hash array to set which character is present in the current string ; If current character appears in the string then update its count ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"var MAX = 26 ; function largestSubSeq ( arr , n ) { var count = Array ( MAX ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { var str = arr [ i ] ; var hash = Array ( MAX ) . fill ( 0 ) ; for ( var j = 0 ; j < str . length ; j ++ ) { hash [ str [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = true ; } for ( var j = 0 ; j < MAX ; j ++ ) { if ( hash [ j ] ) count [ j ] ++ ; } } return count . reduce ( ( a , b ) => Math . max ( a , b ) ) ; } var arr = [ \\\" \\\" , \\\" \\\" , \\\" \\\" ] ; var n = arr . length ; document . write ( largestSubSeq ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"N consecutive ropes problem | Java implementation of the approach ; Function to return the minimum cost to connect the given ropes ; dp [ i ] [ j ] = minimum cost in range ( i , j ) sum [ i ] [ j ] = sum of range ( i , j ) ; Initializing the sum table memset ( sum , 0 , sizeof ( 0 ) ) ; ; Computing minimum cost for all the possible interval ( i , j ) Left range ; Right range ; No cost for a single rope ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int MinCost ( int arr [ ] , int n ) { int [ ] [ ] dp = new int [ n + 5 ] [ n + 5 ] ; int [ ] [ ] sum = new int [ n + 5 ] [ n + 5 ] ; for ( int i = 0 ; i < n ; i ++ ) { int k = arr [ i ] ; for ( int j = i ; j < n ; j ++ ) { if ( i == j ) sum [ i ] [ j ] = k ; else { k += arr [ j ] ; sum [ i ] [ j ] = k ; } } } for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = i ; j < n ; j ++ ) { dp [ i ] [ j ] = Integer . MAX_VALUE ; if ( i == j ) dp [ i ] [ j ] = 0 ; else { for ( int k = i ; k < j ; k ++ ) { dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] + sum [ i ] [ j ] ) ; } } } } return dp [ 0 ] [ n - 1 ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 6 , 8 , 6 , 1 , 1 } ; int n = arr . length ; System . out . println ( MinCost ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Fraction | Function to return gcd of a and b ; Function to convert the obtained fraction into it 's simplest form ; Finding gcd of both terms ; Converting both terms into simpler terms by dividing them by common factor ; Function to add two fractions ; Finding gcd of den1 and den2 ; Denominator of final fraction obtained finding LCM of den1 and den2 LCM * GCD = a * b ; Changing the fractions to have same denominator Numerator of the final fraction obtained ; Calling function to convert final fraction into it 's simplest form ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def gcd ( a , b ) :\\n\\tif ( a == 0 ) :\\n\\t\\treturn b\\n\\treturn gcd ( b % a , a )\\ndef lowest ( den3 , num3 ) :\\n\\tcommon_factor = gcd ( num3 , den3 )\\n\\tden3 = int ( den3 \\/ common_factor )\\n\\tnum3 = int ( num3 \\/ common_factor )\\n\\tprint ( num3 , \\\" \\/ \\\" , den3 )\\ndef addFraction ( num1 , den1 , num2 , den2 ) :\\n\\tden3 = gcd ( den1 , den2 )\\n\\tden3 = ( den1 * den2 ) \\/ den3\\n\\tnum3 = ( ( num1 ) * ( den3 \\/ den1 ) + ( num2 ) * ( den3 \\/ den2 ) )\\n\\tlowest ( den3 , num3 )\\nnum1 = 1 ; den1 = 500\\nnum2 = 2 ; den2 = 1500\\nprint ( num1 , \\\" \\/ \\\" , den1 , \\\" \u2581 + \u2581 \\\" , num2 , \\\" \\/ \\\" , den2 , \\\" \u2581 is \u2581 equal \u2581 to \u2581 \\\" , end = \\\" \\\" )\\naddFraction ( num1 , den1 , num2 , den2 )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Convert to number with digits as 3 and 8 only | function for minimum operation ; remainder and operations count ; count digits not equal to 3 or 8 ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function minOp ( $ num ) { $ count = 0 ; while ( $ num ) { $ rem = intval ( $ num % 10 ) ; if ( ! ( $ rem == 3 $ rem == 8 ) ) $ count ++ ; $ num = intval ( $ num \\/ 10 ) ; } return $ count ; } $ num = 234198 ; echo \\\" Minimum \u2581 Operations \u2581 = \u2581 \\\" . minOp ( $ num ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Print all distinct even and odd prefix Bitwise XORs of first N natural numbers | Print all distinct even & odd prefix Bitwise XORs from 1 to N ; Print the even number ; Print the odd number ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function evenOddBitwiseXOR ( N ) { document . write ( \\\" \\\" + 0 + \\\" \\\" ) ; for ( let i = 4 ; i <= N ; i = i + 4 ) { document . write ( i + \\\" \\\" ) ; } document . write ( \\\" \\\" ) ; document . write ( \\\" \\\" + 1 + \\\" \\\" ) ; for ( let i = 4 ; i <= N ; i = i + 4 ) { document . write ( i - 1 + \\\" \\\" ) ; } if ( N % 4 == 2 ) document . write ( N + 1 ) ; else if ( N % 4 == 3 ) document . write ( N ) ; } let N = 6 ; evenOddBitwiseXOR ( N ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimize prize count required such that smaller value gets less prize in an adjacent pair | Java implementation to find the minimum prizes required such that adjacent smaller elements gets less number of prizes ; Function to find the minimum number of required such that adjacent smaller elements gets less number of prizes ; Loop to compute the smaller elements at the left ; Loop to find the smaller elements at the right ; Loop to find the minimum prizes required ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static int minPrizes ( int arr [ ] , int n ) { int [ ] dpLeft = new int [ n ] ; dpLeft [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) { dpLeft [ i ] = dpLeft [ i - 1 ] + 1 ; } else { dpLeft [ i ] = 1 ; } } int [ ] dpRight = new int [ n ] ; dpRight [ n - 1 ] = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > arr [ i + 1 ] ) { dpRight [ i ] = dpRight [ i + 1 ] + 1 ; } else { dpRight [ i ] = 1 ; } } int totalPrizes = 0 ; for ( int i = 0 ; i < n ; i ++ ) { totalPrizes += Math . max ( dpLeft [ i ] , dpRight [ i ] ) ; } System . out . print ( totalPrizes + \\\"\\n\\\"); return 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 2 , 3 } ; int n = arr . length ; minPrizes ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the N | C ++ program to find n - th number containing only 3 and 5. ; If n is odd , append 3 and move to parent ; If n is even , append 5 and move to parent ; Reverse res and return . ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; string findNthNo ( int n ) { string res = \\\" \\\" ; while ( n >= 1 ) { if ( n & 1 ) { res = res + \\\"3\\\" ; n = ( n - 1 ) \\/ 2 ; } else { res = res + \\\"5\\\" ; n = ( n - 2 ) \\/ 2 ; } } reverse ( res . begin ( ) , res . end ( ) ) ; return res ; } int main ( ) { int n = 5 ; cout << findNthNo ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find all numbers up to N which are both Pentagonal and Hexagonal | Java program of the above approach ; Function to print numbers upto N which are both pentagonal as well as hexagonal numbers ; Calculate i - th pentagonal number ; Check if the pentagonal number pn is hexagonal or not ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void pen_hex ( long n ) { long pn = 1 ; for ( long i = 1 ; i < n ; i ++ ) { pn = i * ( 3 * i - 1 ) \\/ 2 ; if ( pn > n ) break ; double seqNum = ( 1 + Math . sqrt ( 8 * pn + 1 ) ) \\/ 4 ; if ( seqNum == ( long ) seqNum ) System . out . print ( pn + \\\" , \u2581 \\\" ) ; } } public static void main ( String [ ] args ) { long N = 1000000 ; pen_hex ( N ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Biggest Reuleaux Triangle inscirbed within a square inscribed in a semicircle | Function to find the biggest reuleaux triangle ; radius cannot be negative ; height of the reuleaux triangle ; area of the reuleaux triangle ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function Area ( $ r ) { if ( $ r < 0 ) return -1 ; $ x = ( 2 * $ r ) \\/ sqrt ( 5 ) ; $ A = 0.70477 * pow ( $ x , 2 ) ; return $ A ; } $ r = 5 ; echo Area ( $ r ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Ternary Search | C program to illustrate iterative approach to ternary search ; Function to perform Ternary Search ; Find the mid1 and mid2 ; Check if key is present at any mid ; Since key is not present at mid , check in which region it is present then repeat the Search operation in that region ; The key lies in between l and mid1 ; The key lies in between mid2 and r ; The key lies in between mid1 and mid2 ; Key not found ; Driver code ; Get the array Sort the array if not sorted ; Starting index ; length of array ; Key to be searched in the array ; Search the key using ternarySearch ; Print the result ; Key to be searched in the array ; Search the key using ternarySearch ; Print the result\\\"\\nSolution in C:\",\"targets\":\"#include \\nint ternarySearch ( int l , int r , int key , int ar [ ] ) { while ( r >= l ) { int mid1 = l + ( r - l ) \\/ 3 ; int mid2 = r - ( r - l ) \\/ 3 ; if ( ar [ mid1 ] == key ) { return mid1 ; } if ( ar [ mid2 ] == key ) { return mid2 ; } if ( key < ar [ mid1 ] ) { r = mid1 - 1 ; } else if ( key > ar [ mid2 ] ) { l = mid2 + 1 ; } else { l = mid1 + 1 ; r = mid2 - 1 ; } } return -1 ; } int main ( ) { int l , r , p , key ; int ar [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; l = 0 ; r = 9 ; key = 5 ; p = ternarySearch ( l , r , key , ar ) ; printf ( \\\" Index \u2581 of \u2581 % d \u2581 is \u2581 % d \\n \\\" , key , p ) ; key = 50 ; p = ternarySearch ( l , r , key , ar ) ; printf ( \\\" Index \u2581 of \u2581 % d \u2581 is \u2581 % d \\\" , key , p ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if a point lies inside a rectangle | Set | function to find if given point lies inside a given rectangle or not . ; bottom - left and top - right corners of rectangle ; given point ; function call\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function FindPoint ( $ x1 , $ y1 , $ x2 , $ y2 , $ x , $ y ) { if ( $ x > $ x1 and $ x < $ x2 and $ y > $ y1 and $ y < $ y2 ) return true ; return false ; } $ x1 = 0 ; $ y1 = 0 ; $ x2 = 10 ; $ y2 = 8 ; $ x = 1 ; $ y = 5 ; if ( FindPoint ( $ x1 , $ y1 , $ x2 , $ y2 , $ x , $ y ) ) echo \\\" Yes \\\" ; else echo \\\" No \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the two numbers with odd occurrences in an unsorted array | Program to find the two odd occurring elements ; Prints two numbers that occur odd number of times . The function assumes that the array size is at least 2 and there are exactly two numbers occurring odd number of times . ; Will hold XOR of two odd occurring elements ; Will have only single set bit of xor2 ; Get the xor of all elements in arr [ ] . The xor will basically be xor of two odd occurring elements ; Get one set bit in the xor2 . We get rightmost set bit in the following line as it is easy to get ; Now divide elements in two sets : 1 ) The elements having the corresponding bit as 1. 2 ) The elements having the corresponding bit as 0. ; XOR of first set is finally going to hold one odd occurring number x ; XOR of second set is finally going to hold the other odd occurring number y ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\nvoid printTwoOdd ( int arr [ ] , int size ) { int xor2 = arr [ 0 ] ; int set_bit_no ; int i ; int n = size - 2 ; int x = 0 , y = 0 ; for ( i = 1 ; i < size ; i ++ ) xor2 = xor2 ^ arr [ i ] ; set_bit_no = xor2 & ~ ( xor2 - 1 ) ; for ( i = 0 ; i < size ; i ++ ) { if ( arr [ i ] & set_bit_no ) x = x ^ arr [ i ] ; else y = y ^ arr [ i ] ; } printf ( \\\" The two ODD elements are % d & % d \\\" , x , y ) ; } int main ( ) { int arr [ ] = { 4 , 2 , 4 , 5 , 2 , 3 , 3 , 1 } ; int arr_size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printTwoOdd ( arr , arr_size ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the rate percentage from compound interest of consecutive years | Function to return the required rate percentage ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function Rate ( $ N1 , $ N2 ) { $ rate = ( $ N2 - $ N1 ) * 100 \\/ $ N1 ; return $ rate ; } $ N1 = 100 ; $ N2 = 120 ; echo Rate ( $ N1 , $ N2 ) , \\\" % \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find minimum x such that ( x % k ) * ( x \\/ k ) == n | This function gives the required answer ; Iterate over all possible remainders ; it must divide n ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function minimumX ( $ n , $ k ) { $ ans = PHP_INT_MAX ; for ( $ rem = $ k - 1 ; $ rem > 0 ; $ rem -- ) { if ( $ n % $ rem == 0 ) $ ans = min ( $ ans , $ rem + ( $ n \\/ $ rem ) * $ k ) ; } return $ ans ; } $ n = 4 ; $ k = 6 ; echo minimumX ( $ n , $ k ) , \\\" \\n \\\" ; $ n = 5 ; $ k = 5 ; echo minimumX ( $ n , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Segregate 0 s and 1 s in an array | C # program to sort a binary array in one pass ; Function to put all 0 s on left and all 1 s on right ; Initialize left and right indexes ; Increment left index while we see 0 at left ; Decrement right index while we see 1 at right ; If left is smaller than right then there is a 1 at left and a 0 at right . Exchange arr [ left ] and arr [ right ] ; Driver Program to test above functions\\\"\\nSolution in C#:\",\"targets\":\"using System ; class Segregate { void segregate0and1 ( int [ ] arr , int size ) { int left = 0 , right = size - 1 ; while ( left < right ) { while ( arr [ left ] == 0 && left < right ) left ++ ; while ( arr [ right ] == 1 && left < right ) right -- ; if ( left < right ) { arr [ left ] = 0 ; arr [ right ] = 1 ; left ++ ; right -- ; } } } public static void Main ( ) { Segregate seg = new Segregate ( ) ; int [ ] arr = new int [ ] { 0 , 1 , 0 , 1 , 1 , 1 } ; int i , arr_size = arr . Length ; seg . segregate0and1 ( arr , arr_size ) ; Console . WriteLine ( \\\" Array \u2581 after \u2581 segregation \u2581 is \u2581 \\\" ) ; for ( i = 0 ; i < 6 ; i ++ ) Console . Write ( arr [ i ] + \\\" \u2581 \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of given operations required to reduce the array to 0 element | Function to return the minimum operations required ; Count the frequency of each element ; Maximum element from the array ; Find all the multiples of i ; Delete the multiples ; Increment the operations ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def minOperations ( arr , n ) :\\n\\tresult = 0\\n\\tfreq = [ 0 ] * 1000001\\n\\tfor i in range ( 0 , n ) :\\n\\t\\tfreq [ arr [ i ] ] += 1\\n\\tmaxi = max ( arr )\\n\\tfor i in range ( 1 , maxi + 1 ) :\\n\\t\\tif freq [ i ] != 0 :\\n\\t\\t\\tfor j in range ( i * 2 , maxi + 1 , i ) :\\n\\t\\t\\t\\tfreq [ j ] = 0\\n\\t\\t\\tresult += 1\\n\\treturn result\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ 2 , 4 , 2 , 4 , 4 , 4 ]\\n\\tn = len ( arr )\\n\\tprint ( minOperations ( arr , n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Number of subarrays with GCD equal to 1 | Java implementation of the approach ; Function to return the required count ; To store the final answer ; To store the GCD starting from index ' i ' ; Loop to find the gcd of each subarray from arr [ i ] to arr [ i ... n - 1 ] ; Increment the count if curr_gcd = 1 ; Return the final answer ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int cntSubArr ( int [ ] arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int curr_gcd = 0 ; for ( int j = i ; j < n ; j ++ ) { curr_gcd = __gcd ( curr_gcd , arr [ j ] ) ; ans += ( curr_gcd == 1 ) ? 1 : 0 ; } } return ans ; } static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 1 } ; int n = arr . length ; System . out . println ( cntSubArr ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximum length of consecutive 1 s or 0 s after flipping at most K characters | Function to find the maximum length continuos segment of character c after flipping at most K characters ; Stores the maximum length ; Stores the count of char 'c ; Start of window ; Remove the extra ' c ' from left ; Increment the value of the left ; Update the resultant maximum length of character ch ; Function to find the maximum length of consecutive 0 s or 1 s by flipping at most K characters of the string ; Print the maximum of the maximum length of 0 s or 1 s ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def maxLength ( str , n , c , k ) :\\n\\tans = - 1\\n'\\n\\tcnt = 0\\n\\tleft = 0\\n\\tfor right in range ( 0 , n ) :\\n\\t\\tif ( str [ right ] == c ) :\\n\\t\\t\\tcnt += 1\\n\\t\\twhile ( cnt > k ) :\\n\\t\\t\\tif ( str [ left ] == c ) :\\n\\t\\t\\t\\tcnt -= 1\\n\\t\\t\\tleft += 1\\n\\t\\tans = max ( ans , right - left + 1 )\\n\\treturn ans\\ndef maxConsecutiveSegment ( S , K ) :\\n\\tN = len ( S )\\n\\treturn max ( maxLength ( S , N , '0' , K ) , maxLength ( S , N , '1' , K ) )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tS = \\\"1001\\\"\\n\\tK = 1\\n\\tprint ( maxConsecutiveSegment ( S , K ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count of elements which are equal to the XOR of the next two elements | C # implementation of the approach ; Function to return the count of elements which are equal to the XOR of the next two elements ; To store the required count ; For every element of the array such that it has at least two elements appearing after it in the array ; If current element is equal to the XOR of the next two elements in the array ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int cntElements ( int [ ] arr , int n ) { int cnt = 0 ; for ( int i = 0 ; i < n - 2 ; i ++ ) { if ( arr [ i ] == ( arr [ i + 1 ] ^ arr [ i + 2 ] ) ) { cnt ++ ; } } return cnt ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 2 , 1 , 3 , 7 , 8 } ; int n = arr . Length ; Console . WriteLine ( cntElements ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"An efficient way to check whether n | A simple Java program to check if n - th Fibonacci number is multiple of 10. ; Returns true if n - th Fibonacci number is multiple of 10. ; main function\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class Fibonacci { static int fibonacci ( int n ) { int a = 0 ; int b = 1 ; int c = 0 ; if ( n <= 1 ) return n ; for ( int i = 2 ; i <= n ; i ++ ) { c = a + b ; a = b ; b = c ; } return c ; } static boolean isMultipleOf10 ( int n ) { int f = fibonacci ( 30 ) ; return ( f % 10 == 0 ) ; } public static void main ( String [ ] args ) { int n = 30 ; if ( isMultipleOf10 ( n ) ) System . out . println ( \\\" Yes \\\" ) ; else System . out . println ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find all numbers up to N which are both Pentagonal and Hexagonal | C ++ Program of the above approach ; Function to print numbers upto N which are both pentagonal as well as hexagonal numbers ; Calculate i - th pentagonal number ; Check if the pentagonal number pn is hexagonal or not ; Driver Program\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void pen_hex ( long long n ) { long long pn = 1 ; for ( long long int i = 1 ; ; i ++ ) { pn = i * ( 3 * i - 1 ) \\/ 2 ; if ( pn > n ) break ; long double seqNum = ( 1 + sqrt ( 8 * pn + 1 ) ) \\/ 4 ; if ( seqNum == long ( seqNum ) ) cout << pn << \\\" , \u2581 \\\" ; } } int main ( ) { long long int N = 1000000 ; pen_hex ( N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Counts Path in an Array | C # implementation of the above approach ; Find the number of ways to reach the end ; Base case ; Recursive structure ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int mod = 1000000000 ; static int ways ( int i , int [ ] arr , int n ) { if ( i == n - 1 ) return 1 ; int sum = 0 ; for ( int j = 1 ; j + i < n && j <= arr [ i ] ; j ++ ) { sum += ( ways ( i + j , arr , n ) ) % mod ; sum %= mod ; } return sum % mod ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 3 , 1 , 4 , 3 } ; int n = arr . Length ; Console . WriteLine ( ways ( 0 , arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find the sum of all the terms in the n | Java implementation to find the sum of all the terms in the nth row of the given series ; method to find the required sum ; sum = n * ( 2 * n ^ 2 + 1 ) ; Driver method\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import static java . lang . Math . pow ; class Test { static int sumOfTermsInNthRow ( int n ) { int sum = ( int ) ( n * ( 2 * pow ( n , 2 ) + 1 ) ) ; return sum ; } public static void main ( String args [ ] ) { int n = 4 ; System . out . println ( \\\" Sum \u2581 of \u2581 all \u2581 the \u2581 terms \u2581 in \u2581 nth \u2581 row \u2581 = \u2581 \\\" + sumOfTermsInNthRow ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Modular multiplicative inverse from 1 to n | A naive method to find modular multiplicative inverse of ' a ' under modulo 'prime ; Driver Program\\\"\\nHow can the above be solved in Python?\",\"targets\":\"'\\ndef modInverse ( a , prime ) :\\n\\ta = a % prime\\n\\tfor x in range ( 1 , prime ) :\\n\\t\\tif ( ( a * x ) % prime == 1 ) :\\n\\t\\t\\treturn x\\n\\treturn - 1\\ndef printModIverses ( n , prime ) :\\n\\tfor i in range ( 1 , n + 1 ) :\\n\\t\\tprint ( modInverse ( i , prime ) , end = \\\" \u2581 \\\" )\\nn = 10\\nprime = 17\\nprintModIverses ( n , prime )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Number of solutions of n = x + n \u00e2\u0160 \u2022 x | Function to find the number of solutions of n = n xor x ; Counter to store the number of solutions found ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function numberOfSolutions ( n ) { let c = 0 ; for ( let x = 0 ; x <= n ; ++ x ) if ( n == x + n ^ x ) ++ c ; return c ; } let n = 3 ; document . write ( numberOfSolutions ( n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the Nth term of series 5 , 12 , 21 , 32 , 45. ... . . | C # program to find the N - th term of the series : 5 , 12 , 21 , 32 , 45. . ... . ; calculate Nth term of series ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int nthTerm ( int n ) { return ( int ) Math . Pow ( n , 2 ) + 4 * n ; } public static void Main ( ) { int N = 4 ; Console . WriteLine ( nthTerm ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Generate a string whose all K | Function to return the required required string ; Iterate the given string ; Append the first character of every substring of length K ; Consider all characters from the last substring ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def decode_String ( st , K ) :\\n\\tans = \\\" \\\"\\n\\tfor i in range ( 0 , len ( st ) , K ) :\\n\\t\\tans += st [ i ]\\n\\tfor i in range ( len ( st ) - ( K - 1 ) , len ( st ) ) :\\n\\t\\tans += st [ i ]\\n\\tprint ( ans )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tK = 3\\n\\tst = \\\" abcbcscsesesesd \\\"\\n\\tdecode_String ( st , K )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Probability of rain on N + 1 th day | Java code to find the probability of rain on n + 1 - th day when previous day 's data is given ; Function to find the probability ; count 1 ; find probability ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { static float rainDayProbability ( int a [ ] , int n ) { float count = 0 , m ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 1 ) count ++ ; } m = count \\/ n ; return m ; } public static void main ( String args [ ] ) { int a [ ] = { 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 } ; int n = a . length ; System . out . print ( rainDayProbability ( a , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Write your own strcmp that ignores cases | ; implementation of strcmp that ignores cases ; If characters are same or inverting the 6 th bit makes them same ; Compare the last ( or first mismatching in case of not same ) characters ; Set the 6 th bit in both , then compare ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint ic_strcmp ( char * s1 , char * s2 ) { int i ; for ( i = 0 ; s1 [ i ] && s2 [ i ] ; ++ i ) { if ( s1 [ i ] == s2 [ i ] || ( s1 [ i ] ^ 32 ) == s2 [ i ] ) continue ; else break ; } if ( s1 [ i ] == s2 [ i ] ) return 0 ; if ( ( s1 [ i ] 32 ) < ( s2 [ i ] 32 ) ) return -1 ; return 1 ; } int main ( void ) { printf ( \\\" ret : \u2581 % d \\n \\\" , ic_strcmp ( \\\" Geeks \\\" , \\\" apple \\\" ) ) ; printf ( \\\" ret : \u2581 % d \\n \\\" , ic_strcmp ( \\\" \\\" , \\\" ABCD \\\" ) ) ; printf ( \\\" ret : \u2581 % d \\n \\\" , ic_strcmp ( \\\" ABCD \\\" , \\\" z \\\" ) ) ; printf ( \\\" ret : \u2581 % d \\n \\\" , ic_strcmp ( \\\" ABCD \\\" , \\\" abcdEghe \\\" ) ) ; printf ( \\\" ret : \u2581 % d \\n \\\" , ic_strcmp ( \\\" GeeksForGeeks \\\" , \\\" gEEksFORGeEKs \\\" ) ) ; printf ( \\\" ret : \u2581 % d \\n \\\" , ic_strcmp ( \\\" GeeksForGeeks \\\" , \\\" geeksForGeeks \\\" ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Sentence Case of a given Camel cased string | C ++ implementation of the approach ; Function to return the original string after converting it back from camelCase ; Print the first character as it is ; Traverse the rest of the characters one by one ; If current character is uppercase print space followed by the current character in lowercase ; Else print the current character ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void getOrgString ( string s ) { cout << s [ 0 ] ; int i = 1 ; while ( i < s . length ( ) ) { if ( s [ i ] >= ' A ' && s [ i ] <= ' Z ' ) cout << \\\" \u2581 \\\" << ( char ) tolower ( s [ i ] ) ; else cout << s [ i ] ; i ++ ; } } int main ( ) { string s = \\\" ILoveGeeksForGeeks \\\" ; getOrgString ( s ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum length prefix of one string that occurs as subsequence in another | Return the maximum length prefix which is subsequence . ; Iterating string T . ; If end of string S . ; If character match , increment counter . ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function maxPrefix ( s , t ) { let count = 0 ; for ( let i = 0 ; i < t . length ; i ++ ) { if ( count == s . length ) break ; if ( t [ i ] == s [ count ] ) count ++ ; } return count ; } let S = \\\" \\\" ; let T = \\\" \\\" ; document . write ( maxPrefix ( S , T ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Deletion at different positions in a Circular Linked List | Function to delete last node of Circular Linked List ; Check if list doesn 't have any node if not then return ; Check if list have single node if yes then delete it and return ; Move first node to last previous\\\"\\nHow can the above be solved in Java?\",\"targets\":\"static Node DeleteLast ( Node head ) { Node current = head , temp = head , previous = null ; if ( head == null ) { System . out . printf ( \\\" List is empty \\\"); return null ; } if ( current . next == current ) { head = null ; return null ; } while ( current . next != head ) { previous = current ; current = current . next ; } previous . next = current . next ; head = previous . next ; return head ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Euler 's criterion (Check if square root under modulo p exists) | Returns true if square root of n under modulo p exists ; One by one check all numbers from 2 to p - 1 ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function squareRootExists ( $ n , $ p ) { $ n = $ n % $ p ; for ( $ x = 2 ; $ x < $ p ; $ x ++ ) if ( ( $ x * $ x ) % $ p == $ n ) return true ; return false ; } $ p = 7 ; $ n = 2 ; if ( squareRootExists ( $ n , $ p ) == true ) echo \\\" Yes \\\" ; else echo \\\" No \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check whether given string can be generated after concatenating given strings | C # implementation of the approach ; Function that return true if pre is a prefix of str ; While there are characters to match ; If characters differ at any position ; str starts with pre ; Function that return true if suff is a suffix of str ; While there are characters to match ; If characters differ at any position ; str ends with suff ; Function that returns true if str = a + b or str = b + a ; str cannot be generated by concatenating a and b ; If str starts with a i . e . a is a prefix of str ; Check if the rest of the characters are equal to b i . e . b is a suffix of str ; If str starts with b i . e . b is a prefix of str ; Check if the rest of the characters are equal to a i . e . a is a suffix of str ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static Boolean startsWith ( String str , String pre ) { int strLen = str . Length ; int preLen = pre . Length ; int i = 0 , j = 0 ; while ( i < strLen && j < preLen ) { if ( str [ i ] != pre [ j ] ) return false ; i ++ ; j ++ ; } return true ; } static Boolean endsWith ( String str , String suff ) { int i = str . Length - 1 ; int j = suff . Length - 1 ; while ( i >= 0 && j >= 0 ) { if ( str [ i ] != suff [ j ] ) return false ; i -- ; j -- ; } return true ; } static Boolean checkString ( String str , String a , String b ) { if ( str . Length != a . Length + b . Length ) return false ; if ( startsWith ( str , a ) ) { if ( endsWith ( str , b ) ) return true ; } if ( startsWith ( str , b ) ) { if ( endsWith ( str , a ) ) return true ; } return false ; } public static void Main ( String [ ] args ) { String str = \\\" GeeksforGeeks \\\" ; String a = \\\" Geeksfo \\\" ; String b = \\\" rGeeks \\\" ; if ( checkString ( str , a , b ) ) Console . WriteLine ( \\\" Yes \\\" ) ; else Console . WriteLine ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"Check for Majority Element in a sorted array | C Program to check for majority element in a sorted array ; get last index according to n ( even or odd ) ; search for first occurrence of x in arr [ ] ; check if x is present and is present more than n \\/ 2 times ; Driver program to check above function\\nHow can the above be solved in C?\",\"targets\":\"# include \\n# include \\nbool isMajority ( int arr [ ] , int n , int x ) { int i ; int last_index = n % 2 ? ( n \\/ 2 + 1 ) : ( n \\/ 2 ) ; for ( i = 0 ; i < last_index ; i ++ ) { if ( arr [ i ] == x && arr [ i + n \\/ 2 ] == x ) return 1 ; } return 0 ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 4 , 4 , 4 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int x = 4 ; if ( isMajority ( arr , n , x ) ) printf ( \\\" % d \u2581 appears \u2581 more \u2581 than \u2581 % d \u2581 times \u2581 in \u2581 arr [ ] \\\" , x , n \\/ 2 ) ; else printf ( \\\" % d \u2581 does \u2581 not \u2581 appear \u2581 more \u2581 than \u2581 % d \u2581 times \u2581 in \u2581 arr [ ] \\\" , x , n \\/ 2 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find number of subarrays with even sum | C ++ program to count number of sub - arrays whose sum is even using brute force Time Complexity - O ( N ^ 2 ) Space Complexity - O ( 1 ) ; Find sum of all subarrays and increment result if sum is even ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int countEvenSum ( int arr [ ] , int n ) { int result = 0 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) { int sum = 0 ; for ( int j = i ; j <= n - 1 ; j ++ ) { sum = sum + arr [ j ] ; if ( sum % 2 == 0 ) result ++ ; } } return ( result ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 2 , 3 , 4 , 1 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << \\\" The \u2581 Number \u2581 of \u2581 Subarrays \u2581 with \u2581 even \\\" \\\" \u2581 sum \u2581 is \u2581 \\\" << countEvenSum ( arr , n ) ; return ( 0 ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Distance between a point and a Plane in 3 D | Function to find distance ; Driver Code ; function call\\\"\\nSolution in php:\",\"targets\":\"< ? php function shortest_distance ( $ x1 , $ y1 , $ z1 , $ a , $ b , $ c , $ d ) { $ d = abs ( ( $ a * $ x1 + $ b * $ y1 + $ c * $ z1 + $ d ) ) ; $ e = sqrt ( $ a * $ a + $ b * $ b + $ c * $ c ) ; echo \\\" Perpendicular \u2581 distance \u2581 is \u2581 \\\" . $ d \\/ $ e ; } $ x1 = 4 ; $ y1 = -4 ; $ z1 = 3 ; $ a = 2 ; $ b = -2 ; $ c = 5 ; $ d = 8 ; shortest_distance ( $ x1 , $ y1 , $ z1 , $ a , $ b , $ c , $ d ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count all distinct pairs of repeating elements from the array for every array element | C ++ program for the above approach ; Function to print the required count of pairs excluding the current element ; Store the frequency ; Find all the count ; Delete the contribution of each element for equal pairs ; Print the answer ; Driver Code ; Given array arr [ ] ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#define int long long int\\nusing namespace std ; void solve ( int arr [ ] , int n ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; i ++ ) { mp [ arr [ i ] ] ++ ; } int cnt = 0 ; for ( auto x : mp ) { cnt += ( ( x . second ) * ( x . second - 1 ) \\/ 2 ) ; } int ans [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ans [ i ] = cnt - ( mp [ arr [ i ] ] - 1 ) ; } for ( int i = 0 ; i < n ; i ++ ) { cout << ans [ i ] << \\\" \u2581 \\\" ; } } int32_t main ( ) { int arr [ ] = { 1 , 1 , 2 , 1 , 2 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; solve ( arr , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program for subtraction of matrices | This function subtracts B [ ] [ ] from A [ ] [ ] , and stores the result in C [ ] [ ] ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function subtract ( & $ A , & $ B , & $ C ) { $ N = 4 ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) for ( $ j = 0 ; $ j < $ N ; $ j ++ ) $ C [ $ i ] [ $ j ] = $ A [ $ i ] [ $ j ] - $ B [ $ i ] [ $ j ] ; } $ N = 4 ; $ A = array ( array ( 1 , 1 , 1 , 1 ) , array ( 2 , 2 , 2 , 2 ) , array ( 3 , 3 , 3 , 3 ) , array ( 4 , 4 , 4 , 4 ) ) ; $ B = array ( array ( 1 , 1 , 1 , 1 ) , array ( 2 , 2 , 2 , 2 ) , array ( 3 , 3 , 3 , 3 ) , array ( 4 , 4 , 4 , 4 ) ) ; subtract ( $ A , $ B , $ C ) ; echo \\\" Result \u2581 matrix \u2581 is \u2581 \\n \\\" ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) { for ( $ j = 0 ; $ j < $ N ; $ j ++ ) { echo $ C [ $ i ] [ $ j ] ; echo \\\" \u2581 \\\" ; } echo \\\" \\n \\\" ; } ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to find transpose of a matrix | PHP Program to find transpose of a matrix ; Converts A [ ] [ ] to its transpose ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ N = 4 ; function transpose ( & $ A ) { for ( $ i = 0 ; $ i < $ N ; $ i ++ ) for ( $ j = $ i + 1 ; $ j < $ N ; $ j ++ ) { $ temp = $ A [ $ i ] [ $ j ] ; $ A [ $ i ] [ $ j ] = $ A [ $ j ] [ $ i ] ; $ A [ $ j ] [ $ i ] = $ temp ; } } $ N = 4 ; $ A = array ( array ( 1 , 1 , 1 , 1 ) , array ( 2 , 2 , 2 , 2 ) , array ( 3 , 3 , 3 , 3 ) , array ( 4 , 4 , 4 , 4 ) ) ; transpose ( $ A ) ; echo \\\" Modified \u2581 matrix \u2581 is \u2581 \\\" . \\\" \\n \\\" ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) { for ( $ j = 0 ; $ j < $ N ; $ j ++ ) echo $ A [ $ i ] [ $ j ] . \\\" \u2581 \\\" ; echo \\\" \\n \\\" ; } ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Print all possible combinations of r elements in a given array of size n | Java program to print all combination of size r in an array of size n ; The main function that prints all combinations of size r in arr [ ] of size n . This function mainly uses combinationUtil ( ) ; A temporary array to store all combination one by one ; Print all combination using temprary array ' data [ ] ' ; arr [ ] -- -> Input Array data [ ] -- -> Temporary array to store current combination start & end -- -> Staring and Ending indexes in arr [ ] index -- -> Current index in data [ ] r -- -> Size of a combination to be printed ; Current combination is ready to be printed , print it ; replace index with all possible elements . The condition \\\" end - i + 1 \u2581 > = \u2581 r - index \\\" makes sure that including one element at index will make a combination with remaining elements at remaining positions ; Driver function to check for above function\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class Combination { static void printCombination ( int arr [ ] , int n , int r ) { int data [ ] = new int [ r ] ; combinationUtil ( arr , data , 0 , n - 1 , 0 , r ) ; } static void combinationUtil ( int arr [ ] , int data [ ] , int start , int end , int index , int r ) { if ( index == r ) { for ( int j = 0 ; j < r ; j ++ ) System . out . print ( data [ j ] + \\\" \u2581 \\\" ) ; System . out . println ( \\\" \\\" ) ; return ; } for ( int i = start ; i <= end && end - i + 1 >= r - index ; i ++ ) { data [ index ] = arr [ i ] ; combinationUtil ( arr , data , i + 1 , end , index + 1 , r ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int r = 3 ; int n = arr . length ; printCombination ( arr , n , r ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Number with maximum number of prime factors | Return smallest number having maximum prime factors . ; Sieve of eratosthenes method to count number of prime factors . ; Finding number having maximum number of prime factor . ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function maxPrimefactorNum ( $ N ) { $ arr [ $ N + 5 ] = array ( ) ; $ arr = array_fill ( 0 , $ N + 1 , NULL ) ; for ( $ i = 2 ; ( $ i * $ i ) <= $ N ; $ i ++ ) { if ( ! $ arr [ $ i ] ) for ( $ j = 2 * $ i ; $ j <= $ N ; $ j += $ i ) $ arr [ $ j ] ++ ; $ arr [ $ i ] = 1 ; } $ maxval = 0 ; $ maxint = 1 ; for ( $ i = 1 ; $ i <= $ N ; $ i ++ ) { if ( $ arr [ $ i ] > $ maxval ) { $ maxval = $ arr [ $ i ] ; $ maxint = $ i ; } } return $ maxint ; } $ N = 40 ; echo maxPrimefactorNum ( $ N ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum gcd operations to make all array elements one | Java program to find minimum GCD operations to make all array elements one . ; __gcd function ; Function to count number of moves . ; Counting Number of ones . ; If there is a one ; Find smallest subarray with GCD equals to one . ; to calculate GCD ; Not Possible ; Final answer ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static int __gcd ( int a , int b ) { if ( a == 0 ) return b ; return __gcd ( b % a , a ) ; } static int minimumMoves ( int A [ ] , int N ) { int one = 0 ; for ( int i = 0 ; i < N ; i ++ ) if ( A [ i ] == 1 ) one ++ ; if ( one != 0 ) return N - one ; int minimum = Integer . MAX_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { int g = A [ i ] ; for ( int j = i + 1 ; j < N ; j ++ ) { g = __gcd ( A [ j ] , g ) ; if ( g == 1 ) { minimum = Math . min ( minimum , j - i ) ; break ; } } } if ( minimum == Integer . MAX_VALUE ) return - 1 ; else return N + minimum - 1 ; } public static void main ( String [ ] args ) { int A [ ] = { 2 , 4 , 3 , 9 } ; int N = A . length ; System . out . print ( minimumMoves ( A , N ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find GCD of each subtree of a given node in an N | C # program to find GCD of each subtree for a given node by Q queries ; Maximum Number of nodes ; Tree represented as adjacency list ; For storing value associates with node ; For storing GCD of every subarray ; Number of nodes ; Function to find GCD of two numbers using Euclidean algo ; If b == 0 then simply return a ; DFS function to traverse the tree ; Initializing answer with GCD of this node . ; Iterate over each child of current node ; Skipping the parent ; Call DFS for each child ; Taking GCD of the answer of the child to find node 's GCD ; Calling DFS from the root ( 1 ) for precomputing answers ; Function to find and print GCD for Q queries ; Doing preprocessing ; iterate over each given query ; Driver code ; Tree : 1 ( 2 ) \\/ \\\\ 2 ( 3 ) 3 ( 4 ) \\/ \\\\ 4 ( 8 ) 5 ( 16 ) ; Making a undirected tree ; Values associated with nodes ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; public class GFG { static int N = ( int ) ( 1e5 + 5 ) ; static List < int > [ ] v = new List < int > [ N ] ; static int [ ] val = new int [ N ] ; static int [ ] answer = new int [ N ] ; static int n ; static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static void DFS ( int node , int parent ) { answer [ node ] = val [ node ] ; foreach ( int child in v [ node ] ) { if ( child == parent ) continue ; DFS ( child , node ) ; answer [ node ] = gcd ( answer [ node ] , answer [ child ] ) ; } } static void preprocess ( ) { DFS ( 1 , - 1 ) ; } static void findGCD ( int [ ] queries , int q ) { preprocess ( ) ; for ( int i = 0 ; i < q ; i ++ ) { int GCD = answer [ queries [ i ] ] ; Console . Write ( \\\" For \u2581 subtree \u2581 of \u2581 \\\" + queries [ i ] + \\\" , \u2581 GCD \u2581 = \u2581 \\\" + GCD + \\\" \\n \\\" ) ; } } public static void Main ( String [ ] args ) { n = 5 ; for ( int i = 0 ; i < v . Length ; i ++ ) v [ i ] = new List < int > ( ) ; v [ 1 ] . Add ( 2 ) ; v [ 2 ] . Add ( 1 ) ; v [ 1 ] . Add ( 3 ) ; v [ 3 ] . Add ( 1 ) ; v [ 3 ] . Add ( 4 ) ; v [ 4 ] . Add ( 3 ) ; v [ 3 ] . Add ( 5 ) ; v [ 5 ] . Add ( 3 ) ; val [ 1 ] = 2 ; val [ 2 ] = 3 ; val [ 3 ] = 4 ; val [ 4 ] = 8 ; val [ 5 ] = 16 ; int [ ] queries = { 2 , 3 , 1 } ; int q = queries . Length ; findGCD ( queries , q ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find a partition point in array to maximize its xor sum | Function to calculate Prefix Xor array ; Calculating prefix xor ; Function to find partition point in array to maximize xor sum ; To store prefix xor ; Compute the prefix xor ; To store sum and index ; Calculate the maximum sum that can be obtained splitting the array at some index i ; PrefixXor [ i ] = Xor of all arr elements till i ' th \u2581 index \u2581 PrefixXor [ n - 1 ] \u2581 \u2581 ^ \u2581 PrefixXor [ i ] \u2581 = \u2581 Xor \u2581 of \u2581 all \u2581 elements \u2581 \u2581 from \u2581 i + 1' th index to n - 1 'th index ; Return the index ; Driver code ; Function call\\\"\\nSolution in Javascript:\",\"targets\":\"function ComputePrefixXor ( arr , PrefixXor , n ) { PrefixXor [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) PrefixXor [ i ] = PrefixXor [ i - 1 ] ^ arr [ i ] ; } function Xor_Sum ( arr , n ) { let PrefixXor = new Array ( n ) ; ComputePrefixXor ( arr , PrefixXor , n ) ; let sum = 0 , index ; for ( let i = 0 ; i < n ; i ++ ) { if ( PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) > sum ) { sum = PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) ; index = i ; } } return index + 1 ; } let arr = [ 1 , 4 , 6 , 3 , 8 , 13 , 34 , 2 , 21 , 10 ] ; let n = arr . length ; document . write ( Xor_Sum ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Convert given string so that it holds only distinct characters | C # implementation of the approach ; Function to return the index of the character that has 0 occurrence starting from index i ; If current character has 0 occurrence ; If no character has 0 occurrence ; Function to return the modified string which consists of distinct characters ; String cannot consist of all distinct characters ; Count the occurrences for each of the character ; Index for the first character that hasn 't appeared in the string ; If current character appeared more than once then it has to be replaced with some character that hasn 't occurred yet ; Decrement current character 's occurrence by 1 ; Replace the character ; Update the new character ' s \u2581 occurrence \u2581 \u2581 This \u2581 step \u2581 can \u2581 also \u2581 be \u2581 skipped \u2581 \u2581 as \u2581 we ' ll never encounter this character in the string because it has been added just now ; Find the next character that hasn 't occurred yet ; Return the modified string ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int nextZero ( int i , int [ ] occurrences ) { while ( i < occurrences . Length ) { if ( occurrences [ i ] == 0 ) return i ; i ++ ; } return - 1 ; } static string getModifiedString ( string str ) { int n = str . Length ; if ( n > 26 ) return \\\" - 1\\\" ; char [ ] ch = str . ToCharArray ( ) ; int [ ] occurrences = new int [ 26 ] ; int i ; for ( i = 0 ; i < n ; i ++ ) occurrences [ ch [ i ] - ' a ' ] ++ ; int index = nextZero ( 0 , occurrences ) ; for ( i = 0 ; i < n ; i ++ ) { if ( occurrences [ ch [ i ] - ' a ' ] > 1 ) { occurrences [ ch [ i ] - ' a ' ] -- ; ch [ i ] = ( char ) ( ' a ' + index ) ; occurrences [ index ] = 1 ; index = nextZero ( index + 1 , occurrences ) ; } } string s = new string ( ch ) ; return s ; } public static void Main ( ) { string str = \\\" geeksforgeeks \\\" ; Console . WriteLine ( getModifiedString ( str ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Replace every matrix element with maximum of GCD of row or column | Java program to replace each each element with maximum of GCD of row or column . ; returning the greatest common divisor of two number ; Finding GCD of each row and column and replacing with each element with maximum of GCD of row or column . ; Calculating GCD of each row and each column in O ( mn ) and store in arrays . ; Replacing matrix element ; Driver program\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static int R = 3 ; static int C = 4 ; static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static void replacematrix ( int [ ] [ ] mat , int n , int m ) { int [ ] rgcd = new int [ R ] ; int [ ] cgcd = new int [ C ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { rgcd [ i ] = gcd ( rgcd [ i ] , mat [ i ] [ j ] ) ; cgcd [ j ] = gcd ( cgcd [ j ] , mat [ i ] [ j ] ) ; } } for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) mat [ i ] [ j ] = Math . max ( rgcd [ i ] , cgcd [ j ] ) ; } static public void main ( String [ ] args ) { int [ ] [ ] m = { { 1 , 2 , 3 , 3 } , { 4 , 5 , 6 , 6 } , { 7 , 8 , 9 , 9 } , } ; replacematrix ( m , R , C ) ; for ( int i = 0 ; i < R ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) System . out . print ( m [ i ] [ j ] + \\\" \u2581 \\\" ) ; System . out . println ( ) ; } } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Program to find area of a Trapezoid | Function for the area ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function Area ( $ b1 , $ b2 , $ h ) { return ( ( $ b1 + $ b2 ) \\/ 2 ) * $ h ; } $ base1 = 8 ; $ base2 = 10 ; $ height = 6 ; $ area = Area ( $ base1 , $ base2 , $ height ) ; echo ( \\\" Area \u2581 is : \u2581 \\\" ) ; echo ( $ area ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Permutation Coefficient | Returns value of Permutation Coefficient P ( n , k ) ; base case ; Calculate value factorials up to n ; P ( n , k ) = n ! \\/ ( n - k ) ! ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function permutationCoeff ( $ n , $ k ) { $ fact = array ( ) ; $ fact [ 0 ] = 1 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) $ fact [ $ i ] = $ i * $ fact [ $ i - 1 ] ; return $ fact [ $ n ] \\/ $ fact [ $ n - $ k ] ; } $ n = 10 ; $ k = 2 ; echo \\\" Value \u2581 of \u2581 P ( \\\" , $ n , \\\" \u2581 \\\" , $ k , \\\" ) \u2581 is \u2581 \\\" , permutationCoeff ( $ n , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Smallest power of 2 greater than or equal to n | PHP program to find smallest power of 2 greater than or equal to n ; First n in the below condition is for the case where n is 0 ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function nextPowerOf2 ( $ n ) { $ count = 0 ; if ( $ n && ! ( $ n & ( $ n - 1 ) ) ) return $ n ; while ( $ n != 0 ) { $ n >>= 1 ; $ count += 1 ; } return 1 << $ count ; } $ n = 0 ; echo ( nextPowerOf2 ( $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Total time required to travel a path denoted by a given string | Java program for above approach ; Function to calculate time taken to travel the path ; Stores total time ; Initial position ; Stores visited segments ; Check whether segment is present in the set ; Increment the value of time by 2 ; Insert segment into the set ; Print the value of time ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static void calcTotalTime ( String path ) { int time = 0 ; int x = 0 , y = 0 ; Set < String > s = new HashSet < > ( ) ; for ( int i = 0 ; i < path . length ( ) ; i ++ ) { int p = x ; int q = y ; if ( path . charAt ( i ) == ' N ' ) y ++ ; else if ( path . charAt ( i ) == ' S ' ) y -- ; else if ( path . charAt ( i ) == ' E ' ) x ++ ; else if ( path . charAt ( i ) == ' W ' ) x -- ; String o = ( p + x ) + \\\" \u2581 \\\" + ( q + y ) ; if ( ! s . contains ( o ) ) { time += 2 ; s . add ( o ) ; } else time += 1 ; } System . out . println ( time ) ; } public static void main ( String [ ] args ) { String path = \\\" NSE \\\" ; calcTotalTime ( path ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count trailing zero bits using lookup table | Simple C # code for counting trailing zeros in binary representation of a number ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { public static int countTrailingZero ( int x ) { int count = 0 ; while ( ( x & 1 ) == 0 ) { x = x >> 1 ; count ++ ; } return count ; } static public void Main ( ) { Console . WriteLine ( countTrailingZero ( 11 ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count of repeating digits in a given Number | Function that returns the count of repeating digits of the given number ; Initialize a variable to store count of Repeating digits ; Initialize cnt array to store digit count ; Iterate through the digits of N ; Retrieve the last digit of N ; Increase the count of digit ; Remove the last digit of N ; Iterate through the cnt array ; If frequency of digit is greater than 1 ; Increment the count of Repeating digits ; Return count of repeating digit ; Given array arr [ ] ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function countRepeatingDigits ( N ) { var res = 0 ; var cnt = Array ( 10 ) . fill ( 0 ) ; while ( N > 0 ) { var rem = N % 10 ; cnt [ rem ] ++ ; N = N \\/ 10 ; } for ( var i = 0 ; i < 10 ; i ++ ) { if ( cnt [ i ] > 1 ) { res ++ ; } } return res ; } var N = 12 ; document . write ( countRepeatingDigits ( N ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Generate a string whose all K | Java program to generate a string whose substrings of length K concatenates to form given strings ; Function to return the required required string ; Iterate the given string ; Append the first character of every substring of length K ; Consider all characters from the last substring ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { public static void decode_String ( String str , int K ) { String ans = \\\" \\\" ; for ( int i = 0 ; i < str . length ( ) ; i += K ) ans += str . charAt ( i ) ; for ( int i = str . length ( ) - ( K - 1 ) ; i < str . length ( ) ; i ++ ) ans += str . charAt ( i ) ; System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int K = 3 ; String str = \\\" abcbcscsesesesd \\\" ; decode_String ( str , K ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Permutation Coefficient | A Dynamic Programming based solution that uses table P [ ] [ ] to calculate the Permutation Coefficient ; Returns value of Permutation Coefficient P ( n , k ) ; Calculate value of Permutation Coefficient in bottom up manner ; Base Cases ; Calculate value using previosly stored values ; This step is important as P ( i , j ) = 0 for j > i ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\nint permutationCoeff ( int n , int k ) { int P [ n + 1 ] [ k + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= std : : min ( i , k ) ; j ++ ) { if ( j == 0 ) P [ i ] [ j ] = 1 ; else P [ i ] [ j ] = P [ i - 1 ] [ j ] + ( j * P [ i - 1 ] [ j - 1 ] ) ; P [ i ] [ j + 1 ] = 0 ; } } return P [ n ] [ k ] ; } int main ( ) { int n = 10 , k = 2 ; printf ( \\\" Value \u2581 of \u2581 P ( % d , \u2581 % d ) \u2581 is \u2581 % d \u2581 \\\" , n , k , permutationCoeff ( n , k ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if array contains contiguous integers with duplicates allowed | Function to check whether the array contains a set of contiguous integers ; Storing elements of ' arr [ ] ' in a hash table ' us ' ; as arr [ 0 ] is present in ' us ' ; starting with previous smaller element of arr [ 0 ] ; if ' curr _ ele ' is present in ' us ' ; increment count ; update 'curr_ele\\\" ; starting with next greater element of arr [ 0 ] ; if ' curr _ ele ' is present in ' us ' ; increment count ; update 'curr_ele\\\" ; returns true if array contains a set of contiguous integers else returns false ; Driver program to test above\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function areElementsContiguous ( arr , n ) { var us = new Set ( ) ; for ( var i = 0 ; i < n ; i ++ ) us . add ( arr [ i ] ) ; var count = 1 ; var curr_ele = arr [ 0 ] - 1 ; while ( us . has ( curr_ele ) ) { count ++ ; curr_ele -- ; } curr_ele = arr [ 0 ] + 1 ; while ( us . has ( curr_ele ) ) { count ++ ; curr_ele ++ ; } return ( count == ( us . size ) ) ; } var arr = [ 5 , 2 , 3 , 6 , 4 , 4 , 6 , 6 ] ; var n = arr . length ; if ( areElementsContiguous ( arr , n ) ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Given a HUGE number check if it 's a power of two. | Java program to find whether a number is power of 2 or not ; returns 1 when str is power of 2 return 0 when str is not a power of 2 ; sum stores the intermediate dividend while dividing . ; if the input is \\\"1\\\" then return 0 because 2 ^ k = 1 where k >= 1 and here k = 0 ; Divide the number until it gets reduced to 1 if we are successfully able to reduce the number to 1 it means input string is power of two if in between an odd number appears at the end it means string is not divisible by two hence not a power of 2. ; if the last digit is odd then string is not divisible by 2 hence not a power of two return 0. ; divide the whole string by 2. i is used to track index in current number . j is used to track index for next iteration . ; if num < 2 then we have to take another digit to the right of A [ i ] to make it bigger than A [ i ] . E . g . 214 \\/ 2 -- > 107 ; if it 's not the first index. E.g 214 then we have to include 0. ; for eg . \\\"124\\\" we will not write 064 so if it is the first index just ignore ; After every division by 2 the length of string is changed . ; if the string reaches to 1 then the str is a power of 2. ; Driver code .\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static int isPowerOf2 ( String s ) { char [ ] str = s . toCharArray ( ) ; int len_str = s . length ( ) ; int num = 0 ; if ( len_str == 1 && str [ len_str - 1 ] == '1' ) return 0 ; while ( len_str != 1 str [ len_str - 1 ] != '1' ) { if ( ( str [ len_str - 1 ] - '0' ) % 2 == 1 ) return 0 ; int j = 0 ; for ( int i = 0 ; i < len_str ; i ++ ) { num = num * 10 + ( int ) str [ i ] - ( int ) '0' ; if ( num < 2 ) { if ( i != 0 ) str [ j ++ ] = '0' ; continue ; } str [ j ++ ] = ( char ) ( ( int ) ( num \\/ 2 ) + ( int ) '0' ) ; num = ( num ) - ( num \\/ 2 ) * 2 ; } str [ j ] = ' \\\\0' ; len_str = j ; } return 1 ; } public static void main ( String [ ] args ) { String str1 = \\\"124684622466842024680246842024662202000002\\\" ; String str2 = \\\"1\\\" ; String str3 = \\\"128\\\" ; System . out . println ( isPowerOf2 ( str1 ) + \\\"\\n\\\"+isPowerOf2(str2) +\\n\\\"\\n\\\"+isPowerOf2(str3)); } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Compute the minimum or maximum of two integers without branching | ; Function to find minimum of x and y ; Function to find maximum of x and y ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\n#define CHAR_BIT 8\\nint min ( int x , int y ) { return y + ( ( x - y ) & ( ( x - y ) >> ( sizeof ( int ) * CHAR_BIT - 1 ) ) ) ; } int max ( int x , int y ) { return x - ( ( x - y ) & ( ( x - y ) >> ( sizeof ( int ) * CHAR_BIT - 1 ) ) ) ; } int main ( ) { int x = 15 ; int y = 6 ; printf ( \\\" Minimum \u2581 of \u2581 % d \u2581 and \u2581 % d \u2581 is \u2581 \\\" , x , y ) ; printf ( \\\" % d \\\" , min ( x , y ) ) ; printf ( \\\" Maximum of % d and % d is \\\" printf ( \\\" % d \\\" , max ( x , y ) ) ; getchar ( ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count of pairs in an Array with same number of set bits | C # program to count possible number of pairs of elements with same number of set bits . ; Function to return the count of Pairs ; Get the maximum element ; Array to store count of bits of all elements upto maxm ; Store the set bits for powers of 2 ; Compute the set bits for the remaining elements ; Store the frequency of respective counts of set bits ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections ; using System . Collections . Generic ; using System . Text ; class GFG { static int countPairs ( int [ ] arr , int N ) { int maxm = - int . MaxValue ; for ( int j = 0 ; j < N ; j ++ ) { if ( maxm < arr [ j ] ) { maxm = arr [ j ] ; } } int i , k = 0 ; int [ ] bitscount = new int [ maxm + 1 ] ; Array . Fill ( bitscount , 0 ) ; for ( i = 1 ; i <= maxm ; i *= 2 ) bitscount [ i ] = 1 ; for ( i = 1 ; i <= maxm ; i ++ ) { if ( bitscount [ i ] == 1 ) k = i ; if ( bitscount [ i ] == 0 ) { bitscount [ i ] = bitscount [ k ] + bitscount [ i - k ] ; } } Dictionary < int , int > setbits = new Dictionary < int , int > ( ) ; for ( int j = 0 ; j < N ; j ++ ) { if ( setbits . ContainsKey ( bitscount [ arr [ j ] ] ) ) { setbits [ bitscount [ arr [ j ] ] ] ++ ; } else { setbits [ bitscount [ arr [ j ] ] ] = 1 ; } } int ans = 0 ; foreach ( KeyValuePair < int , int > it in setbits ) { ans += it . Value * ( it . Value - 1 ) \\/ 2 ; } return ans ; } public static void Main ( string [ ] args ) { int N = 12 ; int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 } ; Console . Write ( countPairs ( arr , N ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find the smallest missing number | function that returns smallest elements missing in a sorted array . ; Left half has all elements from 0 to mid ; driver program to test above function\\\"\\nSolution in Python:\",\"targets\":\"def findFirstMissing ( array , start , end ) :\\n\\tif ( start > end ) :\\n\\t\\treturn end + 1\\n\\tif ( start != array [ start ] ) :\\n\\t\\treturn start ;\\n\\tmid = int ( ( start + end ) \\/ 2 )\\n\\tif ( array [ mid ] == mid ) :\\n\\t\\treturn findFirstMissing ( array , mid + 1 , end )\\n\\treturn findFirstMissing ( array , start , mid )\\narr = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 10 ]\\nn = len ( arr )\\nprint ( \\\" Smallest \u2581 missing \u2581 element \u2581 is \\\" , findFirstMissing ( arr , 0 , n - 1 ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sum of series with alternate signed squares of AP | function to calculate series sum ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function seiresSum ( $ n , $ a ) { $ res = 0 ; for ( $ i = 0 ; $ i < 2 * $ n ; $ i ++ ) { if ( $ i % 2 == 0 ) $ res += $ a [ $ i ] * $ a [ $ i ] ; else $ res -= $ a [ $ i ] * $ a [ $ i ] ; } return $ res ; } $ n = 2 ; $ a = array ( 1 , 2 , 3 , 4 ) ; echo seiresSum ( $ n , $ a ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Modify N by adding its smallest positive divisor exactly K times | C # program to implement the above approach ; Function to find the smallest divisor of N greater than 1 ; If i is a divisor of N ; If N is a prime number ; Function to find the value of N by performing the operations K times ; If N is an even number ; Update N ; If N is an odd number ; Update N ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int smallestDivisorGr1 ( int N ) { for ( int i = 2 ; i <= Math . Sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { return i ; } } return N ; } static int findValOfNWithOperat ( int N , int K ) { if ( N % 2 == 0 ) { N += K * 2 ; } else { N += smallestDivisorGr1 ( N ) + ( K - 1 ) * 2 ; } return N ; } static public void Main ( ) { int N = 6 , K = 4 ; Console . Write ( findValOfNWithOperat ( N , K ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find all elements in array which have at | Sorting based Javascript program to find all elements in array which have atleast two greater elements itself . ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function findElements ( arr , n ) { arr . sort ( ) ; for ( let i = 0 ; i < n - 2 ; i ++ ) document . write ( arr [ i ] + \\\" \\\" ) ; } let arr = [ 2 , - 6 , 3 , 5 , 1 ] ; let n = arr . length ; findElements ( arr , n ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if N can be represented as sum of integers chosen from set { A , B } | CPP program to find if number N can be represented as sum of a ' s \u2581 and \u2581 b ' s ; Function to find if number N can be represented as sum of a ' s \u2581 and \u2581 b ' s ; base condition ; if x is already visited ; set x as possible ; recursive call ; Driver program\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void checkIfPossibleRec ( int x , int a , int b , bool isPossible [ ] , int n ) { if ( x > n ) return ; if ( isPossible [ x ] ) return ; isPossible [ x ] = true ; checkIfPossibleRec ( x + a , a , b , isPossible , n ) ; checkIfPossibleRec ( x + b , a , b , isPossible , n ) ; } bool checkPossible ( int n , int a , int b ) { bool isPossible [ n + 1 ] = { false } ; checkIfPossibleRec ( 0 , a , b , isPossible , n ) ; return isPossible [ n ] ; } int main ( ) { int a = 3 , b = 7 , n = 8 ; if ( checkPossible ( a , b , n ) ) cout << \\\" Yes \\\" ; else cout << \\\" No \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the Perimeter of a Regular Polygon | C program to find the perimeter of a regular polygon ; Function to calculate the perimeter ; Calculate Perimeter ; driver code ; Get the number of sides ; Get the length of side ; find perimeter\\\"\\nSolution in C:\",\"targets\":\"#include \\nfloat Perimeter ( float s , int n ) { float perimeter = 1 ; perimeter = n * s ; return perimeter ; } int main ( ) { int n = 5 ; float s = 2.5 , peri ; peri = Perimeter ( s , n ) ; printf ( \\\" Perimeter \u2581 of \u2581 Regular \u2581 Polygon \\n \\\" \\\" \u2581 with \u2581 % d \u2581 sides \u2581 of \u2581 length \u2581 % f \u2581 = \u2581 % f \\n \\\" , n , s , peri ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Modular multiplicative inverse | Returns modulo inverse of a with respect to m using extended Euclid Algorithm Assumption : a and m are coprimes , i . e . , gcd ( a , m ) = 1 ; q is quotient ; m is remainder now , process same as Euclid 's algo ; Update y and x ; Make x positive ; Driver Code ; Function call\\\"\\nSolution in php:\",\"targets\":\"< ? php function modInverse ( $ a , $ m ) { $ m0 = $ m ; $ y = 0 ; $ x = 1 ; if ( $ m == 1 ) return 0 ; while ( $ a > 1 ) { $ q = ( int ) ( $ a \\/ $ m ) ; $ t = $ m ; $ m = $ a % $ m ; $ a = $ t ; $ t = $ y ; $ y = $ x - $ q * $ y ; $ x = $ t ; } if ( $ x < 0 ) $ x += $ m0 ; return $ x ; } $ a = 3 ; $ m = 11 ; echo \\\" Modular \u2581 multiplicative \u2581 inverse \u2581 is \\n \\\" , modInverse ( $ a , $ m ) ; a . . . >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum operations to transform given string to another by moving characters to front or end | C # program for the above approach ; Function that finds the minimum number of steps to find the minimum characters must be moved to convert String s to t ; r = maximum value over all dp [ i , j ] computed so far ; dp [ i , j ] stores the longest contiguous suffix of T [ 0. . j ] that is subsequence of S [ 0. . i ] ; Update the maximum length ; Return the resulting length ; Driver Code ; Given String s , t ; Function Call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int [ , ] dp = new int [ 1010 , 1010 ] ; static int solve ( String s , String t ) { int n = s . Length ; int r = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dp [ i , j ] = 0 ; if ( i > 0 ) { dp [ i , j ] = Math . Max ( dp [ i - 1 , j ] , dp [ i , j ] ) ; } if ( s [ i ] == t [ j ] ) { int ans = 1 ; if ( i > 0 && j > 0 ) { ans = 1 + dp [ i - 1 , j - 1 ] ; } dp [ i , j ] = Math . Max ( dp [ i , j ] , ans ) ; r = Math . Max ( r , dp [ i , j ] ) ; } } } return ( n - r ) ; } public static void Main ( String [ ] args ) { String s = \\\" abcde \\\" ; String t = \\\" edacb \\\" ; Console . Write ( solve ( s , t ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find Nth item distributed from infinite items of infinite types based on given conditions | Function to find the type of the item given out according to the given rules ; Stores the count of item given out at each step ; Iterate over the days from 1 ; Iterate over type of item on that day ; Count of items given out should exceed n ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def itemType ( n ) :\\n\\tcount = 0\\n\\tday = 1\\n\\twhile ( True ) :\\n\\t\\tfor type in range ( day , 0 , - 1 ) :\\n\\t\\t\\tcount += type\\n\\t\\t\\tif ( count >= n ) :\\n\\t\\t\\t\\treturn type\\nN = 10\\nprint ( itemType ( N ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Pascal 's Triangle | C program for Pascals Triangle A O ( n ^ 2 ) time and O ( 1 ) extra space function for Pascal 's Triangle ; used to represent C ( line , i ) ; The first value in a line is always 1 ; Driver code\\\"\\nSolution in C:\",\"targets\":\"void printPascal ( int n ) { for ( int line = 1 ; line <= n ; line ++ ) { int C = 1 ; for ( int i = 1 ; i <= line ; i ++ ) { printf ( \\\" % d \u2581 \\\" , C ) ; C = C * ( line - i ) \\/ i ; } printf ( \\\" \\n \\\" ) ; } } int main ( ) { int n = 5 ; printPascal ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Distribute M objects starting from Sth person such that every ith person gets arr [ i ] objects | Function to find distribution of M objects among all array elements ; Stores the distribution of M objects ; Stores the indices of distribution ; Stores the remaining objects ; Iterate until rem is positive ; If the number of remaining objects exceeds required the number of objects ; Increase the number of objects for the index ptr by arr [ ptr ] ; Decrease remaining objects by arr [ ptr ] ; Increase the number of objects for the index ptr by rem ; Decrease remaining objects to 0 ; Increase ptr by 1 ; Print the final distribution ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function distribute ( N , K , M , arr ) { let distribution = new Array ( N ) for ( let i = 0 ; i < N ; i ++ ) { distribution [ i ] = 0 } let ptr = K - 1 ; let rem = M ; while ( rem > 0 ) { if ( rem >= arr [ ptr ] ) { distribution [ ptr ] += arr [ ptr ] ; rem -= arr [ ptr ] ; } else { distribution [ ptr ] += rem ; rem = 0 ; } ptr = ( ptr + 1 ) % N ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( distribution [ i ] + \\\" \\\" ) } } let arr = [ 2 , 3 , 2 , 1 , 4 ] ; let M = 11 , S = 2 ; let N = arr . length distribute ( N , S , M , arr ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Perform K of Q queries to maximize the sum of the array elements | C ++ implementation of the approach ; Function to perform K queries out of Q to maximize the final sum ; Get the initial sum of the array ; Stores the contriution of every query ; Sort the contribution of queries in descending order ; Get the K most contributions ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int getFinalSum ( int a [ ] , int n , pair < int , int > queries [ ] , int q , int k ) { int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) answer += a [ i ] ; vector < int > contribution ; for ( int i = 0 ; i < q ; i ++ ) { contribution . push_back ( queries [ i ] . second - queries [ i ] . first + 1 ) ; } sort ( contribution . begin ( ) , contribution . end ( ) , greater < int > ( ) ) ; int i = 0 ; while ( i < k ) { answer += contribution [ i ] ; i ++ ; } return answer ; } int main ( ) { int a [ ] = { 1 , 1 , 2 , 2 , 2 , 3 } ; int n = sizeof ( a ) \\/ sizeof ( a [ 0 ] ) ; pair < int , int > queries [ ] = { { 0 , 4 } , { 1 , 2 } , { 2 , 5 } , { 2 , 3 } , { 2 , 4 } } ; int q = sizeof ( queries ) \\/ sizeof ( queries [ 0 ] ) ; int k = 3 ; cout << getFinalSum ( a , n , queries , q , k ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Automorphic Number | C ++ program to check if a number is Authomorphic ; Function to check Automorphic number ; Store the square ; Start Comparing digits ; Return false , if any digit of N doesn ' t \u2581 \u2581 match \u2581 with \u2581 its \u2581 square ' s digits from last ; Reduce N and square ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool isAutomorphic ( int N ) { int sq = N * N ; while ( N > 0 ) { if ( N % 10 != sq % 10 ) return false ; N \\/= 10 ; sq \\/= 10 ; } return true ; } int main ( ) { int N = 5 ; isAutomorphic ( N ) ? cout << \\\" Automorphic \\\" : cout << \\\" Not \u2581 Automorphic \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Largest Square in a Binary Matrix with at most K 1 s for multiple Queries | C ++ implementation to find the largest square in the matrix such that it contains atmost K 1 's ; Function to find the largest square in the matrix such that it contains atmost K 1 's ; Precomputation of the countDP prefix sum of the matrix ; Loop to solve each query ; Binary Search to the side which have atmost in K 1 's in square ; Count total number of 1 s in the sub square considered ; If the count is less than or equals to the maximum move to right half ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; const int MAX = 100 ; void largestSquare ( int matrix [ ] [ MAX ] , int R , int C , int q_i [ ] , int q_j [ ] , int K , int Q ) { int countDP [ R ] [ C ] ; memset ( countDP , 0 , sizeof ( countDP ) ) ; countDP [ 0 ] [ 0 ] = matrix [ 0 ] [ 0 ] ; for ( int i = 1 ; i < R ; i ++ ) countDP [ i ] [ 0 ] = countDP [ i - 1 ] [ 0 ] + matrix [ i ] [ 0 ] ; for ( int j = 1 ; j < C ; j ++ ) countDP [ 0 ] [ j ] = countDP [ 0 ] [ j - 1 ] + matrix [ 0 ] [ j ] ; for ( int i = 1 ; i < R ; i ++ ) for ( int j = 1 ; j < C ; j ++ ) countDP [ i ] [ j ] = matrix [ i ] [ j ] + countDP [ i - 1 ] [ j ] + countDP [ i ] [ j - 1 ] - countDP [ i - 1 ] [ j - 1 ] ; for ( int q = 0 ; q < Q ; q ++ ) { int i = q_i [ q ] ; int j = q_j [ q ] ; int min_dist = min ( min ( i , j ) , min ( R - i - 1 , C - j - 1 ) ) ; int ans = -1 , l = 0 , u = min_dist ; while ( l <= u ) { int mid = ( l + u ) \\/ 2 ; int x1 = i - mid , x2 = i + mid ; int y1 = j - mid , y2 = j + mid ; int count = countDP [ x2 ] [ y2 ] ; if ( x1 > 0 ) count -= countDP [ x1 - 1 ] [ y2 ] ; if ( y1 > 0 ) count -= countDP [ x2 ] [ y1 - 1 ] ; if ( x1 > 0 && y1 > 0 ) count += countDP [ x1 - 1 ] [ y1 - 1 ] ; if ( count <= K ) { ans = 2 * mid + 1 ; l = mid + 1 ; } else u = mid - 1 ; } cout << ans << \\\" \\n \\\" ; } } int main ( ) { int matrix [ ] [ MAX ] = { { 1 , 0 , 1 , 0 , 0 } , { 1 , 0 , 1 , 1 , 1 } , { 1 , 1 , 1 , 1 , 1 } , { 1 , 0 , 0 , 1 , 0 } } ; int K = 9 , Q = 1 ; int q_i [ ] = { 1 } ; int q_j [ ] = { 2 } ; largestSquare ( matrix , 4 , 5 , q_i , q_j , K , Q ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Area of a Regular Pentagram | Javascript implementation of the approach ; Function to return the area of triangle BCD ; Using Golden ratio ; Calculate area of triangle BCD ; Return area of all 5 triangle are same ; Function to return the area of regular pentagon ; Calculate the area of regular pentagon using above formula ; Return area of regular pentagon ; Function to return the area of pentagram ; Area of a pentagram is equal to the area of regular pentagon and five times the area of Triangle ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"var PI = 3.14159 function areaOfTriangle ( d ) { var c = 1.618 * d ; var s = ( d + c + c ) \\/ 2 ; var area = Math . sqrt ( s * ( s - c ) * ( s - c ) * ( s - d ) ) ; return 5 * area ; } function areaOfRegPentagon ( d ) { var cal = 4 * Math . tan ( PI \\/ 5 ) ; var area = ( 5 * d * d ) \\/ cal ; return area ; } function areaOfPentagram ( d ) { return areaOfRegPentagon ( d ) + areaOfTriangle ( d ) ; } var d = 5 ; document . write ( areaOfPentagram ( d ) . toFixed ( 3 ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Surface Area and Volume of Hexagonal Prism | Function to calculate Surface area ; Formula to calculate surface area ; Display surface area ; Function to calculate Volume ; formula to calculate Volume ; Display Volume ; Driver Code ; surface area function call ; volume function call\\\"\\nSolution in php:\",\"targets\":\"< ? php function findSurfaceArea ( $ a , $ h ) { $ Area ; $ Area = 6 * $ a * $ h + 3 * sqrt ( 3 ) * $ a * $ a ; echo \\\" Surface \u2581 Area : \u2581 \\\" , $ Area , \\\" \\n \\\" ; } function findVolume ( $ a , $ h ) { $ Volume ; $ Volume = 3 * sqrt ( 3 ) * $ a * $ a * $ h \\/ 2 ; echo \\\" Volume : \u2581 \\\" , $ Volume ; } $ a = 5 ; $ h = 10 ; findSurfaceArea ( $ a , $ h ) ; findVolume ( $ a , $ h ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Apothem of a n | Function to find the apothem of a regular polygon ; Side and side length cannot be negative ; Degree converted to radians ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function polyapothem ( $ n , $ a ) { if ( $ a < 0 && $ n < 0 ) return -1 ; return $ a \\/ ( 2 * tan ( ( 180 \\/ $ n ) * 3.14159 \\/ 180 ) ) ; } $ a = 9 ; $ n = 6 ; echo polyapothem ( $ n , $ a ) . \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if string is right to left diagonal or not | Java program to check if the given string is right to left diagonal or not ; Function to check if the given string is right to left diagonal or not ; Iterate over string ; If character is not same as the first character then return false ; Driver Code ; Given String str ; Function call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { public static boolean is_rtol ( String s ) { int tmp = ( int ) ( Math . sqrt ( s . length ( ) ) ) - 1 ; char first = s . charAt ( tmp ) ; for ( int pos = tmp ; pos < s . length ( ) - 1 ; pos += tmp ) { if ( s . charAt ( pos ) != first ) { return false ; } } return true ; } public static void main ( String args [ ] ) { String str = \\\" abcxabxcaxbcxabc \\\" ; if ( is_rtol ( str ) ) { System . out . print ( \\\" Yes \\\" ) ; } else { System . out . print ( \\\" No \\\" ) ; } } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find first and last digits of a number | Find the first digit ; Remove last digit from number till only one digit is left ; return the first digit ; Find the last digit ; return the last digit ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function firstDigit ( $ n ) { while ( $ n >= 10 ) $ n \\/= 10 ; return ( int ) $ n ; } function lastDigit ( $ n ) { return ( ( int ) $ n % 10 ) ; } $ n = 98562 ; echo firstDigit ( $ n ) . \\\" \u2581 \\\" . lastDigit ( $ n ) . \\\" \\n \\\" ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Cutting a Rod | DP | C program for above approach ; Global Array for the purpose of memoization . ; A recursive program , using , memoization , to implement the rod cutting problem ( Top - Down ) . ; The maximum price will be zero , when either the length of the rod is zero or price is zero . ; If the length of the rod is less than the maximum length , Max_lene will consider it . Now depending upon the profit , either Max_lene we will take it or discard it . ; If the length of the rod is greater than the permitted size , Max_len we will not consider it . ; Max_lene Max_lenill return the maximum value obtained , Max_lenhich is present at the nth roMax_len and Max_lenth column . ; Driver program to test above functions ; Function Call\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nint max ( int a , int b ) { return ( a > b ) ? a : b ; } int t [ 9 ] [ 9 ] ; int un_kp ( int price [ ] , int length [ ] , int Max_len , int n ) { if ( n == 0 Max_len == 0 ) { return 0 ; } if ( length [ n - 1 ] <= Max_len ) { t [ n ] [ Max_len ] = max ( price [ n - 1 ] + un_kp ( price , length , Max_len - length [ n - 1 ] , n ) , un_kp ( price , length , Max_len , n - 1 ) ) ; } else { t [ n ] [ Max_len ] = un_kp ( price , length , Max_len , n - 1 ) ; } return t [ n ] [ Max_len ] ; } int main ( ) { int price [ ] = { 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 } ; int n = sizeof ( price ) \\/ sizeof ( price [ 0 ] ) ; int length [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { length [ i ] = i + 1 ; } int Max_len = n ; printf ( \\\" Maximum \u2581 obtained \u2581 value \u2581 is \u2581 % d \u2581 \\n \\\" , un_kp ( price , length , n , Max_len ) ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if it is possible to create a palindrome string from given N | C # implementation of the above approach ; Function to check if a string is palindrome or not ; String that stores characters of s in reverse order ; Length of the string s ; String used to form substring using N ; Variable to store sum of digits of N ; Forming the substring by traversing N ; Appending the substr to str till it 's length becomes equal to sum ; Trimming the string str so that it 's length becomes equal to sum ; Driver code ; Calling function isPalindrome to check if str is Palindrome or not\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static bool isPalindrome ( String s ) { String s1 = \\\" \\\" ; int N = s . Length ; for ( int i = N - 1 ; i >= 0 ; i -- ) s1 += s [ i ] ; if ( s . Equals ( s1 ) ) return true ; return false ; } static bool createString ( int N ) { String str = \\\" \\\" ; String s = \\\" \\\" + N ; String letters = \\\" abcdefghij \\\" ; int sum = 0 ; String substr = \\\" \\\" ; for ( int i = 0 ; i < s . Length ; i ++ ) { int digit = s [ i ] - '0' ; substr += letters [ digit ] ; sum += digit ; } while ( str . Length <= sum ) { str += substr ; } str = str . Substring ( 0 , sum ) ; return isPalindrome ( str ) ; } public static void Main ( ) { int N = 61 ; bool flag = createString ( N ) ; if ( flag ) Console . WriteLine ( \\\" YES \\\" ) ; else Console . WriteLine ( \\\" NO \\\" ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"Find the minimum element in a sorted and rotated array | C program to find minimum element in a sorted and rotated array ; This condition is needed to handle the case when array is not rotated at all ; If there is only one element left ; Find mid ; Check if element ( mid + 1 ) is minimum element . Consider the cases like { 3 , 4 , 5 , 1 , 2 } ; Check if mid itself is minimum element ; Decide whether we need to go to left half or right half ; Driver program to test above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint findMin ( int arr [ ] , int low , int high ) { if ( high < low ) return arr [ 0 ] ; if ( high == low ) return arr [ low ] ; int mid = low + ( high - low ) \\/ 2 ; if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ; if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ; if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ; return findMin ( arr , mid + 1 , high ) ; } int main ( ) { int arr1 [ ] = { 5 , 6 , 1 , 2 , 3 , 4 } ; int n1 = sizeof ( arr1 ) \\/ sizeof ( arr1 [ 0 ] ) ; printf ( \\\" The \u2581 minimum \u2581 element \u2581 is \u2581 % d \\n \\\" , findMin ( arr1 , 0 , n1 - 1 ) ) ; int arr2 [ ] = { 1 , 2 , 3 , 4 } ; int n2 = sizeof ( arr2 ) \\/ sizeof ( arr2 [ 0 ] ) ; printf ( \\\" The \u2581 minimum \u2581 element \u2581 is \u2581 % d \\n \\\" , findMin ( arr2 , 0 , n2 - 1 ) ) ; int arr3 [ ] = { 1 } ; int n3 = sizeof ( arr3 ) \\/ sizeof ( arr3 [ 0 ] ) ; printf ( \\\" The \u2581 minimum \u2581 element \u2581 is \u2581 % d \\n \\\" , findMin ( arr3 , 0 , n3 - 1 ) ) ; int arr4 [ ] = { 1 , 2 } ; int n4 = sizeof ( arr4 ) \\/ sizeof ( arr4 [ 0 ] ) ; printf ( \\\" The \u2581 minimum \u2581 element \u2581 is \u2581 % d \\n \\\" , findMin ( arr4 , 0 , n4 - 1 ) ) ; int arr5 [ ] = { 2 , 1 } ; int n5 = sizeof ( arr5 ) \\/ sizeof ( arr5 [ 0 ] ) ; printf ( \\\" The \u2581 minimum \u2581 element \u2581 is \u2581 % d \\n \\\" , findMin ( arr5 , 0 , n5 - 1 ) ) ; int arr6 [ ] = { 5 , 6 , 7 , 1 , 2 , 3 , 4 } ; int n6 = sizeof ( arr6 ) \\/ sizeof ( arr6 [ 0 ] ) ; printf ( \\\" The \u2581 minimum \u2581 element \u2581 is \u2581 % d \\n \\\" , findMin ( arr6 , 0 , n6 - 1 ) ) ; int arr7 [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; int n7 = sizeof ( arr7 ) \\/ sizeof ( arr7 [ 0 ] ) ; printf ( \\\" The \u2581 minimum \u2581 element \u2581 is \u2581 % d \\n \\\" , findMin ( arr7 , 0 , n7 - 1 ) ) ; int arr8 [ ] = { 2 , 3 , 4 , 5 , 6 , 7 , 8 , 1 } ; int n8 = sizeof ( arr8 ) \\/ sizeof ( arr8 [ 0 ] ) ; printf ( \\\" The \u2581 minimum \u2581 element \u2581 is \u2581 % d \\n \\\" , findMin ( arr8 , 0 , n8 - 1 ) ) ; int arr9 [ ] = { 3 , 4 , 5 , 1 , 2 } ; int n9 = sizeof ( arr9 ) \\/ sizeof ( arr9 [ 0 ] ) ; printf ( \\\" The \u2581 minimum \u2581 element \u2581 is \u2581 % d \\n \\\" , findMin ( arr9 , 0 , n9 - 1 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Print all numbers up to N in words in lexicographical order | Function to convert a number to words ; Stores the digits ; Base cases ; Stores strings of unit place ; Stores strings for corner cases ; Stores strings for ten 's place digits ; Stores strings for powers of 10 ; If given number contains a single digit ; Iterate over all the digits ; Represent first 2 digits in words ; Represent last 2 digits in words ; Explicitly handle corner cases [ 10 , 19 ] ; Explicitly handle corner case 20 ; For rest of the two digit numbers i . e . , 21 to 99 ; Function to print all the numbers up to n in lexicographical order ; Convert all numbers in words ; Sort all strings ; Print answer ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function convert_to_words ( n ) { let num = ( n ) . toString ( ) . split ( \\\" \\\" ) ; let len = num . length ; let ans = \\\" \\\" ; if ( len == 0 ) { ans += \\\" \\\" ; return ans ; } let single_digits = [ \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" ] ; let two_digits = [ \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" ] ; let tens_multiple = [ \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" ] ; let tens_power = [ \\\" \\\" , \\\" \\\" ] ; if ( len == 1 ) { ans += single_digits [ num [ 0 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; return ans ; } let x = 0 ; while ( x < num . length ) { if ( len >= 3 ) { if ( num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) != 0 ) { ans += single_digits [ num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; ans += \\\" \\\" ; ans += tens_power [ len - 3 ] ; ans += \\\" \\\" ; } -- len ; } else { if ( num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) == 1 ) { let sum = num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; ans += two_digits [ sum ] ; return ans ; } else if ( num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) == 2 && num [ x + 1 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) == 0 ) { ans += \\\" \\\" ; return ans ; } else { let i = ( num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; if ( i > 0 ) { ans += tens_multiple [ i ] ; ans += \\\" \\\" ; } else ans += \\\" \\\" ; ++ x ; if ( num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) != 0 ) ans += single_digits [ num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; } } ++ x ; } return \\\" \\\" ; } function lexNumbers ( n ) { let s = [ ] ; for ( let i = 1 ; i <= n ; i ++ ) { s . push ( convert_to_words ( i ) ) ; } s . sort ( ) let ans = [ ] ; for ( let i = 0 ; i < n ; i ++ ) ans . push ( s [ i ] ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) document . write ( ans [ i ] + \\\" \\\" ) ; document . write ( ans [ n - 1 ] ) ; } let n = 5 ; lexNumbers ( n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum steps to convert one binary string to other only using negation | Function to find the minimum steps to convert string a to string b ; array to mark the positions needed to be negated ; If two character are not same then they need to be negated ; To count the blocks of 1 ; To count the number of 1 ' s \u2581 in \u2581 \u2581 each \u2581 block \u2581 of \u2581 1' s ; For the last block of 1 's ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function convert ( n , a , b ) { let l = new Array ( n ) ; let i ; for ( i = 0 ; i < n ; i ++ ) l [ i ] = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] ) l [ i ] = 1 ; } let cc = 0 ; let vl = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( l [ i ] == 0 ) { if ( vl != 0 ) cc += 1 ; vl = 0 ; } else vl += 1 ; } if ( vl != 0 ) cc += 1 ; document . write ( cc + \\\" \\\" ) ; } let a = \\\" \\\" ; let b = \\\" \\\" ; let n = a . length ; convert ( n , a , b ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find all divisors of a natural number | Set 2 | A O ( sqrt ( n ) ) program that prints all divisors in sorted order ; function to print the divisors ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nvoid printDivisors ( int n ) { int i ; for ( i = 1 ; i * i < n ; i ++ ) { if ( n % i == 0 ) printf ( \\\" % d \u2581 \\\" , i ) ; } if ( i - ( n \\/ i ) == 1 ) { i -- ; } for ( ; i >= 1 ; i -- ) { if ( n % i == 0 ) printf ( \\\" % d \u2581 \\\" , n \\/ i ) ; } } int main ( ) { printf ( \\\" The \u2581 divisors \u2581 of \u2581 100 \u2581 are : \u2581 \\n \\\" ) ; printDivisors ( 100 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximum splits in binary string such that each substring is divisible by given odd number | Function to calculate maximum splits possible ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function rearrange ( str , K ) { var n = str . length ; var s = 0 , sum = 0 , count = 0 ; for ( var i = n - 1 ; i >= 0 ; i -- ) { var a = str . charAt ( i ) - ' ' ; sum += a * Math . pow ( 2 , s ) ; s ++ ; if ( sum != 0 && sum % K == 0 ) { count ++ ; sum = 0 ; s = 0 ; } } if ( sum != 0 ) document . write ( \\\" \\\" ) ; else document . write ( count ) ; } var str = \\\" \\\" ; var K = 5 ; rearrange ( str , K ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if all 3 Candy bags can be emptied by removing 2 candies from any one bag and 1 from the other two repeatedly | Python code for the above approach ; If total candies are not multiple of 4 then its not possible to be left with 0 candies ; If minimum candies of three bags are less than number of operations required then the task is not possible ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def can_empty ( a , b , c ) :\\n\\tif ( ( a + b + c ) % 4 != 0 ) :\\n\\t\\treturn False ;\\n\\telse :\\n\\t\\tm = min ( a , min ( b , c ) ) ;\\n\\t\\tif ( m < ( a + b + c ) \\/\\/ 4 ) :\\n\\t\\t\\treturn False ;\\n\\treturn True ;\\na = 4\\nb = 2\\nc = 2\\nprint ( \\\" true \\\" if can_empty ( a , b , c ) else \\\" false \\\" ) ;\\na = 3\\nb = 4\\nc = 2\\nprint ( \\\" true \\\" if can_empty ( a , b , c ) else \\\" false \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Segregate 0 s and 1 s in an array | Java code to Segregate 0 s and 1 s in an array ; function to segregate 0 s and 1 s ; counts the no of zeros in arr ; loop fills the arr with 0 until count ; loop fills remaining arr space with 1 ; function to print segregated array ; driver function\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static void segregate0and1 ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) count ++ ; } for ( int i = 0 ; i < count ; i ++ ) arr [ i ] = 0 ; for ( int i = count ; i < n ; i ++ ) arr [ i ] = 1 ; } static void print ( int arr [ ] , int n ) { System . out . print ( \\\" Array \u2581 after \u2581 segregation \u2581 is \u2581 \\\" ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + \\\" \u2581 \\\" ) ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 0 , 1 , 0 , 1 , 1 , 1 } ; int n = arr . length ; segregate0and1 ( arr , n ) ; print ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Pairs of complete strings in two sets of strings | Returns count of complete pairs from set [ 0. . n - 1 ] and set2 [ 0. . m - 1 ] ; con_s1 [ i ] is going to store an integer whose set bits represent presence \\/ absence of characters in string set1 [ i ] . Similarly con_s2 [ i ] is going to store an integer whose set bits represent presence \\/ absence of characters in string set2 [ i ] ; Process all strings in set1 [ ] ; initializing all bits to 0 ; Setting the ascii code of char s [ i ] [ j ] to 1 in the compressed integer . ; Process all strings in set2 [ ] ; initializing all bits to 0 ; setting the ascii code of char s [ i ] [ j ] to 1 in the compressed integer . ; assigning a variable whose all 26 ( 0. . 25 ) bits are set to 1 ; Now consider every pair of integer in con_s1 [ ] and con_s2 [ ] and check if the pair is complete . ; if all bits are set , the strings are complete ! ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function countCompletePairs ( set1 , set2 , n , m ) { let result = 0 ; let con_s1 = new Array ( n ) ; let con_s2 = new Array ( m ) ; for ( let i = 0 ; i < n ; i ++ ) { con_s1 [ i ] = 0 ; for ( let j = 0 ; j < set1 [ i ] . length ; j ++ ) { con_s1 [ i ] = con_s1 [ i ] | ( 1 << ( set1 [ i ] [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ; } } for ( let i = 0 ; i < m ; i ++ ) { con_s2 [ i ] = 0 ; for ( let j = 0 ; j < set2 [ i ] . length ; j ++ ) { con_s2 [ i ] = con_s2 [ i ] | ( 1 << ( set2 [ i ] [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ; } } let complete = ( 1 << 26 ) - 1 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( ( con_s1 [ i ] con_s2 [ j ] ) == complete ) { result ++ ; } } } return result ; } let set1 = [ \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" ] ; let set2 = [ \\\" \\\" , \\\" \\\" , \\\" \\\" ] let n = set1 . length ; let m = set2 . length ; document . write ( countCompletePairs ( set1 , set2 , n , m ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find the Batting Average of a batsman | C # program to calculate the average of a batsman ; Function to find the average of a batsman ; Calculate number of dismissals ; Check for 0 times out ; Calculate batting average ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int averageRuns ( int runs , int matches , int notout ) { int out1 ; out1 = matches - notout ; if ( out1 == 0 ) return - 1 ; int avg = ( runs ) \\/ out1 ; return avg ; } public static void Main ( string [ ] args ) { int runs = 10000 ; int matches = 250 ; int notout = 50 ; int avg = averageRuns ( runs , matches , notout ) ; if ( avg == - 1 ) Console . Write ( \\\" NA \\\" ) ; else Console . Write ( avg ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Permute two arrays such that sum of every pair is greater or equal to K | Check whether any permutation exists which satisfy the condition . ; Sort the array a [ ] in decreasing order . ; Sort the array b [ ] in increasing order . ; Checking condition on each index . ; Driven Program\\\"\\nSolution in php:\",\"targets\":\"< ? php function isPossible ( $ a , $ b , $ n , $ k ) { sort ( $ a ) ; rsort ( $ b ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( $ a [ $ i ] + $ b [ $ i ] < $ k ) return false ; return true ; } $ a = array ( 2 , 1 , 3 ) ; $ b = array ( 7 , 8 , 9 ) ; $ k = 10 ; $ n = count ( $ a ) ; if ( isPossible ( $ a , $ b , $ n , $ k ) ) echo \\\" Yes \\\" ; else echo \\\" No \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Absolute difference between the count of odd and even factors of N | Function to find the smallest prime factor of all the numbers using Sieve Of Eratosthenes ; Stores whether any number is prime or not ; Initialize smallest factor as 2 for all the even numbers ; Iterate over the range [ 3 , N ] ; If i is prime ; Iterate all multiples of i ; i is the smallest prime factor of i * j ; Function to find the absolute difference between the count of odd and even factors of N ; Stores the smallest prime factor of i ; Fill values in s [ ] using sieve of eratosthenes ; Stores the total number of factors and the total number of odd and even factors ; Store the current prime factor of the number N ; Store the power of current prime factor ; Loop while N is greater than 1 ; If N also has smallest prime factor as curr , then increment cnt by 1 ; Update only total number of factors if curr is 2 ; Update total number of factors and total number of odd factors ; Update current prime factor as s [ N ] and count as 1 ; Calculate the number of even factors ; Print the difference ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def sieveOfEratosthenes ( N , s ) :\\n\\tprime = [ False ] * ( N + 1 )\\n\\tfor i in range ( 2 , N + 1 , 2 ) :\\n\\t\\ts [ i ] = 2\\n\\tfor i in range ( 3 , N , 2 ) :\\n\\t\\tif ( prime [ i ] == False ) :\\n\\t\\t\\ts [ i ] = i\\n\\t\\t\\tfor j in range ( i , N , 2 ) :\\n\\t\\t\\t\\tif j * i > N :\\n\\t\\t\\t\\t\\tbreak\\n\\t\\t\\t\\tif ( not prime [ i * j ] ) :\\n\\t\\t\\t\\t\\tprime [ i * j ] = True\\n\\t\\t\\t\\t\\ts [ i * j ] = i\\ndef findDifference ( N ) :\\n\\ts = [ 0 ] * ( N + 1 )\\n\\tsieveOfEratosthenes ( N , s )\\n\\ttotal , odd , even = 1 , 1 , 0\\n\\tcurr = s [ N ]\\n\\tcnt = 1\\n\\twhile ( N > 1 ) :\\n\\t\\tN \\/\\/= s [ N ]\\n\\t\\tif ( curr == s [ N ] ) :\\n\\t\\t\\tcnt += 1\\n\\t\\t\\tcontinue\\n\\t\\tif ( curr == 2 ) :\\n\\t\\t\\ttotal = total * ( cnt + 1 )\\n\\t\\telse :\\n\\t\\t\\ttotal = total * ( cnt + 1 )\\n\\t\\t\\todd = odd * ( cnt + 1 )\\n\\t\\tcurr = s [ N ]\\n\\t\\tcnt = 1\\n\\teven = total - odd\\n\\tprint ( abs ( even - odd ) )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 12\\n\\tfindDifference ( N )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find maximum average subarray of k length | Returns beginning index of maximum average subarray of length ' k ' ; Check if ' k ' is valid ; Compute sum of first ' k ' elements ; Compute sum of remaining subarrays ; Return starting index ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findMaxAverage ( $ arr , $ n , $ k ) { if ( $ k > $ n ) return -1 ; $ sum = $ arr [ 0 ] ; for ( $ i = 1 ; $ i < $ k ; $ i ++ ) $ sum += $ arr [ $ i ] ; $ max_sum = $ sum ; $ max_end = $ k - 1 ; for ( $ i = $ k ; $ i < $ n ; $ i ++ ) { $ sum = $ sum + $ arr [ $ i ] - $ arr [ $ i - $ k ] ; if ( $ sum > $ max_sum ) { $ max_sum = $ sum ; $ max_end = $ i ; } } return $ max_end - $ k + 1 ; } $ arr = array ( 1 , 12 , -5 , -6 , 50 , 3 ) ; $ k = 4 ; $ n = count ( $ arr ) ; echo \\\" The \u2581 maximum \u2581 average \u2581 subarray \u2581 of \u2581 \\\" , \\\" length \u2581 \\\" , $ k , \\\" \u2581 begins \u2581 at \u2581 index \u2581 \\\" , findMaxAverage ( $ arr , $ n , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if it is possible to reach ( X , Y ) from ( 1 , 1 ) by given steps | C # program for the above approach ; Function to find the gcd of two numbers ; Base case ; Recurse ; Function to print the answer ; GCD of X and Y ; If GCD is power of 2 ; Driver code ; Given X and Y ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { public static int gcd ( int a , int b ) { if ( a < b ) { int t = a ; a = b ; b = t ; } if ( a % b == 0 ) return b ; return gcd ( b , a % b ) ; } static void printAnswer ( int x , int y ) { int val = gcd ( x , y ) ; if ( ( val & ( val - 1 ) ) == 0 ) Console . WriteLine ( \\\" Yes \\\" ) ; else Console . WriteLine ( \\\" No \\\" ) ; } public static void Main ( ) { int x = 4 ; int y = 7 ; printAnswer ( x , y ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Majority Element | C # Program for finding out majority element in an array ; Driver Code ; Function calling\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { private static void findMajority ( int [ ] arr ) { Dictionary < int , int > map = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < arr . Length ; i ++ ) { if ( map . ContainsKey ( arr [ i ] ) ) { int count = map [ arr [ i ] ] + 1 ; if ( count > arr . Length \\/ 2 ) { Console . WriteLine ( \\\" Majority \u2581 found \u2581 : - \u2581 \\\" + arr [ i ] ) ; return ; } else { map [ arr [ i ] ] = count ; } } else { map [ arr [ i ] ] = 1 ; } } Console . WriteLine ( \\\" \u2581 No \u2581 Majority \u2581 element \\\" ) ; } public static void Main ( string [ ] args ) { int [ ] a = new int [ ] { 2 , 2 , 2 , 2 , 5 , 5 , 2 , 3 , 3 } ; findMajority ( a ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimum jumps required to make a group of persons sit together | Python3 program for the above approach ; Function to find the minimum jumps required to make the whole group sit adjacently ; Store the indexes ; Stores the count of occupants ; Length of the string ; Traverse the seats ; If current place is occupied ; Push the current position in the vector ; Base Case : ; The index of the median element ; The value of the median element ; Traverse the position [ ] ; Update the ans ; Return the final count ; Driver Code ; Given arrange of seats ; Function Call\\\"\\nSolution in Python:\",\"targets\":\"MOD = 10 ** 9 + 7\\ndef minJumps ( seats ) :\\n\\tposition = [ ]\\n\\tcount = 0\\n\\tlenn = len ( seats )\\n\\tfor i in range ( lenn ) :\\n\\t\\tif ( seats [ i ] == ' x ' ) :\\n\\t\\t\\tposition . append ( i - count )\\n\\t\\t\\tcount += 1\\n\\tif ( count == lenn or count == 0 ) :\\n\\t\\treturn 0\\n\\tmed_index = ( count - 1 ) \\/\\/ 2\\n\\tmed_val = position [ med_index ]\\n\\tans = 0\\n\\tfor i in range ( len ( position ) ) :\\n\\t\\tans = ( ans % MOD + abs ( position [ i ] - med_val ) % MOD ) % MOD\\n\\treturn ans % MOD\\nif __name__ == ' _ _ main _ _ ' :\\n\\tS = \\\" . . . . x . . xx . . . x . . \\\"\\n\\tprint ( minJumps ( S ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Search , insert and delete in an unsorted array | Inserts a key in arr [ ] of given capacity . n is current size of arr [ ] . This function returns n + 1 if insertion is successful , else n . ; Cannot insert more elements if n is already more than or equal to capcity ; Driver Code ; Inserting key\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function insertSorted ( & $ arr , $ n , $ key , $ capacity ) { if ( $ n >= $ capacity ) return $ n ; array_push ( $ arr , $ key ) ; return ( $ n + 1 ) ; } $ arr = array ( 12 , 16 , 20 , 40 , 50 , 70 ) ; $ capacity = 20 ; $ n = 6 ; $ key = 26 ; echo \\\" Before \u2581 Insertion : \u2581 \\\" ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo $ arr [ $ i ] . \\\" \u2581 \\\" ; $ n = insertSorted ( $ arr , $ n , $ key , $ capacity ) ; echo \\\" After Insertion : \\\" for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo $ arr [ $ i ] . \\\" \u2581 \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Find subarray with given sum | Set 1 ( Nonnegative Numbers ) | An efficient program to print subarray with sum as given sum ; Returns true if the there is a subarray of arr [ ] with a sum equal to ' sum ' otherwise returns false . Also , prints the result ; Initialize curr_sum as value of first element and starting point as 0 ; Add elements one by one to curr_sum and if the curr_sum exceeds the sum , then remove starting element ; If curr_sum exceeds the sum , then remove the starting elements ; If curr_sum becomes equal to sum , then return true ; Add this element to curr_sum ; If we reach here , then no subarray ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint subArraySum ( int arr [ ] , int n , int sum ) { int curr_sum = arr [ 0 ] , start = 0 , i ; for ( i = 1 ; i <= n ; i ++ ) { while ( curr_sum > sum && start < i - 1 ) { curr_sum = curr_sum - arr [ start ] ; start ++ ; } if ( curr_sum == sum ) { printf ( \\\" Sum \u2581 found \u2581 between \u2581 indexes \u2581 % d \u2581 and \u2581 % d \\\" , start , i - 1 ) ; return 1 ; } if ( i < n ) curr_sum = curr_sum + arr [ i ] ; } printf ( \\\" No \u2581 subarray \u2581 found \\\" ) ; return 0 ; } int main ( ) { int arr [ ] = { 15 , 2 , 4 , 8 , 9 , 5 , 10 , 23 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int sum = 23 ; subArraySum ( arr , n , sum ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Pair formation such that maximum pair sum is minimized | Python 3 Program to divide the array into N pairs such that maximum pair is minimized ; After Sorting Maintain two variables i and j pointing to start and end of array Such that smallest element of array pairs with largest element ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def findOptimalPairs ( arr , N ) :\\n\\tarr . sort ( reverse = False )\\n\\ti = 0\\n\\tj = N - 1\\n\\twhile ( i <= j ) :\\n\\t\\tprint ( \\\" ( \\\" , arr [ i ] , \\\" , \\\" , arr [ j ] , \\\" ) \\\" , end = \\\" \u2581 \\\" )\\n\\t\\ti += 1\\n\\t\\tj -= 1\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 9 , 6 , 5 , 1 ]\\n\\tN = len ( arr )\\n\\tfindOptimalPairs ( arr , N )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Iterative selection sort for linked list | Structure of a node of linked list ; Utility function to create a new Linked List Node ; Function to sort a linked list using selection sort algorithm by swapping the next pointers ; While b is not the last node ; While d is pointing to a valid node ; If d appears immediately after b ; Case 1 : b is the head of the linked list ; Move d before b ; Swap b and d pointers ; Update the head ; Skip to the next element as it is already in order ; Case 2 : b is not the head of the linked list ; Move d before b ; Swap b and d pointers ; Skip to the next element as it is already in order ; If b and d have some non - zero number of nodes in between them ; Case 3 : b is the head of the linked list ; Swap b . next and d . next ; Swap b and d pointers ; Skip to the next element as it is already in order ; Update the head ; Case 4 : b is not the head of the linked list ; Swap b . next and d . next ; Swap b and d pointers ; Skip to the next element as it is already in order ; Update c and skip to the next element as it is already in order ; Function to print the list ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function newNode ( val ) { var temp = new Node ( ) ; temp . data = val ; temp . next = null ; return temp ; } function selectionSort ( head ) { var a , b , c , d , r ; a = b = head ; while ( b . next != null ) { c = d = b . next ; while ( d != null ) { if ( b . data > d . data ) { if ( b . next == d ) { if ( b == head ) { b . next = d . next ; d . next = b ; r = b ; b = d ; d = r ; c = d ; head = b ; d = d . next ; } else { b . next = d . next ; d . next = b ; a . next = d ; r = b ; b = d ; d = r ; c = d ; d = d . next ; } } else { if ( b == head ) { r = b . next ; b . next = d . next ; d . next = r ; c . next = b ; r = b ; b = d ; d = r ; c = d ; d = d . next ; head = b ; } else { r = b . next ; b . next = d . next ; d . next = r ; c . next = b ; a . next = d ; r = b ; b = d ; d = r ; c = d ; d = d . next ; } } } else { c = d ; d = d . next ; } } a = b ; b = b . next ; } return head ; } function printList ( head ) { while ( head != null ) { document . write ( head . data + \\\" \\\" ) ; head = head . next ; } } var head = newNode ( 5 ) ; head . next = newNode ( 4 ) ; head . next . next = newNode ( 3 ) ; head = selectionSort ( head ) ; printList ( head ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimize K to let Person A consume at least ceil ( N \\/ ( M + 1 ) ) candies based on given rules | C ++ program for the above approach ; Function to find minimum value of K such that the first person gets at least ( N \\/ ( M + 1 ) ) candies ; Find the minimum required value of candies for the first person ; Iterate K from [ 1 , n ] ; Total number of candies ; Candies taken by Person 1 ; Candies taken by 1 st person is minimum of K and candies left ; Traverse the array arr [ ] ; Amount consumed by the person j ; Update the number of candies ; Good share of candies achieved ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void minimumK ( vector < int > & arr , int M , int N ) { int good = ceil ( ( N * 1.0 ) \\/ ( ( M + 1 ) * 1.0 ) ) ; for ( int i = 1 ; i <= N ; i ++ ) { int K = i ; int candies = N ; int taken = 0 ; while ( candies > 0 ) { taken += min ( K , candies ) ; candies -= min ( K , candies ) ; for ( int j = 0 ; j < M ; j ++ ) { int consume = ( arr [ j ] * candies ) \\/ 100 ; candies -= consume ; } } if ( taken >= good ) { cout << i ; return ; } } } int main ( ) { int N = 13 , M = 1 ; vector < int > arr = { 50 } ; minimumK ( arr , M , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Print reverse of a string using recursion | C program to reverse a string using recursion ; Function to print reverse of the passed string ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"# include \\nvoid reverse ( char * str ) { if ( * str ) { reverse ( str + 1 ) ; printf ( \\\" % c \\\" , * str ) ; } } int main ( ) { char a [ ] = \\\" Geeks \u2581 for \u2581 Geeks \\\" ; reverse ( a ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find a pair from the given array with maximum nCr value | C ++ implementation of the approach ; Function to print the pair that gives maximum nCr ; This gives the value of N in nCr ; Case 1 : When N is odd ; Case 2 : When N is even ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void printMaxValPair ( vector < long long > & v , int n ) { sort ( v . begin ( ) , v . end ( ) ) ; long long N = v [ n - 1 ] ; if ( N % 2 == 1 ) { long long first_maxima = N \\/ 2 ; long long second_maxima = first_maxima + 1 ; long long ans1 = 3e18 , ans2 = 3e18 ; long long from_left = -1 , from_right = -1 ; long long from = -1 ; for ( long long i = 0 ; i < n ; ++ i ) { if ( v [ i ] > first_maxima ) { from = i ; break ; } else { long long diff = first_maxima - v [ i ] ; if ( diff < ans1 ) { ans1 = diff ; from_left = v [ i ] ; } } } from_right = v [ from ] ; long long diff1 = first_maxima - from_left ; long long diff2 = from_right - second_maxima ; if ( diff1 < diff2 ) cout << N << \\\" \u2581 \\\" << from_left ; else cout << N << \\\" \u2581 \\\" << from_right ; } else { long long maxima = N \\/ 2 ; long long ans1 = 3e18 ; long long R = -1 ; for ( long long i = 0 ; i < n - 1 ; ++ i ) { long long diff = abs ( v [ i ] - maxima ) ; if ( diff < ans1 ) { ans1 = diff ; R = v [ i ] ; } } cout << N << \\\" \u2581 \\\" << R ; } } int main ( ) { vector < long long > v = { 1 , 1 , 2 , 3 , 6 , 1 } ; int n = v . size ( ) ; printMaxValPair ( v , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Rearrange a given linked list in | Java implementation ; Creating the structure for node ; ; Function to print the list ; Function to rearrange ; we set left = null , when we reach stop condition , so no processing required after that ; Stop condition : odd case : left = right , even case : left . next = right ; stop condition , set null to left nodes ; even case ; odd case ; Drivers Code ; Print original list ; Modify the list ; Print modified list\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class Node { int data ; Node next ; Node ( int key ) { data = key ; next = null ; } } class GFG { Node left = null ; void printlist ( Node head ) { while ( head != null ) { System . out . print ( head . data + \\\" \u2581 \\\" ) ; if ( head . next != null ) { System . out . print ( \\\" - > \\\" ) ; } head = head . next ; } System . out . println ( ) ; } void rearrange ( Node head ) { if ( head != null ) { left = head ; reorderListUtil ( left ) ; } } void reorderListUtil ( Node right ) { if ( right == null ) { return ; } reorderListUtil ( right . next ) ; if ( left == null ) { return ; } if ( left != right && left . next != right ) { Node temp = left . next ; left . next = right ; right . next = temp ; left = temp ; } else { if ( left . next == right ) { left . next . next = null ; left = null ; } else { left . next = null ; left = null ; } } } public static void main ( String [ ] args ) { Node head = new Node ( 1 ) ; head . next = new Node ( 2 ) ; head . next . next = new Node ( 3 ) ; head . next . next . next = new Node ( 4 ) ; head . next . next . next . next = new Node ( 5 ) ; GFG gfg = new GFG ( ) ; gfg . printlist ( head ) ; gfg . rearrange ( head ) ; gfg . printlist ( head ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum time required to color all edges of a Tree | Stores the required answer ; Stores the graph ; Function to add edges ; Function to calculate the minimum time required to color all the edges of a tree ; Starting from time = 0 , for all the child edges ; If the edge is not visited yet . ; Time of coloring of the current edge ; If the parent edge has been colored at the same time ; Update the maximum time ; Recursively call the function to its child node ; Driver Code ; Function call ; Finally , print the answer\\\"\\nHow can the above be solved in Python?\",\"targets\":\"ans = 0\\nedges = [ [ ] for i in range ( 100000 ) ]\\ndef Add_edge ( u , v ) :\\n\\tglobal edges\\n\\tedges [ u ] . append ( v )\\n\\tedges [ v ] . append ( u )\\ndef minTimeToColor ( node , parent , arrival_time ) :\\n\\tglobal ans\\n\\tcurrent_time = 0\\n\\tfor x in edges [ node ] :\\n\\t\\tif ( x != parent ) :\\n\\t\\t\\tcurrent_time += 1\\n\\t\\t\\tif ( current_time == arrival_time ) :\\n\\t\\t\\t\\tcurrent_time += 1\\n\\t\\t\\tans = max ( ans , current_time )\\n\\t\\t\\tminTimeToColor ( x , node , current_time )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tA = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 3 , 4 ] ]\\n\\tfor i in A :\\n\\t\\tAdd_edge ( i [ 0 ] , i [ 1 ] )\\n\\tminTimeToColor ( 1 , - 1 , 0 )\\n\\tprint ( ans )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Biggest integer which has maximum digit sum in range from 1 to n | CPP program to find the number with maximum digit sum . ; function to calculate the sum of digits of a number . ; Returns the maximum number with maximum sum of digits . ; initializing b as 1 and initial max sum to be of n ; iterates from right to left in a digit ; while iterating this is the number from from right to left ; calls the function to check if sum of cur is more then of ans ; reduces the number to one unit less ; driver program\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int sumOfDigits ( int a ) { int sum = 0 ; while ( a ) { sum += a % 10 ; a \\/= 10 ; } return sum ; } int findMax ( int x ) { int b = 1 , ans = x ; while ( x ) { int cur = ( x - 1 ) * b + ( b - 1 ) ; if ( sumOfDigits ( cur ) > sumOfDigits ( ans ) || ( sumOfDigits ( cur ) == sumOfDigits ( ans ) && cur > ans ) ) ans = cur ; x \\/= 10 ; b *= 10 ; } return ans ; } int main ( ) { int n = 521 ; cout << findMax ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum possible middle element of the array after deleting exactly k elements | C # implementation of the approach ; Function to calculate maximum possible middle value of the array after deleting exactly k elements ; Initialize answer as - 1 ; Calculate range of elements that can give maximum possible middle value of the array since index of maximum possible middle value after deleting exactly k elements from array will lie in between low and high ; Find maximum element of the array in range low and high ; since indexing is 1 based so check element at index i - 1 ; Return the maximum possible middle value of the array after deleting exactly k elements from the array ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int maximum_middle_value ( int n , int k , int [ ] arr ) { int ans = - 1 ; int low = ( n + 1 - k ) \\/ 2 ; int high = ( n + 1 - k ) \\/ 2 + k ; for ( int i = low ; i <= high ; i ++ ) { ans = Math . Max ( ans , arr [ i - 1 ] ) ; } return ans ; } static public void Main ( ) { int n = 5 , k = 2 ; int [ ] arr = { 9 , 5 , 3 , 7 , 10 } ; Console . WriteLine ( maximum_middle_value ( n , k , arr ) ) ; n = 9 ; k = 3 ; int [ ] arr1 = { 2 , 4 , 3 , 9 , 5 , 8 , 7 , 6 , 10 } ; Console . WriteLine ( maximum_middle_value ( n , k , arr1 ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check if an array is sorted and rotated using Binary Search | Function to return the index of the pivot ; Base cases ; Check if element at ( mid - 1 ) is pivot Consider the cases like { 4 , 5 , 1 , 2 , 3 } ; Decide whether we need to go to the left half or the right half ; Function to check if a given array is sorted rotated or not ; To check if the elements to the left of the pivot are in descending or not ; To check if the elements to the right of the pivot are in ascending or not ; If any of the above if or else is true Then the array is sorted rotated ; Else the array is not sorted rotated ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findPivot ( arr , low , high ) :\\n\\tif ( high < low ) :\\n\\t\\treturn - 1 ;\\n\\tif ( high == low ) :\\n\\t\\treturn low ;\\n\\tmid = ( low + high ) \\/\\/ 2 ;\\n\\tif ( mid < high and arr [ mid + 1 ] < arr [ mid ] ) :\\n\\t\\treturn mid ;\\n\\tif ( mid > low and arr [ mid ] < arr [ mid - 1 ] ) :\\n\\t\\treturn mid - 1 ;\\n\\tif ( arr [ low ] > arr [ mid ] ) :\\n\\t\\treturn findPivot ( arr , low , mid - 1 ) ;\\n\\telse :\\n\\t\\treturn findPivot ( arr , mid + 1 , high ) ;\\ndef isRotated ( arr , n ) :\\n\\tl = 0 ;\\n\\tr = n - 1 ;\\n\\tpivot = - 1 ;\\n\\tif ( arr [ l ] > arr [ r ] ) :\\n\\t\\tpivot = findPivot ( arr , l , r ) ;\\n\\t\\ttemp = pivot\\n\\t\\tif ( l < pivot ) :\\n\\t\\t\\twhile ( pivot > l ) :\\n\\t\\t\\t\\tif ( arr [ pivot ] < arr [ pivot - 1 ] ) :\\n\\t\\t\\t\\t\\treturn False ;\\n\\t\\t\\t\\tpivot -= 1 ;\\n\\t\\telse :\\n\\t\\t\\tpivot = temp\\n\\t\\t\\tpivot += 1 ;\\n\\t\\t\\twhile ( pivot < r ) :\\n\\t\\t\\t\\tif ( arr [ pivot ] > arr [ pivot + 1 ] ) :\\n\\t\\t\\t\\t\\treturn False ;\\n\\t\\t\\t\\tpivot + + 1 ;\\n\\t\\treturn True ;\\n\\telse :\\n\\t\\treturn False ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ 3 , 4 , 5 , 1 , 2 ] ;\\n\\tif ( isRotated ( arr , 5 ) ) :\\n\\t\\tprint ( \\\" True \\\" ) ;\\n\\telse :\\n\\t\\tprint ( \\\" False \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check whether a given point lies on or inside the rectangle | Set 3 | Java program to Check whether a given point lies inside or on the rectangle or not ; function to Check whether a given point lies inside or on the rectangle or not ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static boolean LiesInsieRectangle ( int a , int b , int x , int y ) { if ( x - y - b <= 0 && x - y + b >= 0 && x + y - 2 * a + b <= 0 && x + y - b >= 0 ) return true ; return false ; } public static void main ( String [ ] args ) { int a = 7 , b = 2 , x = 4 , y = 5 ; if ( LiesInsieRectangle ( a , b , x , y ) ) System . out . println ( \\\" Given \u2581 point \u2581 lies \u2581 \\\" + \\\" inside \u2581 the \u2581 rectangle \\\" ) ; else System . out . println ( \\\" Given \u2581 point \u2581 does \u2581 not \u2581 \\\" + \\\" lie \u2581 on \u2581 the \u2581 rectangle \\\" ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Queries to find longest subsequence having no similar adjacent elements with updates | Java program for the above approach ; Traverse the array arr [ ] ; If previous element is not same as current element ; Traverse the queries ; Replace element at index x with y ; Recalculate for index x ; Subtract contribution of element at index x ; Add contribution of y ; Recalculate for index x + 1 ; Subtract contribution of element at index x + 1 ; Adds contribution of y ; Replace the element ; Driver Code ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static void longestSubsequence ( int N , int Q , int arr [ ] , int Queries [ ] [ ] ) { int count = 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] != arr [ i - 1 ] ) { count += 1 ; } } for ( int i = 0 ; i < Q ; i ++ ) { int x = Queries [ i ] [ 0 ] ; int y = Queries [ i ] [ 1 ] ; if ( x > 1 ) { if ( arr [ x - 1 ] != arr [ x - 2 ] ) { count -= 1 ; } if ( arr [ x - 2 ] != y ) { count += 1 ; } } if ( x < N ) { if ( arr [ x ] != arr [ x - 1 ] ) { count -= 1 ; } if ( y != arr [ x ] ) { count += 1 ; } } System . out . print ( count + \\\" \u2581 \\\" ) ; arr [ x - 1 ] = y ; } } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 1 , 2 , 5 , 2 } ; int N = arr . length ; int Q = 2 ; int Queries [ ] [ ] = { { 1 , 3 } , { 4 , 2 } } ; longestSubsequence ( N , Q , arr , Queries ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Number of GP ( Geometric Progression ) subsequences of size 3 | C # program to count GP subsequences of size 3. ; To calculate nCr DP approach ; nC0 is 1 ; Compute next row of pascal triangle using the previous row ; Returns count of G . P . subsequences with length 3 and common ratio r ; Hashing to maintain left and right array elements to the main count ; Stores the answer ; Traverse through the elements ; IF RATIO IS ONE ; Traverse the count in hash ; Calculating nC3 , where ' n ' is the number of times each number is repeated in the input ; Traverse through all elements and find out the number of elements as k1 * k2 ; Keep the count of left and right elements left is a [ i ] \\/ r and right a [ i ] * r ; If the current element is divisible by k , count elements in left hash . ; Decrease the count in right hash ; Number of right elements ; left count of a [ i ] ; Returns answer ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int binomialCoeff ( int n , int k ) { int [ ] C = new int [ k + 1 ] ; C [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = Math . Min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } static long subsequences ( int [ ] a , int n , int r ) { Dictionary < int , int > left = new Dictionary < int , int > ( ) ; Dictionary < int , int > right = new Dictionary < int , int > ( ) ; long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( right . ContainsKey ( a [ i ] ) ) { right [ a [ i ] ] ++ ; } else { right . Add ( a [ i ] , 1 ) ; } if ( r == 1 ) { foreach ( KeyValuePair < int , int > i in right ) { ans += binomialCoeff ( i . Value , 3 ) ; } return ans ; } for ( int i = 0 ; i < n ; i ++ ) { long c1 = 0 , c2 = 0 ; if ( a [ i ] % r == 0 ) if ( left . ContainsKey ( a [ i ] \\/ r ) ) c1 = left [ a [ i ] \\/ r ] ; if ( right . ContainsKey ( a [ i ] ) ) { right [ a [ i ] ] -- ; } else { right . Add ( a [ i ] , - 1 ) ; } if ( right . ContainsKey ( a [ i ] * r ) ) c2 = right [ a [ i ] * r ] ; ans += c1 * c2 ; if ( left . ContainsKey ( a [ i ] ) ) { left [ a [ i ] ] ++ ; } else { left . Add ( a [ i ] , 1 ) ; } } return ans ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 2 , 6 , 2 , 3 , 6 , 9 , 18 , 3 , 9 } ; int n = a . GetLength ( 0 ) ; int r = 3 ; Console . Write ( subsequences ( a , n , r ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check for an array element that is co | C # implementation of the approach ; Stores smallest prime factor for every number ; Hash to store prime factors count ; Function to calculate SPF ( Smallest Prime Factor ) for every number till MAXN ; Marking smallest prime factor for every number to be itself ; Separately marking spf for every even number as 2 ; Checking if i is prime ; Marking SPF for all numbers divisible by i ; Marking spf [ j ] if it is not previously marked ; Function to store the prime factors after dividing by the smallest prime factor at every step ; Storing the count of prime factors in hash ; Function that returns true if there are no common prime factors between x and other numbers of the array ; Checking whether it common prime factor with other numbers ; Function that returns true if there is an element in the array which is coprime with all the other elements of the array ; Using sieve for generating prime factors ; Checking the common prime factors with other numbers ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int MAXN = 1000001 ; static int [ ] spf = new int [ MAXN ] ; static int [ ] hash1 = new int [ MAXN ] ; static void sieve ( ) { spf [ 1 ] = 1 ; for ( int i = 2 ; i < MAXN ; i ++ ) spf [ i ] = i ; for ( int i = 4 ; i < MAXN ; i += 2 ) spf [ i ] = 2 ; for ( int i = 3 ; i * i < MAXN ; i ++ ) { if ( spf [ i ] == i ) { for ( int j = i * i ; j < MAXN ; j += i ) if ( spf [ j ] == j ) spf [ j ] = i ; } } } static void getFactorization ( int x ) { int temp ; while ( x != 1 ) { temp = spf [ x ] ; if ( x % temp == 0 ) { hash1 [ spf [ x ] ] ++ ; x = x \\/ spf [ x ] ; } while ( x % temp == 0 ) x = x \\/ temp ; } } static bool check ( int x ) { int temp ; while ( x != 1 ) { temp = spf [ x ] ; if ( x % temp == 0 && hash1 [ temp ] > 1 ) return false ; while ( x % temp == 0 ) x = x \\/ temp ; } return true ; } static bool hasValidNum ( int [ ] arr , int n ) { sieve ( ) ; for ( int i = 0 ; i < n ; i ++ ) getFactorization ( arr [ i ] ) ; for ( int i = 0 ; i < n ; i ++ ) if ( check ( arr [ i ] ) ) return true ; return false ; } static void Main ( ) { int [ ] arr = { 2 , 8 , 4 , 10 , 6 , 7 } ; int n = arr . Length ; if ( hasValidNum ( arr , n ) ) Console . WriteLine ( \\\" Yes \\\" ) ; else Console . WriteLine ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Largest area square in an array when elements can be shuffled | Java implementation of the approach ; Function that returns true if it is possible to make a square with side equal to l ; To store the count of elements greater than or equal to l ; Increment the count ; If the count becomes greater than or equal to l ; Function to return the maximum area of the square that can be obtained ; If square is possible with side length m ; Try to find a square with smaller side length ; Return the area ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static boolean isSquarePossible ( int arr [ ] , int n , int l ) { int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= l ) cnt ++ ; if ( cnt >= l ) return true ; } return false ; } static int maxArea ( int arr [ ] , int n ) { int l = 0 , r = n ; int len = 0 ; while ( l <= r ) { int m = l + ( ( r - l ) \\/ 2 ) ; if ( isSquarePossible ( arr , n , m ) ) { len = m ; l = m + 1 ; } else r = m - 1 ; } return ( len * len ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 4 , 5 , 5 } ; int n = arr . length ; System . out . println ( maxArea ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Subtract 1 without arithmetic operators | C code to subtract one from a given number ; Flip all the set bits until we find a 1 ; flip the rightmost 1 bit ; Driver program to test above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint subtractOne ( int x ) { int m = 1 ; while ( ! ( x & m ) ) { x = x ^ m ; m <<= 1 ; } x = x ^ m ; return x ; } int main ( ) { printf ( \\\" % d \\\" , subtractOne ( 13 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Program to find the Perimeter of a Regular Polygon | C program to find the perimeter of a regular polygon ; Function to calculate the perimeter ; Calculate Perimeter ; driver code ; Get the number of sides ; Get the length of side ; find perimeter\\nHow can the above be solved in C?\",\"targets\":\"#include \\nfloat Perimeter ( float s , int n ) { float perimeter = 1 ; perimeter = n * s ; return perimeter ; } int main ( ) { int n = 5 ; float s = 2.5 , peri ; peri = Perimeter ( s , n ) ; printf ( \\\" Perimeter \u2581 of \u2581 Regular \u2581 Polygon \\n \\\" \\\" \u2581 with \u2581 % d \u2581 sides \u2581 of \u2581 length \u2581 % f \u2581 = \u2581 % f \\n \\\" , n , s , peri ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximum determinant of a matrix with every values either 0 or n | C # program to find maximum possible determinant of 0 \\/ n matrix . ; Function for maximum determinant ; Function to print resulatant matrix ; three position where 0 appears ; position where n appears ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GFG { static int maxDet ( int n ) { return ( 2 * n * n * n ) ; } void resMatrix ( int n ) { for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { if ( i == 0 && j == 2 ) Console . Write ( \\\"0 \u2581 \\\" ) ; else if ( i == 1 && j == 0 ) Console . Write ( \\\"0 \u2581 \\\" ) ; else if ( i == 2 && j == 1 ) Console . Write ( \\\"0 \u2581 \\\" ) ; else Console . Write ( n + \\\" \u2581 \\\" ) ; } Console . WriteLine ( \\\" \\\" ) ; } } static public void Main ( String [ ] args ) { int n = 15 ; GFG geeks = new GFG ( ) ; Console . WriteLine ( \\\" Maximum \u2581 Determinant \u2581 = \u2581 \\\" + maxDet ( n ) ) ; Console . WriteLine ( \\\" Resultant \u2581 Matrix \u2581 : \\\" ) ; geeks . resMatrix ( n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Dynamic Programming | High | A DP based PHP program to find maximum tasks . Returns the maximum among the 2 numbers ; Returns the maximum among the 2 numbers ; Returns maximum amount of task that can be done till day n ; An array task_dp that stores the maximum task done ; If n = 0 , no solution exists ; If n = 1 , high effort task on that day will be the solution ; Fill the entire array determining which task to choose on day i ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function max1 ( $ x , $ y ) { return ( $ x > $ y ? $ x : $ y ) ; } return ( $ x > $ y ? $ x : $ y ) ; } function maxTasks ( $ high , $ low , $ n ) { $ task_dp = array ( $ n + 1 ) ; $ task_dp [ 0 ] = 0 ; $ task_dp [ 1 ] = $ high [ 0 ] ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) $ task_dp [ $ i ] = max ( $ high [ $ i - 1 ] + $ task_dp [ $ i - 2 ] , $ low [ $ i - 1 ] + $ task_dp [ $ i - 1 ] ) ; return $ task_dp [ $ n ] ; } { $ n = 5 ; $ high = array ( 3 , 6 , 8 , 7 , 6 ) ; $ low = array ( 1 , 5 , 4 , 5 , 3 ) ; echo ( maxTasks ( $ high , $ low , $ n ) ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Count ways to reach the nth stair using step 1 , 2 or 3 | Program to find n - th stair using step size 1 or 2 or 3. ; Returns count of ways to reach n - th stair using 1 or 2 or 3 steps . ; Driver code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint findStep ( int n ) { if ( n == 1 n == 0 ) return 1 ; else if ( n == 2 ) return 2 ; else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ; } int main ( ) { int n = 4 ; printf ( \\\" % d \\n \\\" , findStep ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"To check divisibility of any large number by 999 | Java for divisibility of number by 999 ; Method to check divisibility ; Append required 0 s at the beginning . ; add digits in group of three in gSum ; group saves 3 - digit group ; calculate result till 3 digit sum ; Driver method\\\"\\nSolution in Java:\",\"targets\":\"class Test { static boolean isDivisible999 ( String num ) { int n = num . length ( ) ; if ( n == 0 && num . charAt ( 0 ) == '0' ) return true ; if ( n % 3 == 1 ) num = \\\"00\\\" + num ; if ( n % 3 == 2 ) num = \\\"0\\\" + num ; int gSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int group = 0 ; group += ( num . charAt ( i ++ ) - '0' ) * 100 ; group += ( num . charAt ( i ++ ) - '0' ) * 10 ; group += num . charAt ( i ) - '0' ; gSum += group ; } if ( gSum > 1000 ) { num = Integer . toString ( gSum ) ; n = num . length ( ) ; gSum = isDivisible999 ( num ) ? 1 : 0 ; } return ( gSum == 999 ) ; } public static void main ( String args [ ] ) { String num = \\\"1998\\\" ; System . out . println ( isDivisible999 ( num ) ? \\\" Divisible \\\" : \\\" Not \u2581 divisible \\\" ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sum of products of all combination taken ( 1 to n ) at a time | Java Program to find sum of all combination takne ( 1 to N ) at a time using dynamic programming ; find the postfix sum array ; modify the array such that we don 't have to compute the products which are obtained before ; finding sum of all combination taken 1 to N at a time ; sum taken 1 at time is simply sum of 1 - N ; for sum of products for all combination ; finding postfix array ; sum of products taken i + 1 at a time ; modify the array for overlapping problem ; Driver 's Code ; storing numbers from 1 to N ; calling allCombination\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static void postfix ( int a [ ] , int n ) { for ( int i = n - 1 ; i > 0 ; i -- ) { a [ i - 1 ] = a [ i - 1 ] + a [ i ] ; } } static void modify ( int a [ ] , int n ) { for ( int i = 1 ; i < n ; i ++ ) { a [ i - 1 ] = i * a [ i ] ; } } static void allCombination ( int a [ ] , int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { sum += i ; } System . out . println ( \\\" f ( 1 ) \u2581 - - > \u2581 \\\" + sum ) ; for ( int i = 1 ; i < n ; i ++ ) { postfix ( a , n - i + 1 ) ; sum = 0 ; for ( int j = 1 ; j <= n - i ; j ++ ) { sum += ( j * a [ j ] ) ; } System . out . println ( \\\" f ( \\\" + ( i + 1 ) + \\\" ) \u2581 - - > \u2581 \\\" + sum ) ; modify ( a , n ) ; } } public static void main ( String [ ] args ) { int n = 5 ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = i + 1 ; } allCombination ( a , n ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find all elements in array which have at | Sorting based C ++ program to find all elements in array which have atleast two greater elements itself . ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void findElements ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; for ( int i = 0 ; i < n - 2 ; i ++ ) cout << arr [ i ] << \\\" \u2581 \\\" ; } int main ( ) { int arr [ ] = { 2 , -6 , 3 , 5 , 1 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; findElements ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count numbers ( smaller than or equal to N ) with given digit sum | C # program to count 2 s from 0 to n ; N can be max 10 ^ 18 and hence digitsum will be 162 maximum . ; If sum_so_far equals to given sum then return 1 else 0 ; Our constructed number should not become greater than N . ; If tight is true then it will also be true for ( i + 1 ) digit . ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static long [ , , ] dp = new long [ 18 , 2 , 162 ] ; static long solve ( int i , bool tight , int sum_so_far , int Sum , String number , int len ) { if ( i == len ) { if ( sum_so_far == Sum ) return 1 ; else return 0 ; } long ans = dp [ i , 1 , sum_so_far ] ; if ( ans != - 1 ) { return ans ; } ans = 0 ; bool ntight ; int nsum_so_far ; for ( char currdigit = '0' ; currdigit <= '9' ; currdigit ++ ) { if ( ! tight && currdigit > number [ i ] ) { break ; } ntight = tight || currdigit < number [ i ] ; nsum_so_far = sum_so_far + ( currdigit - '0' ) ; ans += solve ( i + 1 , ntight , nsum_so_far , Sum , number , len ) ; } return ans ; } public static void Main ( String [ ] args ) { int sum = 4 ; String number = \\\"100\\\" ; for ( int i = 0 ; i < 18 ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { for ( int k = 0 ; k < 162 ; k ++ ) dp [ i , j , k ] = - 1 ; } } Console . WriteLine ( solve ( 0 , false , 0 , sum , number , number . Length ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count of Fibonacci divisors of a given number | Java program to count number of divisors of N which are Fibonacci numbers ; Function to create hash table to check Fibonacci numbers ; Function to count number of divisors of N which are fibonacci numbers ; If divisors are equal , check and count only one ; Otherwise check and count both ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void createHash ( HashSet < Integer > hash , int maxElement ) { int prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr <= maxElement ) { int temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } static int countFibonacciDivisors ( int n ) { HashSet < Integer > hash = new HashSet < Integer > ( ) ; createHash ( hash , n ) ; int cnt = 0 ; for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( ( n \\/ i == i ) && ( hash . contains ( n \\/ i ) ) ) cnt ++ ; else { if ( hash . contains ( n \\/ i ) ) cnt ++ ; if ( hash . contains ( n \\/ ( n \\/ i ) ) ) cnt ++ ; } } } return cnt ; } public static void main ( String [ ] args ) { int n = 12 ; System . out . print ( countFibonacciDivisors ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximum difference between two elements in an Array | Function to return the maximum absolute difference between any two elements of the array ; To store the minimum and the maximum elements from the array ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function maxAbsDiff ( $ arr , $ n ) { $ minEle = $ arr [ 0 ] ; $ maxEle = $ arr [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { $ minEle = min ( $ minEle , $ arr [ $ i ] ) ; $ maxEle = max ( $ maxEle , $ arr [ $ i ] ) ; } return ( $ maxEle - $ minEle ) ; } $ arr = array ( 2 , 1 , 5 , 3 ) ; $ n = sizeof ( $ arr ) ; echo maxAbsDiff ( $ arr , $ n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Maximum sum such that no two elements are adjacent | ; Function to return max sum such that no two elements are adjacent ; current max excluding i ; current max including i ; return max of incl and excl ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint FindMaxSum ( int arr [ ] , int n ) { int incl = arr [ 0 ] ; int excl = 0 ; int excl_new ; int i ; for ( i = 1 ; i < n ; i ++ ) { excl_new = ( incl > excl ) ? incl : excl ; incl = excl + arr [ i ] ; excl = excl_new ; } return ( ( incl > excl ) ? incl : excl ) ; } int main ( ) { int arr [ ] = { 5 , 5 , 10 , 100 , 10 , 5 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" % d \u2581 n \\\" , FindMaxSum ( arr , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Generate an N | Fun dtion to print the required sequence ; Stores count of even and odd elements ; Stores sum of even and odd elements ; Print N \\/ 2 even elements ; Print N \\/ 2 - 1 odd elements ; Print final odd element ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function Print ( N ) { if ( ( N \\/ 2 ) % 2 == 1 || ( N % 2 == 1 ) ) { document . write ( - 1 ) ; return ; } var CurEven = 2 , CurOdd = 1 ; var SumOdd = 0 , SumEven = 0 ; for ( var i = 0 ; i < ( N \\/ 2 ) ; i ++ ) { document . write ( CurEven + \\\" \\\" ) ; SumEven += CurEven ; CurEven += 2 ; } for ( var i = 0 ; i < N \\/ 2 - 1 ; i ++ ) { document . write ( CurOdd + \\\" \\\" ) ; SumOdd += CurOdd ; CurOdd += 2 ; } CurOdd = SumEven - SumOdd ; document . write ( CurOdd ) ; } var N = 12 ; Print ( N ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Printing Shortest Common Supersequence | A dynamic programming based Java program print shortest supersequence of two strings ; returns shortest supersequence of X and Y ; dp [ i ] [ j ] contains length of shortest supersequence for X [ 0. . i - 1 ] and Y [ 0. . j - 1 ] ; Fill table in bottom up manner ; Below steps follow recurrence relation ; string to store the shortest supersequence ; Start from the bottom right corner and one by one push characters in output string ; If current character in X and Y are same , then current character is part of shortest supersequence ; Put current character in result ; reduce values of i , j and index ; If current character in X and Y are different ; Put current character of Y in result ; reduce values of j and index ; Put current character of X in result ; reduce values of i and index ; If Y reaches its end , put remaining characters of X in the result string ; If X reaches its end , put remaining characters of Y in the result string ; reverse the string and return it ; Swap values of left and right ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static String printShortestSuperSeq ( String X , String Y ) { int m = X . length ( ) ; int n = Y . length ( ) ; int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 ) { dp [ i ] [ j ] = j ; } else if ( j == 0 ) { dp [ i ] [ j ] = i ; } else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) { dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; } else { dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } } String str = \\\" \\\" ; int i = m , j = n ; while ( i > 0 && j > 0 ) { if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) { str += ( X . charAt ( i - 1 ) ) ; i -- ; j -- ; } else if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j - 1 ] ) { str += ( Y . charAt ( j - 1 ) ) ; j -- ; } else { str += ( X . charAt ( i - 1 ) ) ; i -- ; } } while ( i > 0 ) { str += ( X . charAt ( i - 1 ) ) ; i -- ; } while ( j > 0 ) { str += ( Y . charAt ( j - 1 ) ) ; j -- ; } str = reverse ( str ) ; return str ; } static String reverse ( String input ) { char [ ] temparray = input . toCharArray ( ) ; int left , right = 0 ; right = temparray . length - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) { char temp = temparray [ left ] ; temparray [ left ] = temparray [ right ] ; temparray [ right ] = temp ; } return String . valueOf ( temparray ) ; } public static void main ( String [ ] args ) { String X = \\\" AGGTAB \\\" ; String Y = \\\" GXTXAYB \\\" ; System . out . println ( printShortestSuperSeq ( X , Y ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Program to convert Centimeters to Pixels | Function to convert centimeter to pixels ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function Conversion ( $ centi ) { $ pixels = ( 96 * $ centi ) \\/ 2.54 ; echo ( $ pixels . \\\" \\\" ) ; } $ centi = 15 ; Conversion ( $ centi ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Largest gap in an array | function to solve the given problem ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function solve ( $ a , $ n ) { $ max1 = PHP_INT_MIN ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { if ( abs ( $ a [ $ i ] - $ a [ $ j ] ) > $ max1 ) { $ max1 = abs ( $ a [ $ i ] - $ a [ $ j ] ) ; } } } return $ max1 ; } $ arr = array ( -1 , 2 , 3 , -4 , -10 , 22 ) ; $ size = count ( $ arr ) ; echo \\\" Largest \u2581 gap \u2581 is \u2581 : \u2581 \\\" , solve ( $ arr , $ size ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find if it is possible to choose subarray that it contains exactly K even integers | Function to check if it is possible to choose a subarray that contains exactly K even integers ; Variable to store the count of even numbers ; If we have to select 0 even numbers but there is all odd numbers in the array ; If the count of even numbers is greater than or equal to K then we can select a subarray with exactly K even integers ; If the count of even numbers is less than K then we cannot select any subarray with exactly K even integers ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function isPossible ( A , n , k ) { var countOfTwo = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( A [ i ] % 2 == 0 ) { countOfTwo ++ ; } } if ( k == 0 && countOfTwo == n ) document . write ( \\\" \\\" ) ; else if ( countOfTwo >= k ) { document . write ( \\\" \\\" ) ; } else document . write ( \\\" \\\" ) ; } var arr = [ 1 , 2 , 4 , 5 ] ; var K = 2 ; var N = arr . length ; isPossible ( arr , N , K ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find a Fixed Point ( Value equal to index ) in a given array | PHP program to check fixed point in an array using linear search ; If no fixed point present then return - 1 ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function linearSearch ( $ arr , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] == $ i ) return $ i ; } return -1 ; } $ arr = array ( -10 , -1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 ) ; $ n = count ( $ arr ) ; echo \\\" Fixed \u2581 Point \u2581 is \u2581 \\\" . linearSearch ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Modify a bit at a given position | Returns modified n . ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def modifyBit ( n , p , b ) :\\n\\tmask = 1 << p\\n\\treturn ( n & ~ mask ) | ( ( b << p ) & mask )\\ndef main ( ) :\\n\\tprint ( modifyBit ( 6 , 2 , 0 ) )\\n\\tprint ( modifyBit ( 6 , 5 , 1 ) )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tmain ( )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program for factorial of a number | C ++ program to find factorial of given number ; single line to find factorial ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\nint factorial ( int n ) { return ( n == 1 n == 0 ) ? 1 : n * factorial ( n - 1 ) ; } int main ( ) { int num = 5 ; printf ( \\\" Factorial \u2581 of \u2581 % d \u2581 is \u2581 % d \\\" , num , factorial ( num ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Mobile Numeric Keypad Problem | A Space Optimized C program to count number of possible numbers of given length ; Return count of all possible numbers of length n in a given numeric keyboard ; odd [ i ] , even [ i ] arrays represent count of numbers starting with digit i for any length j ; for j = 1 ; Bottom Up calculation from j = 2 to n ; Here we are explicitly writing lines for each number 0 to 9. But it can always be written as DFS on 4 X3 grid using row , column array valid moves ; Get count of all possible numbers of length \\\" n \\\" starting with digit 0 , 1 , 2 , ... , 9 ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\nint getCount ( char keypad [ ] [ 3 ] , int n ) { if ( keypad == NULL n <= 0 ) return 0 ; if ( n == 1 ) return 10 ; int odd [ 10 ] , even [ 10 ] ; int i = 0 , j = 0 , useOdd = 0 , totalCount = 0 ; for ( i = 0 ; i <= 9 ; i ++ ) odd [ i ] = 1 ; for ( j = 2 ; j <= n ; j ++ ) { useOdd = 1 - useOdd ; if ( useOdd == 1 ) { even [ 0 ] = odd [ 0 ] + odd [ 8 ] ; even [ 1 ] = odd [ 1 ] + odd [ 2 ] + odd [ 4 ] ; even [ 2 ] = odd [ 2 ] + odd [ 1 ] + odd [ 3 ] + odd [ 5 ] ; even [ 3 ] = odd [ 3 ] + odd [ 2 ] + odd [ 6 ] ; even [ 4 ] = odd [ 4 ] + odd [ 1 ] + odd [ 5 ] + odd [ 7 ] ; even [ 5 ] = odd [ 5 ] + odd [ 2 ] + odd [ 4 ] + odd [ 8 ] + odd [ 6 ] ; even [ 6 ] = odd [ 6 ] + odd [ 3 ] + odd [ 5 ] + odd [ 9 ] ; even [ 7 ] = odd [ 7 ] + odd [ 4 ] + odd [ 8 ] ; even [ 8 ] = odd [ 8 ] + odd [ 0 ] + odd [ 5 ] + odd [ 7 ] + odd [ 9 ] ; even [ 9 ] = odd [ 9 ] + odd [ 6 ] + odd [ 8 ] ; } else { odd [ 0 ] = even [ 0 ] + even [ 8 ] ; odd [ 1 ] = even [ 1 ] + even [ 2 ] + even [ 4 ] ; odd [ 2 ] = even [ 2 ] + even [ 1 ] + even [ 3 ] + even [ 5 ] ; odd [ 3 ] = even [ 3 ] + even [ 2 ] + even [ 6 ] ; odd [ 4 ] = even [ 4 ] + even [ 1 ] + even [ 5 ] + even [ 7 ] ; odd [ 5 ] = even [ 5 ] + even [ 2 ] + even [ 4 ] + even [ 8 ] + even [ 6 ] ; odd [ 6 ] = even [ 6 ] + even [ 3 ] + even [ 5 ] + even [ 9 ] ; odd [ 7 ] = even [ 7 ] + even [ 4 ] + even [ 8 ] ; odd [ 8 ] = even [ 8 ] + even [ 0 ] + even [ 5 ] + even [ 7 ] + even [ 9 ] ; odd [ 9 ] = even [ 9 ] + even [ 6 ] + even [ 8 ] ; } } totalCount = 0 ; if ( useOdd == 1 ) { for ( i = 0 ; i <= 9 ; i ++ ) totalCount += even [ i ] ; } else { for ( i = 0 ; i <= 9 ; i ++ ) totalCount += odd [ i ] ; } return totalCount ; } int main ( ) { char keypad [ 4 ] [ 3 ] = { { '1' , '2' , '3' } , { '4' , '5' , '6' } , { '7' , '8' , '9' } , { ' * ' , '0' , ' # ' } } ; printf ( \\\" Count \u2581 for \u2581 numbers \u2581 of \u2581 length \u2581 % d : \u2581 % dn \\\" , 1 , getCount ( keypad , 1 ) ) ; printf ( \\\" Count \u2581 for \u2581 numbers \u2581 of \u2581 length \u2581 % d : \u2581 % dn \\\" , 2 , getCount ( keypad , 2 ) ) ; printf ( \\\" Count \u2581 for \u2581...\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of ways to remove a sub | C # program to count number of ways of removing a substring from a string such that all remaining characters are equal ; Function to return the number of ways of removing a sub - string from s such that all the remaining characters are same ; To store the count of prefix and suffix ; Loop to count prefix ; Loop to count suffix ; First and last characters of the string are same ; Otherwise ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int no_of_ways ( string s ) { int n = s . Length ; int count_left = 0 , count_right = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( s [ i ] == s [ 0 ] ) { ++ count_left ; } else break ; } for ( int i = n - 1 ; i >= 0 ; -- i ) { if ( s [ i ] == s [ n - 1 ] ) { ++ count_right ; } else break ; } if ( s [ 0 ] == s [ n - 1 ] ) return ( ( count_left + 1 ) * ( count_right + 1 ) ) ; else return ( count_left + count_right + 1 ) ; } public static void Main ( ) { string s = \\\" geeksforgeeks \\\" ; Console . WriteLine ( no_of_ways ( s ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Unique paths covering every non | C # implementation of the approach ; Function for dfs . i , j == > Current cell indexes vis == > To mark visited cells ans == > Result z == > Current count 0 s visited z_count == > Total 0 s present ; Mark the block as visited ; update the count ; If end block reached ; If path covered all the non - obstacle blocks ; Up ; Down ; Left ; Right ; Unmark the block ( unvisited ) ; Function to return the count of the unique paths ; int z_count = 0 ; Total 0 s present ; Count non - obstacle blocks ; Starting position ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int ans = 0 ; static void dfs ( int i , int j , int [ , ] grid , bool [ , ] vis , int z , int z_count ) { int n = grid . GetLength ( 0 ) , m = grid . GetLength ( 1 ) ; vis [ i , j ] = true ; if ( grid [ i , j ] == 0 ) z ++ ; if ( grid [ i , j ] == 2 ) { if ( z == z_count ) ans ++ ; vis [ i , j ] = false ; return ; } if ( i >= 1 && ! vis [ i - 1 , j ] && grid [ i - 1 , j ] != - 1 ) dfs ( i - 1 , j , grid , vis , z , z_count ) ; if ( i < n - 1 && ! vis [ i + 1 , j ] && grid [ i + 1 , j ] != - 1 ) dfs ( i + 1 , j , grid , vis , z , z_count ) ; if ( j >= 1 && ! vis [ i , j - 1 ] && grid [ i , j - 1 ] != - 1 ) dfs ( i , j - 1 , grid , vis , z , z_count ) ; if ( j < m - 1 && ! vis [ i , j + 1 ] && grid [ i , j + 1 ] != - 1 ) dfs ( i , j + 1 , grid , vis , z , z_count ) ; vis [ i , j ] = false ; } static int uniquePaths ( int [ , ] grid ) { int n = grid . GetLength ( 0 ) , m = grid . GetLength ( 1 ) ; bool [ , ] vis = new bool [ n , m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { vis [ i , j ] = false ; } } int x = 0 , y = 0 ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { if ( grid [ i , j ] == 0 ) z_count ++ ; else if ( grid [ i , j ] == 1 ) { x = i ; y = j ; } } } dfs ( x , y , grid , vis , 0 , z_count ) ; return ans ; } static void Main ( ) { int [ , ] grid = { { 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } , { 0 , 0 , 2 , - 1 } } ; Console . WriteLine ( uniquePaths ( grid ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximum equlibrium sum in an array | Java program to find maximum equilibrium sum . ; Function to find maximum equilibrium sum . ; Array to store prefix sum . ; Array to store suffix sum . ; Variable to store maximum sum . ; Calculate prefix sum . ; Calculate suffix sum and compare it with prefix sum . Update ans accordingly . ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; public class GFG { static int findMaxSum ( int [ ] arr , int n ) { int [ ] preSum = new int [ n ] ; int [ ] suffSum = new int [ n ] ; int ans = Integer . MIN_VALUE ; preSum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) preSum [ i ] = preSum [ i - 1 ] + arr [ i ] ; suffSum [ n - 1 ] = arr [ n - 1 ] ; if ( preSum [ n - 1 ] == suffSum [ n - 1 ] ) ans = Math . max ( ans , preSum [ n - 1 ] ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) { suffSum [ i ] = suffSum [ i + 1 ] + arr [ i ] ; if ( suffSum [ i ] == preSum [ i ] ) ans = Math . max ( ans , preSum [ i ] ) ; } return ans ; } static public void main ( String [ ] args ) { int [ ] arr = { - 2 , 5 , 3 , 1 , 2 , 6 , - 4 , 2 } ; int n = arr . length ; System . out . println ( findMaxSum ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find the Nth term of the series 14 , 28 , 20 , 40 , ... . . | Function to find the N - th term ; initializing the 1 st number ; loop from 2 nd term to nth term ; if i is even , double the previous number ; if i is odd , subtract 8 from previous number ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findNth ( $ N ) { $ b = 14 ; for ( $ i = 2 ; $ i <= $ N ; $ i ++ ) { if ( $ i % 2 == 0 ) $ b = $ b * 2 ; else $ b = $ b - 8 ; } return $ b ; } $ N = 6 ; echo findNth ( $ N ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find politeness of a number | C # program for the above approach ; Function to find politeness ; sqrt ( 2 * n ) as max length will be when the sum starts from 1 which follows the equation n ^ 2 - n - ( 2 * sum ) = 0 ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GFG { static int politness ( int n ) { int count = 0 ; for ( int i = 2 ; i <= Math . Sqrt ( 2 * n ) ; i ++ ) { int a ; if ( ( 2 * n ) % i != 0 ) continue ; a = 2 * n ; a \\/= i ; a -= ( i - 1 ) ; if ( a % 2 != 0 ) continue ; a \\/= 2 ; if ( a > 0 ) { count ++ ; } } return count ; } public static void Main ( String [ ] args ) { int n = 90 ; Console . WriteLine ( \\\" Politness \u2581 of \u2581 \\\" + n + \\\" \u2581 = \u2581 \\\" + politness ( n ) ) ; n = 15 ; Console . WriteLine ( \\\" Politness \u2581 of \u2581 \\\" + n + \\\" \u2581 = \u2581 \\\" + politness ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all divisors from 1 to n | ; var t1 = i * ( num \\/ i - i + 1 ) ; adding i every time it appears with numbers greater than or equal to itself var t2 = ( ( ( num \\/ i ) * ( num \\/ i + 1 ) ) \\/ 2 ) - ( ( i * ( i + 1 ) ) \\/ 2 ) ; adding numbers that appear with i and are greater than i ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function sum_all_divisors ( num ) { var sum = 0 ; for ( var i = 1 ; i <= Math . sqrt ( num ) ; i ++ ) { sum += t1 + t2 ; } return sum ; } var n ; var sum = sum_all_divisors ( n ) ; document . write ( sum ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Contiguous unique substrings with the given length L | Function to print the unique sub - string of length n ; set to store the strings ; if the size of the string is equal to 1 then insert ; inserting unique sub - string of length L ; Printing the set of strings ; Driver Code ; Function calling\\\"\\nSolution in Python:\",\"targets\":\"def result ( s , n ) :\\n\\tst = set ( ) ;\\n\\tfor i in range ( len ( s ) ) :\\n\\t\\tans = \\\" \\\" ;\\n\\t\\tfor j in range ( i , len ( s ) ) :\\n\\t\\t\\tans += s [ j ] ;\\n\\t\\t\\tif ( len ( ans ) == n ) :\\n\\t\\t\\t\\tst . add ( ans ) ;\\n\\t\\t\\t\\tbreak ;\\n\\tfor it in st :\\n\\t\\tprint ( it , end = \\\" \u2581 \\\" ) ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\ts = \\\" abca \\\" ;\\n\\tn = 3 ;\\n\\tresult ( s , n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sort even and odd placed elements in increasing order | function to prin the odd and even indexed digits ; lists to store the odd and even positioned digits ; traverse through all the indexes in the integer ; if the digit is in odd_index position append it to odd_position list ; else append it to the even_position list ; print the elements in the list in sorted order ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function odd_even ( $ n ) { $ odd_indexes = array ( ) ; $ even_indexes = array ( ) ; for ( $ i = 0 ; $ i < sizeof ( $ n ) ; $ i ++ ) { if ( $ i % 2 == 0 ) array_push ( $ odd_indexes , $ n [ $ i ] ) ; else array_push ( $ even_indexes , $ n [ $ i ] ) ; } sort ( $ odd_indexes ) ; for ( $ i = 0 ; $ i < sizeof ( $ odd_indexes ) ; $ i ++ ) echo $ odd_indexes [ $ i ] , \\\" \u2581 \\\" ; sort ( $ even_indexes ) ; for ( $ i = 0 ; $ i < sizeof ( $ even_indexes ) ; $ i ++ ) echo $ even_indexes [ $ i ] , \\\" \u2581 \\\" ; } $ n = array ( 3 , 2 , 7 , 6 , 8 ) ; odd_even ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Pell Number | Pell Number Series using Recursion in C ; calculate nth pell number ; driver function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint pell ( int n ) { if ( n <= 2 ) return n ; return 2 * pell ( n - 1 ) + pell ( n - 2 ) ; } int main ( ) { int n = 4 ; printf ( \\\" % d \\\" , pell ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if given four integers ( or sides ) make rectangle | A simple program to find if given 4 values can represent 4 sides of rectangle ; Function to check if the given integers value make a rectangle ; Square is also a rectangle ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool isRectangle ( int a , int b , int c , int d ) { if ( a == b == c == d ) return true ; else if ( a == b && c == d ) return true ; else if ( a == d && c == b ) return true ; else if ( a == c && d == b ) return true ; else return false ; } int main ( ) { int a , b , c , d ; a = 1 , b = 2 , c = 3 , d = 4 ; if ( isRectangle ( a , b , c , d ) ) cout << \\\" Yes \\\" ; else cout << \\\" No \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Sum of the multiples of two numbers below N | C # program to find the sum of all the integers below N which are multiples of either A or B ; Function to return the sum of all the integers below N which are multiples of either A or B ; If i is a multiple of a or b ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int findSum ( int n , int a , int b ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( i % a == 0 i % b == 0 ) sum += i ; return sum ; } static void Main ( ) { int n = 10 , a = 3 , b = 5 ; Console . WriteLine ( findSum ( n , a , b ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count the number of ways to construct the target string | C ++ Program to Count the number of ways to construct the target string ; base case ; If current subproblem has been solved , use the value ; current character ; search through all the indiced at which the current character occurs . For each index greater than prev , take the index and move to the next position , and add to the answer . ; Store and return the solution for this subproblem ; preprocess the strings by storing for each character of every string , the index of their occurrence we will use a common list for all because of only the index matter in the string from which the character was picked ; we are storing j + 1 because the initial picked index in the recursive step will ne 0. This is just for ease of implementation ; initialise dp table . - 1 represents that the subproblem hasn 't been solved ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int mod = 1000000007 ; int dp [ 1000 ] [ 1000 ] ; int calculate ( int pos , int prev , string s , vector < int > * index ) { if ( pos == s . length ( ) ) return 1 ; if ( dp [ pos ] [ prev ] != -1 ) return dp [ pos ] [ prev ] ; int c = s [ pos ] - ' a ' ; int answer = 0 ; for ( int i = 0 ; i < index . size ( ) ; i ++ ) { if ( index [ i ] > prev ) { answer = ( answer % mod + calculate ( pos + 1 , index [ i ] , s , index ) % mod ) % mod ; } } return dp [ pos ] [ prev ] = answer ; } int countWays ( vector < string > & a , string s ) { int n = a . size ( ) ; vector < int > index [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < a [ i ] . length ( ) ; j ++ ) { index [ a [ i ] [ j ] - ' a ' ] . push_back ( j + 1 ) ; } } memset ( dp , -1 , sizeof ( dp ) ) ; return calculate ( 0 , 0 , s , index ) ; } int main ( ) { vector < string > A ; A . push_back ( \\\" adc \\\" ) ; A . push_back ( \\\" aec \\\" ) ; A . push_back ( \\\" erg \\\" ) ; string S = \\\" ac \\\" ; cout << countWays ( A , S ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Largest gap in an array | A C program to find largest gap between two elements in an array . ; function to solve the given problem ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\n#include \\nint solve ( int a [ ] , int n ) { int max1 = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( abs ( a [ i ] - a [ j ] ) > max1 ) { max1 = abs ( a [ i ] - a [ j ] ) ; } } } return max1 ; } int main ( ) { int arr [ ] = { -1 , 2 , 3 , -4 , -10 , 22 } ; int size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Largest \u2581 gap \u2581 is \u2581 : \u2581 % d \\\" , solve ( arr , size ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximum sum from three arrays such that picking elements consecutively from same is not allowed | PHP implementation of the approach ; Function to return the maximum sum ; Base case ; Already visited ; If the element has been taken from first array in previous step ; If the element has been taken from second array in previous step ; If the element has been taken from third array in previous step ; Driver code ; Pick element from first array ; Pick element from second array ; Pick element from third array ; Print the maximum of them\\\"\\nSolution in php:\",\"targets\":\"< ? php $ N = 3 ; function FindMaximumSum ( $ ind , $ kon , $ a , $ b , $ c , $ n , $ dp ) { global $ N ; if ( $ ind == $ n ) return 0 ; if ( $ dp [ $ ind ] [ $ kon ] != -1 ) return $ dp [ $ ind ] [ $ kon ] ; $ ans = -1e9 + 5 ; if ( $ kon == 0 ) { $ ans = max ( $ ans , $ b [ $ ind ] + FindMaximumSum ( $ ind + 1 , 1 , $ a , $ b , $ c , $ n , $ dp ) ) ; $ ans = max ( $ ans , $ c [ $ ind ] + FindMaximumSum ( $ ind + 1 , 2 , $ a , $ b , $ c , $ n , $ dp ) ) ; } else if ( $ kon == 1 ) { $ ans = max ( $ ans , $ a [ $ ind ] + FindMaximumSum ( $ ind + 1 , 0 , $ a , $ b , $ c , $ n , $ dp ) ) ; $ ans = max ( $ ans , $ c [ $ ind ] + FindMaximumSum ( $ ind + 1 , 2 , $ a , $ b , $ c , $ n , $ dp ) ) ; } else if ( $ kon == 2 ) { $ ans = max ( $ ans , $ a [ $ ind ] + FindMaximumSum ( $ ind + 1 , 1 , $ a , $ b , $ c , $ n , $ dp ) ) ; $ ans = max ( $ ans , $ b [ $ ind ] + FindMaximumSum ( $ ind + 1 , 0 , $ a , $ b , $ c , $ n , $ dp ) ) ; } return $ dp [ $ ind ] [ $ kon ] = $ ans ; } $ a = array ( 6 , 8 , 2 , 7 , 4 , 2 , 7 ) ; $ b = array ( 7 , 8 , 5 , 8 , 6 , 3 , 5 ) ; $ c = array ( 8 , 3 , 2 , 6 , 8 , 4 , 1 ) ; $ n = count ( $ a ) ; $ dp = array_fill ( 0 , $ n , array_fill ( 0 , $ N , -1 ) ) ; $ x = FindMaximumSum ( 0 , 0 , $ a , $ b , $ c , $ n , $ dp ) ; $ y = FindMaximumSum ( 0 , 1 , $ a , $ b , $ c , $ n , $ dp ) ; $ z = FindMaximumSum ( 0 , 2 , $ a , $ b , $ c , $ n , $ dp ) ; print ( max ( $ x , max ( $ y , $ z ) ) ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Nearest prime less than given number n | Java program for the above approach ; Function to return nearest prime number ; All prime numbers are odd except two ; It will only be executed when n is 3 ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int prime ( int n ) { if ( n % 2 != 0 ) n -= 2 ; else n -- ; int i , j ; for ( i = n ; i >= 2 ; i -= 2 ) { if ( i % 2 == 0 ) continue ; for ( j = 3 ; j <= Math . sqrt ( i ) ; j += 2 ) { if ( i % j == 0 ) break ; } if ( j > Math . sqrt ( i ) ) return i ; } return 2 ; } public static void main ( String [ ] args ) { int n = 17 ; System . out . print ( prime ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Program to find whether a no is power of two | ; Function to check if x is power of 2 ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nbool isPowerOfTwo ( int n ) { if ( n == 0 ) return 0 ; while ( n != 1 ) { if ( n % 2 != 0 ) return 0 ; n = n \\/ 2 ; } return 1 ; } int main ( ) { isPowerOfTwo ( 31 ) ? printf ( \\\" Yes \\n \\\" ) : printf ( \\\" No \\n \\\" ) ; isPowerOfTwo ( 64 ) ? printf ( \\\" Yes \\n \\\" ) : printf ( \\\" No \\n \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if a number can be expressed as power | Set 2 ( Using Log ) | javascript program to find if a number can be expressed as x raised to power y . ; Find Log n in different bases and check if the value is an integer ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function isPower ( n ) { for ( x = 2 ; x <= parseInt ( Math . sqrt ( n ) ) ; x ++ ) { var f = Math . log ( n ) \\/ Math . log ( x ) ; if ( ( f - parseInt ( f ) ) == 0.0 ) return true ; } return false ; } for ( i = 2 ; i < 100 ; i ++ ) if ( isPower ( i ) ) document . write ( i + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Average of even numbers till a given even number | C # Program to find average of even numbers till a given even number . ; Function to calculate the average of even numbers ; driver function\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int averageEven ( int n ) { if ( n % 2 != 0 ) { Console . Write ( \\\" Invalid \u2581 Input \\\" ) ; return - 1 ; } return ( n + 2 ) \\/ 2 ; } public static void Main ( ) { int n = 16 ; Console . Write ( averageEven ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sum of decimals that are binary representations of first N natural numbers | Python3 program for the above approach ; Function to find the sum of first N natural numbers represented in binary representation ; Stores the resultant sum ; Iterate until the value of N is greater than 0 ; If N is less than 2 ; Store the MSB position of N ; Iterate in the range [ 1 , x ] and add the contribution of the numbers from 1 to ( 2 ^ x - 1 ) ; Update the value of the cur and add ; Add the cur to ans ; Store the remaining numbers ; Add the contribution by MSB by the remaining numbers ; The next iteration will be repeated for 2 ^ x - 1 ; Print the result ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"from math import log2 , pow\\nMOD = 1000000007\\ndef sumOfBinaryNumbers ( n ) :\\n\\tans = 0\\n\\tone = 1\\n\\twhile ( 1 ) :\\n\\t\\tif ( n <= 1 ) :\\n\\t\\t\\tans = ( ans + n ) % MOD\\n\\t\\t\\tbreak\\n\\t\\tx = int ( log2 ( n ) )\\n\\t\\tcur = 0\\n\\t\\tadd = ( one << ( x - 1 ) )\\n\\t\\tfor i in range ( 1 , x + 1 , 1 ) :\\n\\t\\t\\tcur = ( cur + add ) % MOD\\n\\t\\t\\tadd = ( add * 10 % MOD )\\n\\t\\tans = ( ans + cur ) % MOD\\n\\t\\trem = n - ( one << x ) + 1\\n\\t\\tp = pow ( 10 , x )\\n\\t\\tp = ( p * ( rem % MOD ) ) % MOD\\n\\t\\tans = ( ans + p ) % MOD\\n\\t\\tn = rem - 1\\n\\tprint ( int ( ans ) )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 3\\n\\tsumOfBinaryNumbers ( N )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Form minimum number from given sequence | Returns minimum number made from given sequence without repeating digits ; The loop runs for each input character as well as one additional time for assigning rank to each remaining characters ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function getMinNumberForPattern ( seq ) { let n = seq . length ; if ( n >= 9 ) return \\\" \\\" ; let result = new Array ( n + 1 ) ; let count = 1 ; for ( let i = 0 ; i <= n ; i ++ ) { if ( i == n seq [ i ] == ' ' ) { for ( let j = i - 1 ; j >= - 1 ; j -- ) { result [ j + 1 ] = String . fromCharCode ( ' ' . charCodeAt ( ) + count ++ ) ; if ( j >= 0 && seq [ j ] == ' ' ) break ; } } } return result . join ( \\\" \\\" ) ; } let inputs = [ \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" ] ; for ( let input = 0 ; input < inputs . length ; input ++ ) { document . write ( getMinNumberForPattern ( inputs [ input ] ) + \\\" \\\" ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Mean of array generated by products of all pairs of the given array | Function to find the mean of pair product array of arr ; Store product of pairs ; Generate all unordered pairs ; Store product of pairs ; Size of pairArray ; Store sum of pairArray ; Stores the mean of pairArray ; Find mean of pairArray ; Return the resultant mean ; Given array arr ; Function Call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function pairProductMean ( arr , N ) { var pairArray = [ ] ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { var pairProduct = arr [ i ] * arr [ j ] ; pairArray . push ( pairProduct ) ; } } var length = pairArray . length ; var sum = 0 ; for ( i = 0 ; i < length ; i ++ ) sum += pairArray [ i ] ; var mean ; if ( length != 0 ) mean = sum \\/ length ; else mean = 0 ; return mean ; } var arr = [ 1 , 2 , 4 , 8 ] ; var N = arr . length ; document . write ( pairProductMean ( arr , N ) . toFixed ( 2 ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find all divisors of a natural number | Set 2 | A O ( sqrt ( n ) ) program that prints all divisors in sorted order ; Function to print the divisors ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void printDivisors ( int n ) { for ( int i = 1 ; i * i < n ; i ++ ) { if ( n % i == 0 ) Console . Write ( i + \\\" \u2581 \\\" ) ; } for ( int i = ( int ) Math . Sqrt ( n ) ; i >= 1 ; i -- ) { if ( n % i == 0 ) Console . Write ( n \\/ i + \\\" \u2581 \\\" ) ; } } public static void Main ( string [ ] arg ) { Console . Write ( \\\" The \u2581 divisors \u2581 of \u2581 100 \u2581 are : \u2581 \\n \\\" ) ; printDivisors ( 100 ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Number of triplets in array having subarray xor equal | Java program to find Number of triplets in array having subarray xor equal ; Function to return the count ; Initialise result ; Pick 1 st element of the triplet ; Pick 2 nd element of the triplet ; Pick 3 rd element of the triplet ; Taking xor in the first subarray ; Taking xor in the second subarray ; If both xor is equal ; Driver Code ; Function Calling\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int xor_triplet ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = j ; k < n ; k ++ ) { int xor1 = 0 , xor2 = 0 ; for ( int x = i ; x < j ; x ++ ) { xor1 ^= arr [ x ] ; } for ( int x = j ; x <= k ; x ++ ) { xor2 ^= arr [ x ] ; } if ( xor1 == xor2 ) { ans ++ ; } } } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; System . out . println ( xor_triplet ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Indexed Sequential Search | C # program for Indexed Sequential Search ; Storing element ; Storing the index ; Driver code ; Element to search ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void indexedSequentialSearch ( int [ ] arr , int n , int k ) { int [ ] elements = new int [ 20 ] ; int [ ] indices = new int [ 20 ] ; int i ; int j = 0 , ind = 0 , start = 0 , end = 0 , set = 0 ; for ( i = 0 ; i < n ; i += 3 ) { elements [ ind ] = arr [ i ] ; indices [ ind ] = i ; ind ++ ; } if ( k < elements [ 0 ] ) { Console . Write ( \\\" Not \u2581 found \\\" ) ; return ; } else { for ( i = 1 ; i <= ind ; i ++ ) if ( k <= elements [ i ] ) { start = indices [ i - 1 ] ; set = 1 ; end = indices [ i ] ; break ; } } if ( set == 0 ) { start = indices [ i - 1 ] ; end = n - 1 ; } for ( i = start ; i <= end ; i ++ ) { if ( k == arr [ i ] ) { j = 1 ; break ; } } if ( j == 1 ) Console . WriteLine ( \\\" Found \u2581 at \u2581 index \u2581 \\\" + i ) ; else Console . WriteLine ( \\\" Not \u2581 found \\\" ) ; } public static void Main ( ) { int [ ] arr = { 6 , 7 , 8 , 9 , 10 } ; int n = arr . Length ; int k = 8 ; indexedSequentialSearch ( arr , n , k ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Average of first n odd naturals numbers | Returns the Avg of first n odd numbers ; sum of first n odd number ; Average of first n odd numbers ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function avg_of_odd_num ( $ n ) { $ sum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ sum += ( 2 * $ i + 1 ) ; return $ sum \\/ $ n ; } $ n = 20 ; echo ( avg_of_odd_num ( $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Program to find whether a no is power of two | ; Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#define bool int\\nbool isPowerOfTwo ( int x ) { return x && ( ! ( x & ( x - 1 ) ) ) ; } int main ( ) { isPowerOfTwo ( 31 ) ? printf ( \\\" Yes \\n \\\" ) : printf ( \\\" No \\n \\\" ) ; isPowerOfTwo ( 64 ) ? printf ( \\\" Yes \\n \\\" ) : printf ( \\\" No \\n \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Print all triplets in sorted array that form AP | C # implementation to print all the triplets in given array that form Arithmetic Progression ; Function to print all triplets in given sorted array that forms AP ; Search other two elements of AP with arr [ i ] as middle . ; if a triplet is found ; Since elements are distinct , arr [ k ] and arr [ j ] cannot form any more triplets with arr [ i ] ; If middle element is more move to higher side , else move lower side . ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void findAllTriplets ( int [ ] arr , int n ) { for ( int i = 1 ; i < n - 1 ; i ++ ) { for ( int j = i - 1 , k = i + 1 ; j >= 0 && k < n ; ) { if ( arr [ j ] + arr [ k ] == 2 * arr [ i ] ) { Console . WriteLine ( arr [ j ] + \\\" \u2581 \\\" + arr [ i ] + \\\" \u2581 \\\" + arr [ k ] ) ; k ++ ; j -- ; } else if ( arr [ j ] + arr [ k ] < 2 * arr [ i ] ) k ++ ; else j -- ; } } } public static void Main ( ) { int [ ] arr = { 2 , 6 , 9 , 12 , 17 , 22 , 31 , 32 , 35 , 42 } ; int n = arr . Length ; findAllTriplets ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimum cost to fill given weight in a bag | Java program to find minimum cost to get exactly W Kg with given packets ; Returns the best obtainable price for a rod of length n and price [ ] as prices of different pieces ; Build the table val [ ] in bottom up manner and return the last entry from the table ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class Main { public static int minCost ( int cost [ ] , int n ) { int dp [ ] = new int [ n + 1 ] ; dp [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int min_cost = Integer . MAX_VALUE ; for ( int j = 0 ; j < i ; j ++ ) if ( j < cost . length && cost [ j ] != - 1 ) { min_cost = Math . min ( min_cost , cost [ j ] + dp [ i - j - 1 ] ) ; } dp [ i ] = min_cost ; } return dp [ n ] ; } public static void main ( String [ ] args ) { int cost [ ] = { 10 , - 1 , - 1 , - 1 , - 1 } ; int W = cost . length ; System . out . print ( minCost ( cost , W ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find two numbers with given sum and maximum possible LCM | Function that print two numbers with the sum X and maximum possible LCM ; variables to store the result ; If X is odd ; If X is even ; If floor ( X \\/ 2 ) is even ; If floor ( X \\/ 2 ) is odd ; Print the result ; Given Number ; Function call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function maxLCMWithGivenSum ( X ) { let A , B ; if ( X & 1 ) { A = X \\/ 2 ; B = X \\/ 2 + 1 ; } else { if ( ( X \\/ 2 ) % 2 == 0 ) { A = X \\/ 2 - 1 ; B = X \\/ 2 + 1 ; } else { A = X \\/ 2 - 2 ; B = X \\/ 2 + 2 ; } } document . write ( A + \\\" \\\" + B + \\\" \\\" ) ; } let X = 30 ; maxLCMWithGivenSum ( X ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Finding LCM of more than two ( or array ) numbers without using GCD | Returns LCM of arr [ 0. . n - 1 ] ; Find the maximum value in arr [ ] ; Initialize result ; Find all factors that are present in two or more array elements . $x = 2 ; Current factor . ; To store indexes of all array elements that are divisible by x . ; If there are 2 or more array elements that are divisible by x . ; Reduce all array elements divisible by x . ; Then multiply all reduced array elements ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function LCM ( $ arr , $ n ) { $ max_num = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( $ max_num < $ arr [ $ i ] ) $ max_num = $ arr [ $ i ] ; $ res = 1 ; while ( $ x <= $ max_num ) { $ indexes = array ( ) ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) if ( $ arr [ $ j ] % $ x == 0 ) array_push ( $ indexes , $ j ) ; if ( count ( $ indexes ) >= 2 ) { for ( $ j = 0 ; $ j < count ( $ indexes ) ; $ j ++ ) $ arr [ $ indexes [ $ j ] ] = ( int ) ( $ arr [ $ indexes [ $ j ] ] \\/ $ x ) ; $ res = $ res * $ x ; } else $ x ++ ; } for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ res = $ res * $ arr [ $ i ] ; return $ res ; } $ arr = array ( 1 , 2 , 3 , 4 , 5 , 10 , 20 , 35 ) ; $ n = count ( $ arr ) ; echo LCM ( $ arr , $ n ) . \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Area of a Square | Using Side , Diagonal and Perimeter | C # program for the above approach ; Function to find the area of a square ; Use above formula ; Driver Code ; Given Side of square ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int areaOfSquare ( int S ) { int area = S * S ; return area ; } public static void Main ( string [ ] args ) { int S = 5 ; Console . Write ( areaOfSquare ( S ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Majority Element | Function to find Majority element in an array it returns - 1 if there is no majority element ; Sort the array in O ( nlogn ) ; Increases the count if the same element occurs otherwise starts counting new element ; Sets maximum count and stores maximum occured element so far if maximum count becomes greater than n \\/ 2 it breaks out setting the flag ; Returns maximum occured element if there is no such element , returns - 1 ; Driver code ; Function calling\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function majorityElement ( arr , n ) { arr . sort ( function ( a , b ) { return a - b } ) ; let count = 1 , max_ele = - 1 , temp = arr [ 0 ] , ele = 0 , f = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( temp == arr [ i ] ) { count ++ ; } else { count = 1 ; temp = arr [ i ] ; } if ( max_ele < count ) { max_ele = count ; ele = arr [ i ] ; if ( max_ele > parseInt ( n \\/ 2 , 10 ) ) { f = 1 ; break ; } } } return ( f == 1 ? ele : - 1 ) ; } let arr = [ 1 , 1 , 2 , 1 , 3 , 5 , 1 ] ; let n = 7 ; document . write ( majorityElement ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program to find nth term of the series 1 4 15 24 45 60 92 | function to calculate nth term of the series ; variable nth will store the nth term of series ; if n is even ; if n is odd ; return nth term ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function nthTerm ( $ n ) { $ nth ; if ( $ n % 2 == 0 ) $ nth = 2 * ( ( $ n * $ n ) - $ n ) ; else $ nth = ( 2 * $ n * $ n ) - $ n ; return $ nth ; } $ n = 5 ; echo nthTerm ( $ n ) , \\\" \\n \\\" ; $ n = 25 ; echo nthTerm ( $ n ) , \\\" \\n \\\" ; $ n = 25000000 ; echo nthTerm ( $ n ) , \\\" \\n \\\" ; $ n = 250000007 ; echo nthTerm ( $ n ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Program to print ' N ' alphabet using the number pattern from 1 to n | C implementation of the approach ; Function to print the desired Alphabet N Pattern ; Declaring the values of Right , Left and Diagonal values ; Main Loop for the rows ; For the left Values ; Spaces for the diagonals ; Condition for the diagonals ; Spaces for the Right Values ; For the right values ; Driver Code ; Size of the Pattern ; Calling the function to print the desired Pattern\\nHow can the above be solved in C?\",\"targets\":\"#include \\nvoid Alphabet_N_Pattern ( int N ) { int index , side_index , size ; int Right = 1 , Left = 1 , Diagonal = 2 ; for ( index = 0 ; index < N ; index ++ ) { printf ( \\\" % d \\\" , Left ++ ) ; for ( side_index = 0 ; side_index < 2 * ( index ) ; side_index ++ ) printf ( \\\" \u2581 \\\" ) ; if ( index != 0 && index != N - 1 ) printf ( \\\" % d \\\" , Diagonal ++ ) ; else printf ( \\\" \u2581 \\\" ) ; for ( side_index = 0 ; side_index < 2 * ( N - index - 1 ) ; side_index ++ ) printf ( \\\" \u2581 \\\" ) ; printf ( \\\" % d \\\" , Right ++ ) ; printf ( \\\" \\n \\\" ) ; } } int main ( int argc , char * * argv ) { int Size = 6 ; Alphabet_N_Pattern ( Size ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count the number of ways to divide N in k groups incrementally | DP Table ; Function to count the number of ways to divide the number N in groups such that each group has K number of elements ; Base Case ; if N is divides completely into less than k groups ; If the subproblem has been solved , use the value ; put all possible values greater equal to prev ; Function to count the number of ways to divide the number N in groups ; Initialize DP Table as - 1 ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"dp = [ [ [ 0 for i in range ( 50 ) ] for j in range ( 50 ) ] for j in range ( 50 ) ]\\ndef calculate ( pos , prev , left , k ) :\\n\\tif ( pos == k ) :\\n\\t\\tif ( left == 0 ) :\\n\\t\\t\\treturn 1 ;\\n\\t\\telse :\\n\\t\\t\\treturn 0 ;\\n\\tif ( left == 0 ) :\\n\\t\\treturn 0 ;\\n\\tif ( dp [ pos ] [ prev ] [ left ] != - 1 ) :\\n\\t\\treturn dp [ pos ] [ prev ] [ left ] ;\\n\\tanswer = 0 ;\\n\\tfor i in range ( prev , left + 1 ) :\\n\\t\\tanswer += calculate ( pos + 1 , i , left - i , k ) ;\\n\\tdp [ pos ] [ prev ] [ left ] = answer ;\\n\\treturn dp [ pos ] [ prev ] [ left ] ;\\ndef countWaystoDivide ( n , k ) :\\n\\tfor i in range ( 50 ) :\\n\\t\\tfor j in range ( 50 ) :\\n\\t\\t\\tfor l in range ( 50 ) :\\n\\t\\t\\t\\tdp [ i ] [ j ] [ l ] = - 1 ;\\n\\treturn calculate ( 0 , 1 , n , k ) ;\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 8 ;\\n\\tK = 4 ;\\n\\tprint ( countWaystoDivide ( N , K ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Seeds ( Or Seed Roots ) of a number | C # program to find Seed of a number ; Stores product of digits of x in prodDig [ x ] ; If x has single digit ; If digit product is already computed ; If digit product is not computed before . ; Prints all seeds of n ; Find all seeds using prodDig [ ] ; If there was no seed ; Print seeds ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections ; class GFG { static int MAX = 10000 ; static int [ ] prodDig = new int [ MAX ] ; static int getDigitProduct ( int x ) { if ( x < 10 ) return x ; if ( prodDig [ x ] != 0 ) return prodDig [ x ] ; int prod = ( x % 10 ) * getDigitProduct ( x \\/ 10 ) ; return ( prodDig [ x ] = prod ) ; } static void findSeed ( int n ) { ArrayList res = new ArrayList ( ) ; for ( int i = 1 ; i <= n \\/ 2 ; i ++ ) if ( i * getDigitProduct ( i ) == n ) res . Add ( i ) ; if ( res . Count == 0 ) { Console . WriteLine ( \\\" NO \u2581 seed \u2581 exists \\\" ) ; return ; } for ( int i = 0 ; i < res . Count ; i ++ ) Console . WriteLine ( res [ i ] + \\\" \u2581 \\\" ) ; } static void Main ( ) { int n = 138 ; findSeed ( n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the profit or loss when CP of N items is equal to SP of M items | Function to calculate Profit or loss ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function profitLoss ( $ N , $ M ) { if ( $ N == $ M ) echo \\\" No \u2581 Profit \u2581 nor \u2581 Loss \\\" ; else { $ result = 0.0 ; $ result = ( abs ( $ N - $ M ) ) \\/ $ M ; if ( $ N - $ M < 0 ) echo \\\" Loss \u2581 = \u2581 - \\\" , $ result * 100 , \\\" % \\\" ; else echo \\\" Profit \u2581 = \u2581 \\\" , $ result * 100 , \\\" % \\\" ; } } $ N = 8 ; $ M = 9 ; profitLoss ( $ N , $ M ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Print the most occurring character in an array of strings | C # program to print the most occurring character in an array of Strings ; Function to print the most occurring character ; Creating a hash of size 26 ; For loop to iterate through every String of the array ; For loop to iterate through every character of the String ; Incrementing the count of the character in the hash ; Finding the character with the maximum count ; Driver code ; Declaring Vector of String type\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void findMostOccurringChar ( string [ ] str ) { int [ ] hash = new int [ 26 ] ; for ( int i = 0 ; i < str . Length ; i ++ ) { for ( int j = 0 ; j < str [ i ] . Length ; j ++ ) { hash [ str [ i ] [ j ] - 97 ] ++ ; } } int max = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { max = hash [ i ] > hash [ max ] ? i : max ; } Console . Write ( ( char ) ( max + 97 ) + \\\" \\n \\\" ) ; } public static void Main ( String [ ] args ) { string [ ] str = { \\\" animal \\\" , \\\" zebra \\\" , \\\" lion \\\" , \\\" giraffe \\\" } ; findMostOccurringChar ( str ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"C \\/ C ++ Program for Longest Increasing Subsequence | A Naive C recursive implementation of LIS problem ; To make use of recursive calls , this function must return two things : 1 ) Length of LIS ending with element arr [ n - 1 ] . We use max_ending_here for this purpose 2 ) Overall maximum as the LIS may end with an element before arr [ n - 1 ] max_ref is used this purpose . The value of LIS of full array of size n is stored in * max_ref which is our final result ; Base case ; ' max _ ending _ here ' is length of LIS ending with arr [ n - 1 ] ; Recursively get all LIS ending with arr [ 0 ] , arr [ 1 ] ... arr [ n - 2 ] . If arr [ i - 1 ] is smaller than arr [ n - 1 ] , and max ending with arr [ n - 1 ] needs to be updated , then update it ; Compare max_ending_here with the overall max . And update the overall max if needed ; Return length of LIS ending with arr [ n - 1 ] ; The wrapper function for _lis ( ) ; The max variable holds the result ; The function _lis ( ) stores its result in max ; returns max ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nint _lis ( int arr [ ] , int n , int * max_ref ) { if ( n == 1 ) return 1 ; int res , max_ending_here = 1 ; for ( int i = 1 ; i < n ; i ++ ) { res = _lis ( arr , i , max_ref ) ; if ( arr [ i - 1 ] < arr [ n - 1 ] && res + 1 > max_ending_here ) max_ending_here = res + 1 ; } if ( * max_ref < max_ending_here ) * max_ref = max_ending_here ; return max_ending_here ; } int lis ( int arr [ ] , int n ) { int max = 1 ; _lis ( arr , n , & max ) ; return max ; } int main ( ) { int arr [ ] = { 10 , 22 , 9 , 33 , 21 , 50 , 41 , 60 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Length \u2581 of \u2581 lis \u2581 is \u2581 % d \\n \\\" , lis ( arr , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Length of the longest substring without repeating characters | Python3 program to find the length of the longest substring without repeating characters ; Result ; Note : Default values in visited are false ; If current character is visited Break the loop ; Else update the result if this window is larger , and mark current character as visited . ; Remove the first character of previous window ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def longestUniqueSubsttr ( str ) :\\n\\tn = len ( str )\\n\\tres = 0\\n\\tfor i in range ( n ) :\\n\\t\\tvisited = [ 0 ] * 256\\n\\t\\tfor j in range ( i , n ) :\\n\\t\\t\\tif ( visited [ ord ( str [ j ] ) ] == True ) :\\n\\t\\t\\t\\tbreak\\n\\t\\t\\telse :\\n\\t\\t\\t\\tres = max ( res , j - i + 1 )\\n\\t\\t\\t\\tvisited [ ord ( str [ j ] ) ] = True\\n\\t\\tvisited [ ord ( str [ i ] ) ] = False\\n\\treturn res\\nstr = \\\" geeksforgeeks \\\"\\nprint ( \\\" The \u2581 input \u2581 is \u2581 \\\" , str )\\nlen = longestUniqueSubsttr ( str )\\nprint ( \\\" The \u2581 length \u2581 of \u2581 the \u2581 longest \u2581 \\\" \\\" non - repeating \u2581 character \u2581 substring \u2581 is \u2581 \\\" , len )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if two strings can be made equal by reversing a substring of one of the strings | Function to check if the Strings can be made equal or not by reversing a subString of X ; Store the first index from the left which contains unequal characters in both the Strings ; Store the first element from the right which contains unequal characters in both the Strings ; Checks for the first index from left in which characters in both the Strings are unequal ; Store the current index ; Break out of the loop ; Checks for the first index from right in which characters in both the Strings are unequal ; Store the current index ; Break out of the loop ; Reverse the subString X [ L , R ] ; If X and Y are equal ; Otherwise ; Driver Code ; Function Call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function checkString ( X , Y ) { var L = - 1 ; var R = - 1 ; for ( var i = 0 ; i < X . length ; ++ i ) { if ( X [ i ] !== Y [ i ] ) { L = i ; break ; } } for ( var i = X . length - 1 ; i > 0 ; -- i ) { if ( X [ i ] !== Y [ i ] ) { R = i ; break ; } } X = X . substring ( 0 , L ) + reverse ( X . substring ( L , R + 1 ) ) + X . substring ( R + 1 ) ; if ( X === Y ) { document . write ( \\\" \\\" ) ; } else { document . write ( \\\" \\\" ) ; } } function reverse ( input ) { var a = input . split ( \\\" \\\" ) ; var l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { var temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return a . join ( \\\" \\\" ) ; } var X = \\\" \\\" , Y = \\\" \\\" ; checkString ( X , Y ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"k | Python Program to print kth prime factor ; A function to generate prime factors of a given number n and return k - th prime factor ; Find the number of 2 's that divide k ; n must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; While i divides n , store i and divide n ; This condition is to handle the case where n is a prime number greater than 2 ; Driver Program\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import math\\ndef kPrimeFactor ( n , k ) :\\n\\twhile ( n % 2 == 0 ) :\\n\\t\\tk = k - 1\\n\\t\\tn = n \\/ 2\\n\\t\\tif ( k == 0 ) :\\n\\t\\t\\treturn 2\\n\\ti = 3\\n\\twhile i <= math . sqrt ( n ) :\\n\\t\\twhile ( n % i == 0 ) :\\n\\t\\t\\tif ( k == 1 ) :\\n\\t\\t\\t\\treturn i\\n\\t\\t\\tk = k - 1\\n\\t\\t\\tn = n \\/ i\\n\\t\\ti = i + 2\\n\\tif ( n > 2 and k == 1 ) :\\n\\t\\treturn n\\n\\treturn - 1\\nn = 12\\nk = 3\\nprint ( kPrimeFactor ( n , k ) )\\nn = 14\\nk = 3\\nprint ( kPrimeFactor ( n , k ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find the smallest missing number | C program to find the smallest elements missing in a sorted array . ; function that returns smallest elements missing in a sorted array . ; Left half has all elements from 0 to mid ; driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\nint findFirstMissing ( int array [ ] , int start , int end ) { if ( start > end ) return end + 1 ; if ( start != array [ start ] ) return start ; int mid = ( start + end ) \\/ 2 ; if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ; return findFirstMissing ( array , start , mid ) ; } int main ( ) { int arr [ ] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 10 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Smallest \u2581 missing \u2581 element \u2581 is \u2581 % d \\\" , findFirstMissing ( arr , 0 , n - 1 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximum length palindrome that can be created with characters in range L and R | Python3 implementation of the approach ; Function to return the length of the longest palindrome that can be formed using the characters in the range [ l , r ] ; 0 - based indexing ; Marks if there is an odd frequency character ; Length of the longest palindrome possible from characters in range ; Traverse for all characters and count their frequencies ; Find the frequency in range 1 - r ; Exclude the frequencies in range 1 - ( l - 1 ) ; If frequency is odd , then add 1 less than the original frequency to make it even ; Else completely add if even ; If any odd frequency character is present then add 1 ; Function to pre - calculate the frequencies of the characters to reduce complexity ; Iterate and increase the count ; Create a prefix type array ; Driver code ; Pre - calculate prefix array ; Perform queries\\\"\\nHow can the above be solved in Python?\",\"targets\":\"N = 4\\ndef performQueries ( l , r , prefix ) :\\n\\tl -= 1\\n\\tr -= 1\\n\\tflag = False\\n\\tcount = 0\\n\\tfor i in range ( 26 ) :\\n\\t\\tcnt = prefix [ r ] [ i ]\\n\\t\\tif ( l > 0 ) :\\n\\t\\t\\tcnt -= prefix [ l - 1 ] [ i ]\\n\\t\\tif ( cnt % 2 == 1 ) :\\n\\t\\t\\tflag = True\\n\\t\\t\\tcount += cnt - 1\\n\\t\\telse :\\n\\t\\t\\tcount += cnt\\n\\tif ( flag ) :\\n\\t\\tcount += 1\\n\\treturn count\\ndef preCalculate ( s , prefix ) :\\n\\tn = len ( s )\\n\\tfor i in range ( n ) :\\n\\t\\tprefix [ i ] [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1\\n\\tfor i in range ( 1 , n ) :\\n\\t\\tfor j in range ( 26 ) :\\n\\t\\t\\tprefix [ i ] [ j ] += prefix [ i - 1 ] [ j ]\\ns = \\\" amim \\\"\\nprefix = [ [ 0 for i in range ( 26 ) ] for i in range ( N ) ]\\npreCalculate ( s , prefix )\\nqueries = [ [ 1 , 4 ] , [ 3 , 4 ] ]\\nq = len ( queries )\\nfor i in range ( q ) :\\n\\tprint ( performQueries ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , prefix ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sum of XOR of all sub | Java implementation of the approach ; Sum of XOR of all K length sub - array of an array ; If the length of the array is less than k ; Array that will store xor values of subarray from 1 to i ; Traverse through the array ; If i is greater than zero , store xor of all the elements from 0 to i ; If it is the first element ; If i is greater than k ; Xor of values from 0 to i ; Now to find subarray of length k that ends at i , xor sum with x [ i - k ] ; Add the xor of elements from i - k + 1 to i ; Return the resultant sum ; ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int FindXorSum ( int arr [ ] , int k , int n ) { if ( n < k ) return 0 ; int [ ] x = new int [ n ] ; int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i > 0 ) x [ i ] = x [ i - 1 ] ^ arr [ i ] ; else x [ i ] = arr [ i ] ; if ( i >= k - 1 ) { int sum = 0 ; sum = x [ i ] ; if ( i - k > - 1 ) sum ^= x [ i - k ] ; result += sum ; } } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = 4 , k = 2 ; System . out . println ( FindXorSum ( arr , k , n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Trapping Rain Water | C ++ program to find maximum amount of water that can be trapped within given set of bars . Space Complexity : O ( 1 ) ; initialize output ; maximum element on left and right ; indices to traverse the array ; update max in left ; water on curr element = max - curr ; update right maximum ; Driver program to test above function\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int findWater ( int arr [ ] , int n ) { int result = 0 ; int left_max = 0 , right_max = 0 ; int lo = 0 , hi = n - 1 ; while ( lo <= hi ) { if ( arr [ lo ] < arr [ hi ] ) { if ( arr [ lo ] > left_max ) left_max = arr [ lo ] ; else result += left_max - arr [ lo ] ; lo ++ ; } else { if ( arr [ hi ] > right_max ) right_max = arr [ hi ] ; else result += right_max - arr [ hi ] ; hi -- ; } } return result ; } int main ( ) { int arr [ ] = { 0 , 1 , 0 , 2 , 1 , 0 , 1 , 3 , 2 , 1 , 2 , 1 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << \\\" Maximum \u2581 water \u2581 that \u2581 can \u2581 be \u2581 accumulated \u2581 is \u2581 \\\" << findWater ( arr , n ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Maximum difference between two elements such that larger element appears after the smaller number | ; The function assumes that there are at least two elements in array . The function returns a negative value if the array is sorted in decreasing order . Returns 0 if elements are equal ; Driver program to test above function ; Function calling\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint maxDiff ( int arr [ ] , int arr_size ) { int max_diff = arr [ 1 ] - arr [ 0 ] ; int i , j ; for ( i = 0 ; i < arr_size ; i ++ ) { for ( j = i + 1 ; j < arr_size ; j ++ ) { if ( arr [ j ] - arr [ i ] > max_diff ) max_diff = arr [ j ] - arr [ i ] ; } } return max_diff ; } int main ( ) { int arr [ ] = { 1 , 2 , 90 , 10 , 110 } ; printf ( \\\" Maximum \u2581 difference \u2581 is \u2581 % d \\\" , maxDiff ( arr , 5 ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Calculate speed , distance and time | C ++ Program to calculate speed distance and time ; Function to calculate speed ; Function to calculate distance traveled ; Function to calculate time taken ; Driver function ; Calling function cal_speed ( ) ; Calling function cal_dis ( ) ; Calling function cal_time ( )\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; double cal_speed ( double dist , double time ) { cout << \\\" Distance ( km ) : \\\" cout << \\\" Time ( hr ) : \\\" return dist \\/ time ; } double cal_dis ( double speed , double time ) { cout << \\\" Time ( hr ) : \\\" cout << \\\" Speed ( km \\/ hr ) : \\\" return speed * time ; } double cal_time ( double dist , double speed ) { cout << \\\" Distance ( km ) : \\\" cout << \\\" Speed ( km \\/ hr ) : \\\" return speed * dist ; } int main ( ) { cout << \\\" The calculated Speed ( km \\/ hr ) is : \\\" << cal_speed ( 45.9 , 2.0 ) << endl ; cout << \\\" The calculated Distance ( km ) : \\\" << cal_dis ( 62.9 , 2.5 ) << endl ; cout << \\\" The calculated Time ( hr ) : \\\" << cal_time ( 48.0 , 4.5 ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Tetranacci Numbers | A simple recursive C # program to print the nth tetranacci numbers . ; Function to return the N - th tetranacci number ; base cases ; base cases ; base cases ; function to print the Nth tetranacci number ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"class GFG { static int printTetraRec ( int n ) { if ( n == 0 ) return 0 ; if ( n == 1 n == 2 ) return 1 ; if ( n == 3 ) return 2 ; else return printTetraRec ( n - 1 ) + printTetraRec ( n - 2 ) + printTetraRec ( n - 3 ) + printTetraRec ( n - 4 ) ; } static void printTetra ( int n ) { System . Console . WriteLine ( printTetraRec ( n ) + \\\" \u2581 \\\" ) ; } static void Main ( ) { int n = 10 ; printTetra ( n ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Construct Binary Tree from given Parent Array representation | C # program to construct a binary tree from parent array ; A binary tree node ; Creates a node with key as ' i ' . If i is root , then it changes root . If parent of i is not created , then it creates parent first ; If this node is already created ; Create a new node and set created [ i ] ; If ' i ' is root , change root pointer and return ; If parent is not created , then create parent first ; Find parent pointer ; If this is first child of parent ; If second child ; Creates tree from parent [ 0. . n - 1 ] and returns root of the created tree ; Create an array created [ ] to keep track of created nodes , initialize all entries as NULL ; For adding new line in a program ; Utility function to do inorder traversal ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class Node { public int key ; public Node left , right ; public Node ( int key ) { this . key = key ; left = right = null ; } } class GFG { public Node root ; public virtual void createNode ( int [ ] parent , int i , Node [ ] created ) { if ( created [ i ] != null ) { return ; } created [ i ] = new Node ( i ) ; if ( parent [ i ] == - 1 ) { root = created [ i ] ; return ; } if ( created [ parent [ i ] ] == null ) { createNode ( parent , parent [ i ] , created ) ; } Node p = created [ parent [ i ] ] ; if ( p . left == null ) { p . left = created [ i ] ; } else { p . right = created [ i ] ; } } public virtual Node createTree ( int [ ] parent , int n ) { Node [ ] created = new Node [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { created [ i ] = null ; } for ( int i = 0 ; i < n ; i ++ ) { createNode ( parent , i , created ) ; } return root ; } public virtual void newLine ( ) { Console . WriteLine ( \\\" \\\" ) ; } public virtual void inorder ( Node node ) { if ( node != null ) { inorder ( node . left ) ; Console . Write ( node . key + \\\" \u2581 \\\" ) ; inorder ( node . right ) ; } } public static void Main ( string [ ] args ) { GFG tree = new GFG ( ) ; int [ ] parent = new int [ ] { - 1 , 0 , 0 , 1 , 1 , 3 , 5 } ; int n = parent . Length ; Node node = tree . createTree ( parent , n ) ; Console . WriteLine ( \\\" Inorder \u2581 traversal \u2581 of \u2581 \\\" + \\\" constructed \u2581 tree \u2581 \\\" ) ; tree . inorder ( node ) ; tree . newLine ( ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"Find the smallest missing number | C program to find the smallest elements missing in a sorted array . ; function that returns smallest elements missing in a sorted array . ; Left half has all elements from 0 to mid ; driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint findFirstMissing ( int array [ ] , int start , int end ) { if ( start > end ) return end + 1 ; if ( start != array [ start ] ) return start ; int mid = ( start + end ) \\/ 2 ; if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ; return findFirstMissing ( array , start , mid ) ; } int main ( ) { int arr [ ] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 10 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Smallest \u2581 missing \u2581 element \u2581 is \u2581 % d \\\" , findFirstMissing ( arr , 0 , n - 1 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Find a Fixed Point ( Value equal to index ) in a given array | C program to check fixed point in an array using linear search ; If no fixed point present then return - 1 ; Driver program to check above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint linearSearch ( int arr [ ] , int n ) { int i ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == i ) return i ; } return -1 ; } int main ( ) { int arr [ ] = { -10 , -1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Fixed \u2581 Point \u2581 is \u2581 % d \\\" , linearSearch ( arr , n ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Reduce array to longest sorted array possible by removing either half of given array in each operation | Function to check if the subarray arr [ i . . j ] is a sorted subarray or not ; Traverse all elements of the subarray arr [ i ... j ] ; If the previous element of the subarray exceeds current element ; Return 0 ; Return 1 ; Recursively partition the array into two equal halves ; If atmost one element is left in the subarray arr [ i . . j ] ; Checks if subarray arr [ i . . j ] is a sorted subarray or not ; If the subarray arr [ i ... j ] is a sorted subarray ; Stores middle element of the subarray arr [ i . . j ] ; Recursively partition the current subarray arr [ i . . j ] into equal halves ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def isSortedparitions ( arr , i , j ) :\\n\\tfor k in range ( i + 1 , j + 1 ) :\\n\\t\\tif ( arr [ k ] < arr [ k - 1 ] ) :\\n\\t\\t\\treturn 0\\n\\treturn 1\\ndef partitionsArr ( arr , i , j ) :\\n\\tif ( i >= j ) :\\n\\t\\treturn 1\\n\\tflag = int ( isSortedparitions ( arr , i , j ) )\\n\\tif ( flag != 0 ) :\\n\\t\\treturn ( j - i + 1 )\\n\\tmid = ( i + j ) \\/\\/ 2\\n\\tX = partitionsArr ( arr , i , mid ) ;\\n\\tY = partitionsArr ( arr , mid + 1 , j )\\n\\treturn max ( X , Y )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 11 , 12 , 1 , 2 , 13 , 14 , 3 , 4 ]\\n\\tN = len ( arr )\\n\\tprint ( partitionsArr ( arr , 0 , N - 1 ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program to print binomial expansion series | Java program to print terms of binomial series and also calculate sum of series . ; function to print the series ; Calculating and printing first term ; Computing and printing remaining terms ; Find current term using previous terms We increment power of X by 1 , decrement power of A by 1 and compute nCi using previous term by multiplying previous term with ( n - i + 1 ) \\/ i ; main function started\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static void series ( int A , int X , int n ) { int term = ( int ) Math . pow ( A , n ) ; System . out . print ( term + \\\" \u2581 \\\" ) ; for ( int i = 1 ; i <= n ; i ++ ) { term = term * X * ( n - i + 1 ) \\/ ( i * A ) ; System . out . print ( term + \\\" \u2581 \\\" ) ; } } public static void main ( String [ ] args ) { int A = 3 , X = 4 , n = 5 ; series ( A , X , n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if two strings are permutation of each other | C ++ function to check whether two strings are Permutations of each other ; Create a count array and initialize all values as 0 ; For each character in input strings , increment count in the corresponding count array ; If both strings are of different length . Removing this condition will make the program fail for strings like \\\" aaca \\\" and \\\" aca \\\" ; See if there is any non - zero value in count array\\\"\\nSolution in C++:\",\"targets\":\"bool arePermutation ( string str1 , string str2 ) { int count [ NO_OF_CHARS ] = { 0 } ; int i ; for ( i = 0 ; str1 [ i ] && str2 [ i ] ; i ++ ) { count [ str1 [ i ] ] ++ ; count [ str2 [ i ] ] -- ; } if ( str1 [ i ] str2 [ i ] ) return false ; for ( i = 0 ; i < NO_OF_CHARS ; i ++ ) if ( count [ i ] ) return false ; return true ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Matrix Chain Multiplication | DP | See the Cormen book for details of the following algorithm ; Matrix Ai has dimension p [ i - 1 ] x p [ i ] for i = 1. . n ; For simplicity of the program , one extra row and one extra column are allocated in m [ ] [ ] . 0 th row and 0 th column of m [ ] [ ] are not used ; cost is zero when multiplying one matrix . ; L is chain length . ; q = cost \\/ scalar multiplications ; Driver code\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nint MatrixChainOrder ( int p [ ] , int n ) { int m [ n ] [ n ] ; int i , j , k , L , q ; for ( i = 1 ; i < n ; i ++ ) m [ i ] [ i ] = 0 ; for ( L = 2 ; L < n ; L ++ ) { for ( i = 1 ; i < n - L + 1 ; i ++ ) { j = i + L - 1 ; m [ i ] [ j ] = INT_MAX ; for ( k = i ; k <= j - 1 ; k ++ ) { q = m [ i ] [ k ] + m [ k + 1 ] [ j ] + p [ i - 1 ] * p [ k ] * p [ j ] ; if ( q < m [ i ] [ j ] ) m [ i ] [ j ] = q ; } } } return m [ 1 ] [ n - 1 ] ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Minimum \u2581 number \u2581 of \u2581 multiplications \u2581 is \u2581 % d \u2581 \\\" , MatrixChainOrder ( arr , size ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Find a pair with the given difference | C program to find a pair with the given difference ; The function assumes that the array is sorted ; Initialize positions of two elements ; Search for a pair ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nbool findPair ( int arr [ ] , int size , int n ) { int i = 0 ; int j = 1 ; while ( i < size && j < size ) { if ( i != j && arr [ j ] - arr [ i ] == n ) { printf ( \\\" Pair \u2581 Found : \u2581 ( % d , \u2581 % d ) \\\" , arr [ i ] , arr [ j ] ) ; return true ; } else if ( arr [ j ] - arr [ i ] < n ) j ++ ; else i ++ ; } printf ( \\\" No \u2581 such \u2581 pair \\\" ) ; return false ; } int main ( ) { int arr [ ] = { 1 , 8 , 30 , 40 , 100 } ; int size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int n = 60 ; findPair ( arr , size , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if a string can be made equal to another string by swapping or replacement of characters | C ++ program for the above approach ; Function to find if given strings are same or not ; Base Condition ; Stores frequency of characters of the string str1 and str2 ; Traverse strings str1 & str2 and store frequencies in a [ ] and b [ ] ; Check if both strings have same characters or not ; If a character is present in one string and is not in another string , return false ; Sort the array a [ ] and b [ ] ; Check arrays a and b contain the same frequency or not ; If the frequencies are not the same after sorting ; At this point , str1 can be converted to str2 ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool sameStrings ( string str1 , string str2 ) { int N = str1 . length ( ) ; int M = str2 . length ( ) ; if ( N != M ) { return false ; } int a [ 256 ] = { 0 } , b [ 256 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { a [ str1 [ i ] - ' a ' ] ++ ; b [ str2 [ i ] - ' a ' ] ++ ; } int i = 0 ; while ( i < 256 ) { if ( ( a [ i ] == 0 && b [ i ] == 0 ) || ( a [ i ] != 0 && b [ i ] != 0 ) ) { i ++ ; } else { return false ; } } sort ( a , a + 256 ) ; sort ( b , b + 256 ) ; for ( int i = 0 ; i < 256 ; i ++ ) { if ( a [ i ] != b [ i ] ) return false ; } return true ; } int main ( ) { string S1 = \\\" cabbba \\\" , S2 = \\\" abbccc \\\" ; if ( sameStrings ( S1 , S2 ) ) cout << \\\" YES \\\" << endl ; else cout << \\\" \u2581 NO \\\" << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Total number of non | javascript program to count non - decreasing numner with n digits ; Compute value of N * ( N + 1 ) \\/ 2 * ( N + 2 ) \\/ 3 * ... . * ( N + n - 1 ) \\/ n ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function countNonDecreasing ( n ) { let N = 10 ; let count = 1 ; for ( let i = 1 ; i <= n ; i ++ ) { count *= ( N + i - 1 ) ; count = Math . floor ( count \\/ i ) ; } return count ; } let n = 3 ; document . write ( countNonDecreasing ( n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if the string contains consecutive letters and each letter occurs exactly once | Python3 program to implement the above approach ; For all the characters of the string ; Find the ascii value of the character ; Check if if its a valid character , if not then return false ; Calculate sum of all the characters ascii values ; Find minimum ascii value from the string ; Find maximum ascii value from the string ; To get the previous element of the minimum ASCII value ; Take the expected sum from the above equation ; Check if the expected sum is equals to the calculated sum or not ; Driver code ; 1 st example ; 2 nd example\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import sys\\ndef check ( str ) :\\n\\tmin = sys . maxsize\\n\\tmax = - sys . maxsize - 1\\n\\tsum = 0\\n\\tfor i in range ( len ( str ) ) :\\n\\t\\tascii = str [ i ]\\n\\t\\tif ( ord ( ascii ) < 96 or ord ( ascii ) > 122 ) :\\n\\t\\t\\treturn False\\n\\t\\tsum += ord ( ascii )\\n\\t\\tif ( min > ord ( ascii ) ) :\\n\\t\\t\\tmin = ord ( ascii )\\n\\t\\tif ( max < ord ( ascii ) ) :\\n\\t\\t\\tmax = ord ( ascii )\\n\\tmin -= 1\\n\\teSum = ( ( ( max * ( max + 1 ) ) \\/\\/ 2 ) - ( ( min * ( min + 1 ) ) \\/\\/ 2 ) )\\n\\treturn sum == eSum\\nif __name__ == ' _ _ main _ _ ' :\\n\\tstr = \\\" dcef \\\"\\n\\tif ( check ( str ) ) :\\n\\t\\tprint ( \\\" Yes \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\\n\\tstr1 = \\\" xyza \\\"\\n\\tif ( check ( str1 ) ) :\\n\\t\\tprint ( \\\" Yes \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if right triangle possible from given area and hypotenuse | C ++ program to check existence of right triangle . ; Prints three sides of a right triangle from given area and hypotenuse if triangle is possible , else prints - 1. ; Descriminant of the equation ; applying the linear equation formula to find both the roots ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void findRightAngle ( int A , int H ) { long D = pow ( H , 4 ) - 16 * A * A ; if ( D >= 0 ) { long root1 = ( H * H + sqrt ( D ) ) \\/ 2 ; long root2 = ( H * H - sqrt ( D ) ) \\/ 2 ; long a = sqrt ( root1 ) ; long b = sqrt ( root2 ) ; if ( b >= a ) cout << a << \\\" \u2581 \\\" << b << \\\" \u2581 \\\" << H ; else cout << b << \\\" \u2581 \\\" << a << \\\" \u2581 \\\" << H ; } else cout << \\\" - 1\\\" ; } int main ( ) { findRightAngle ( 6 , 5 ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find the value of P and modular inverse of Q modulo 998244353 | Java implementation to find the value of P . Q - 1 mod 998244353 ; Function to find the value of P * Q ^ - 1 mod 998244353 ; Loop to find the value until the expo is not zero ; Multiply p with q if expo is odd ; Reduce the value of expo by 2 ; Driver code ; Function call\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static long calculate ( long p , long q ) { long mod = 998244353 , expo ; expo = mod - 2 ; while ( expo != 0 ) { if ( ( expo & 1 ) == 1 ) { p = ( p * q ) % mod ; } q = ( q * q ) % mod ; expo >>= 1 ; } return p ; } public static void main ( String [ ] args ) { long p = 1 , q = 4 ; System . out . println ( calculate ( p , q ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find the number of Chicks in a Zoo at Nth day | Java implementation of the approach ; Function to return the number of chicks on the nth day ; Size of dp [ ] has to be at least 6 ( 1 - based indexing ) ; Every day current population will be three times of the previous day ; Manually calculated value ; From 8 th day onwards ; Chick population decreases by 2 \\/ 3 everyday . For 8 th day on [ i - 6 ] i . e 2 nd day population was 3 and so 2 new born die on the 6 th day and so on for the upcoming days ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; public class GFG { static long getChicks ( int n ) { int size = Math . max ( n , 7 ) ; long [ ] dp = new long [ size ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; for ( int i = 2 ; i < 6 ; i ++ ) { dp [ i ] = dp [ i - 1 ] * 3 ; } dp [ 6 ] = 726 ; for ( int i = 8 ; i <= n ; i ++ ) { dp [ i ] = ( dp [ i - 1 ] - ( 2 * dp [ i - 6 ] \\/ 3 ) ) * 3 ; } return dp [ n ] ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( getChicks ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Average of a stream of numbers | ; Returns the new average after including x ; Prints average of a stream of numbers ; Driver program to test above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\nfloat getAvg ( int x ) { static int sum , n ; sum += x ; return ( ( ( float ) sum ) \\/ ++ n ) ; } void streamAvg ( float arr [ ] , int n ) { float avg = 0 ; for ( int i = 0 ; i < n ; i ++ ) { avg = getAvg ( arr [ i ] ) ; printf ( \\\" Average \u2581 of \u2581 % d \u2581 numbers \u2581 is \u2581 % f \u2581 \\n \\\" , i + 1 , avg ) ; } return ; } int main ( ) { float arr [ ] = { 10 , 20 , 30 , 40 , 50 , 60 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; streamAvg ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum value to be added to X such that it is at least Y percent of N | Function to return the required value that must be added to x so that it is at least y percent of n ; Required value ; If x is already >= y percent of n ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function minValue ( $ n , $ x , $ y ) { $ val = ( $ y * $ n ) \\/ 100 ; if ( $ x >= $ val ) return 0 ; else return ( ceil ( $ val ) - $ x ) ; } { $ n = 10 ; $ x = 2 ; $ y = 40 ; echo ( minValue ( $ n , $ x , $ y ) ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Minimum number of jumps to reach end | C program to find Minimum number of jumps to reach end ; Returns minimum number of jumps to reach arr [ h ] from arr [ l ] ; Base case : when source and destination are same ; When nothing is reachable from the given source ; Traverse through all the points reachable from arr [ l ] . Recursively get the minimum number of jumps needed to reach arr [ h ] from these reachable points . ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nint minJumps ( int arr [ ] , int l , int h ) { if ( h == l ) return 0 ; if ( arr [ l ] == 0 ) return INT_MAX ; int min = INT_MAX ; for ( int i = l + 1 ; i <= h && i <= l + arr [ l ] ; i ++ ) { int jumps = minJumps ( arr , i , h ) ; if ( jumps != INT_MAX && jumps + 1 < min ) min = jumps + 1 ; } return min ; } int main ( ) { int arr [ ] = { 1 , 3 , 6 , 3 , 2 , 3 , 6 , 8 , 9 , 5 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Minimum \u2581 number \u2581 of \u2581 jumps \u2581 to \u2581 reach \u2581 end \u2581 is \u2581 % d \u2581 \\\" , minJumps ( arr , 0 , n - 1 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximum occurrence of prefix in the Array | Java program to find the number of occurrences of prefix which occurs maximum no . of time ; Function to return the count of the required prefix ; Find the frequency of first character of string ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int prefixOccurrences ( String str ) { char c = str . charAt ( 0 ) ; int countc = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == c ) countc ++ ; } return countc ; } public static void main ( String args [ ] ) { String str = \\\" abbcdabbcd \\\" ; System . out . println ( prefixOccurrences ( str ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Rare Numbers | Java implementation to check if N is a Rare number ; Iterative function to reverse digits of num ; Function to check if N is perfect square ; Find floating point value of square root of x . ; If square root is an integer ; Function to check if N is an Rare number ; Find reverse of N ; Number should be non - palindromic ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int reversDigits ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num \\/ 10 ; } return rev_num ; } static boolean isPerfectSquare ( double x ) { double sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } static boolean isRare ( int N ) { int reverseN = reversDigits ( N ) ; if ( reverseN == N ) return false ; return isPerfectSquare ( N + reverseN ) && isPerfectSquare ( N - reverseN ) ; } public static void main ( String [ ] args ) { int n = 65 ; if ( isRare ( n ) ) { System . out . println ( \\\" Yes \\\" ) ; } else { System . out . println ( \\\" No \\\" ) ; } } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Primality Test | Set 5 ( Using Lucas | C ++ program to find out Lucas - Lehmer series . ; Function to find out first n terms ( considering 4 as 0 th term ) of Lucas - Lehmer series . ; the 0 th term of the series is 4. ; create an array to store the terms . ; compute each term and add it to the array . ; print out the terms one by one . ; Driver program\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#include \\nusing namespace std ; void LucasLehmer ( int n ) { unsigned long long current_val = 4 ; vector < unsigned long long > series ; series . push_back ( current_val ) ; for ( int i = 0 ; i < n ; i ++ ) { current_val = current_val * current_val - 2 ; series . push_back ( current_val ) ; } for ( int i = 0 ; i <= n ; i ++ ) cout << \\\" Term \u2581 \\\" << i << \\\" : \u2581 \\\" << series [ i ] << endl ; } int main ( ) { int n = 5 ; LucasLehmer ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Threaded Binary Search Tree | Deletion | Complete Java program to demonstrate deletion in threaded BST ; True if left pointer points to predecessor in Inorder Traversal ; True if right pointer points to predecessor in Inorder Traversal ; Insert a Node in Binary Threaded Tree ; Searching for a Node with given value ; Parent of key to be inserted ; If key already exists , return ; Update parent pointer ; Moving on left subtree . ; Moving on right subtree . ; Create a new Node ; Returns inorder successor using left and right children ( Used in deletion ) ; Returns inorder successor using rthread ( Used in inorder ) ; If rthread is set , we can quickly find ; Else return leftmost child of right subtree ; Printing the threaded tree ; Reach leftmost Node ; One by one print successors ; Here ' par ' is pointer to parent Node and ' ptr ' is pointer to current Node . ; If Node to be deleted is root ; If Node to be deleted is left of its parent ; Here ' par ' is pointer to parent Node and ' ptr ' is pointer to current Node . ; Initialize child Node to be deleted has left child . ; Node to be deleted has right child . ; Node to be deleted is root Node . ; Node is left child of its parent . ; Find successor and predecessor ; If ptr has left subtree . ; If ptr has right subtree . ; Here ' par ' is pointer to parent Node and ' ptr ' is pointer to current Node . ; Find inorder successor and its parent . ; Find leftmost child of successor ; Deletes a key from threaded BST with given root and returns new root of BST . ; Initialize parent as null and ptrent Node as root . ; Set true if key is found ; Search key in BST : find Node and its parent . ; Two Children ; Only Left Child ; Only Right Child ; No child ; Driver Program\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class solution { static class Node { Node left , right ; int info ; boolean lthread ; boolean rthread ; } ; static Node insert ( Node root , int ikey ) { Node ptr = root ; Node par = null ; while ( ptr != null ) { if ( ikey == ( ptr . info ) ) { System . out . printf ( \\\"Duplicate Key !\\n\\\"); return root ; } par = ptr ; if ( ikey < ptr . info ) { if ( ptr . lthread == false ) ptr = ptr . left ; else break ; } else { if ( ptr . rthread == false ) ptr = ptr . right ; else break ; } } Node tmp = new Node ( ) ; tmp . info = ikey ; tmp . lthread = true ; tmp . rthread = true ; if ( par == null ) { root = tmp ; tmp . left = null ; tmp . right = null ; } else if ( ikey < ( par . info ) ) { tmp . left = par . left ; tmp . right = par ; par . lthread = false ; par . left = tmp ; } else { tmp . left = par ; tmp . right = par . right ; par . rthread = false ; par . right = tmp ; } return root ; } static Node inSucc ( Node ptr ) { if ( ptr . rthread == true ) return ptr . right ; ptr = ptr . right ; while ( ptr . lthread == false ) ptr = ptr . left ; return ptr ; } static Node inorderSuccessor ( Node ptr ) { if ( ptr . rthread == true ) return ptr . right ; ptr = ptr . right ; while ( ptr . lthread == false ) ptr = ptr . left ; return ptr ; } static void inorder ( Node root ) { if ( root == null ) System . out . printf ( \\\" Tree \u2581 is \u2581 empty \\\" ) ; Node ptr = root ; while ( ptr . lthread == false ) ptr = ptr . left ; while ( ptr != null ) { System . out . printf ( \\\" % d \u2581 \\\" , ptr . info ) ; ptr = inorderSuccessor ( ptr ) ; } } static Node inPred ( Node ptr ) { if ( ptr . lthread == true ) return ptr . left ; ptr = ptr . left ; while ( ptr . rthread == false ) ptr = ptr . right ; return ptr ; } static Node caseA ( Node root , Node par , Node ptr ) { if ( par == null ) root = null ; else if ( ptr == par . left ) { par . lthread = true ; par . left = ptr . left ; } else { par . rthread = true ; par . right = ptr . right ; } return root ; } static Node caseB ( Node root , Node par , Node ptr ) { Node...\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count all disjoint pairs having absolute difference at least K from a given array | Function to check if it is possible to form M pairs with abs diff at least K ; Traverse the array over [ 0 , M ] ; If valid index ; Return 1 ; Function to count distinct pairs with absolute difference atleasr K ; Stores the count of all possible pairs ; Initialize left and right ; Sort the array ; Perform Binary Search ; Find the value of mid ; Check valid index ; Update ans ; Prvar the answer ; Given array arr ; Given difference K ; Size of the array ; Function call\\\"\\nSolution in Javascript:\",\"targets\":\"function isValid ( arr , n , m , d ) { for ( i = 0 ; i < m ; i ++ ) { if ( Math . abs ( arr [ n - m + i ] - arr [ i ] ) < d ) { return 0 ; } } return 1 ; } function countPairs ( arr , N , K ) { var ans = 0 ; var left = 0 , right = N \\/ 2 + 1 ; arr . sort ( ) ; while ( left < right ) { var mid = parseInt ( ( left + right ) \\/ 2 ) ; if ( isValid ( arr , N , mid , K ) == 1 ) { ans = mid ; left = mid + 1 ; } else right = mid - 1 ; } document . write ( ans ) ; } var arr = [ 1 , 3 , 3 , 5 ] ; var K = 2 ; var N = arr . length ; countPairs ( arr , N , K ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum cells to be flipped to get a 2 * 2 submatrix with equal elements | Python 3 implementation of the approach ; Function to return the minimum flips required such that the submatrix from mat [ i ] [ j ] to mat [ i + 1 ] [ j + 1 ] contains all equal elements ; Function to return the minimum number of slips required such that the matrix contains at least a single submatrix of size 2 * 2 with all equal elements ; To store the result ; For every submatrix of size 2 * 2 ; Update the count of flips required for the current submatrix ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import sys\\ndef minFlipsSub ( mat , i , j ) :\\n\\tcnt0 = 0\\n\\tcnt1 = 0\\n\\tif ( mat [ i ] [ j ] == '1' ) :\\n\\t\\tcnt1 += 1\\n\\telse :\\n\\t\\tcnt0 += 1\\n\\tif ( mat [ i ] [ j + 1 ] == '1' ) :\\n\\t\\tcnt1 += 1\\n\\telse :\\n\\t\\tcnt0 += 1\\n\\tif ( mat [ i + 1 ] [ j ] == '1' ) :\\n\\t\\tcnt1 += 1\\n\\telse :\\n\\t\\tcnt0 += 1\\n\\tif ( mat [ i + 1 ] [ j + 1 ] == '1' ) :\\n\\t\\tcnt1 += 1\\n\\telse :\\n\\t\\tcnt0 += 1\\n\\treturn min ( cnt0 , cnt1 )\\ndef minFlips ( mat , r , c ) :\\n\\tres = sys . maxsize\\n\\tfor i in range ( r - 1 ) :\\n\\t\\tfor j in range ( c - 1 ) :\\n\\t\\t\\tres = min ( res , minFlipsSub ( mat , i , j ) )\\n\\treturn res\\nif __name__ == ' _ _ main _ _ ' :\\n\\tmat = [ \\\"0101\\\" , \\\"0101\\\" , \\\"0101\\\" ]\\n\\tr = len ( mat )\\n\\tc = len ( mat [ 0 ] )\\n\\tprint ( minFlips ( mat , r , c ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"Sudoku | Backtracking | ; N is the size of the 2D matrix N * N ; A utility function to print grid ; Checks whether it will be legal to assign num to the given row , col ; Check if we find the same num in the similar row , we return 0 ; Check if we find the same num in the similar column , we return 0 ; Check if we find the same num in the particular 3 * 3 matrix , we return 0 ; Takes a partially filled - in grid and attempts to assign values to all unassigned locations in such a way to meet the requirements for Sudoku solution ( non - duplication across rows , columns , and boxes ) ; Check if we have reached the 8 th row and 9 th column ( 0 indexed matrix ) , we are returning true to avoid further backtracking ; Check if column value becomes 9 , we move to next row and column start from 0 ; Check if the current position of the grid already contains value > 0 , we iterate for next column ; Check if it is safe to place the num ( 1 - 9 ) in the given row , col -> we move to next column ; assigning the num in the current ( row , col ) position of the grid and assuming our assigned num in the position is correct ; Checking for next possibility with next column ; Removing the assigned num , since our assumption was wrong , and we go for next assumption with diff num value ; 0 means unassigned cells\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\n#define N 9\\nvoid print ( int arr [ N ] [ N ] ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) printf ( \\\" % d \u2581 \\\" , arr [ i ] [ j ] ) ; printf ( \\\" \\n \\\" ) ; } } int isSafe ( int grid [ N ] [ N ] , int row , int col , int num ) { for ( int x = 0 ; x <= 8 ; x ++ ) if ( grid [ row ] [ x ] == num ) return 0 ; for ( int x = 0 ; x <= 8 ; x ++ ) if ( grid [ x ] [ col ] == num ) return 0 ; int startRow = row - row % 3 , startCol = col - col % 3 ; for ( int i = 0 ; i < 3 ; i ++ ) for ( int j = 0 ; j < 3 ; j ++ ) if ( grid [ i + startRow ] [ j + startCol ] == num ) return 0 ; return 1 ; } int solveSuduko ( int grid [ N ] [ N ] , int row , int col ) { if ( row == N - 1 && col == N ) return 1 ; if ( col == N ) { row ++ ; col = 0 ; } if ( grid [ row ] [ col ] > 0 ) return solveSuduko ( grid , row , col + 1 ) ; for ( int num = 1 ; num <= N ; num ++ ) { if ( isSafe ( grid , row , col , num ) == 1 ) { grid [ row ] [ col ] = num ; if ( solveSuduko ( grid , row , col + 1 ) == 1 ) return 1 ; } grid [ row ] [ col ] = 0 ; } return 0 ; } int main ( ) { int grid [ N ] [ N ] = { { 3 , 0 , 6 , 5 , 0 , 8 , 4 , 0 , 0 } , { 5 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 8 , 7 , 0 , 0 , 0 , 0 , 3 , 1 } , { 0 , 0 , 3 , 0 , 1 , 0 , 0 , 8 , 0 } , { 9 , 0 , 0 , 8 , 6 , 3 , 0 , 0 , 5 } , { 0 , 5 , 0 , 0 , 9 , 0 , 6 , 0 , 0 } , { 1 , 3 , 0 , 0 , 0 , 0 , 2 , 5 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 4 } , { 0 , 0 , 5 , 2 , 0 , 6 , 3 , 0 , 0 } } ; if ( solveSuduko ( grid , 0 , 0 ) == 1 ) print ( grid ) ; else printf ( \\\" No \u2581 solution \u2581 exists \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if the given number is Ore number or not | Python3 program to check if the given number is Ore number ; Function that returns harmonic mean ; Note that this loop runs till square root ; If divisors are equal , store 'i ; Otherwise store ' i ' and ' n \\/ i ' both ; Utility function to calculate harmonic mean of the divisors ; Declare sum variables and initialize with zero . ; calculate denominator ; Calculate harmonic mean and return ; Function to check if a number is ore number ; Calculate Harmonic mean of divisors of n ; Check if harmonic mean is an integer or not ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"arr = [ ]\\ndef generateDivisors ( n ) :\\n\\tfor i in range ( 1 , int ( n ** ( 0.5 ) ) + 1 ) :\\n\\t\\tif n % i == 0 :\\n'\\n\\tif n \\/\\/ i == i :\\n\\t\\tarr . append ( i )\\n\\telse :\\n\\t\\tarr . append ( i )\\n\\t\\tarr . append ( n \\/\\/ i )\\ndef harmonicMean ( n ) :\\n\\tgenerateDivisors ( n )\\n\\tSum = 0\\n\\tlength = len ( arr )\\n\\tfor i in range ( 0 , length ) :\\n\\t\\tSum = Sum + ( n \\/ arr [ i ] )\\n\\tSum = Sum \\/ n\\n\\treturn length \\/ Sum\\ndef isOreNumber ( n ) :\\n\\tmean = harmonicMean ( n )\\n\\tif mean - int ( mean ) == 0 :\\n\\t\\treturn True\\n\\telse :\\n\\t\\treturn False\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tn = 28\\n\\tif isOreNumber ( n ) == True :\\n\\t\\tprint ( \\\" YES \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" NO \\\" )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if a number is prime in Flipped Upside Down , Mirror Flipped and Mirror Flipped Upside Down | C ++ program to implement the above approach ; Function to check if N contains digits 0 , 1 , 2 , 5 , 8 only ; Extract digits of N ; Return false if any of these digits are present ; Function to check if N is prime or not ; Check for all factors ; Function to check if n is prime in all the desired forms ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool checkDigits ( int n ) { do { int r = n % 10 ; if ( r == 3 r == 4 r == 6 r == 7 r == 9 ) return false ; n \\/= 10 ; } while ( n != 0 ) ; return true ; } bool isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } int isAllPrime ( int n ) { return isPrime ( n ) && checkDigits ( n ) ; } int main ( ) { int N = 101 ; if ( isAllPrime ( N ) ) cout << \\\" Yes \\\" ; else cout << \\\" No \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Reverse Level Order Traversal | A recursive C program to print REVERSE level order traversal ; A binary tree node has data , pointer to left and right child ; Function protoypes ; Function to print REVERSE level order traversal a tree ; Print nodes at a given level ; Compute the \\\" height \\\" of a tree -- the number of nodes along the longest path from the root node down to the farthest leaf node . ; compute the height of each subtree ; use the larger one ; Helper function that allocates a new node with the given data and NULL left and right pointers . ; Driver program to test above functions ; Let us create trees shown in above diagram\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nstruct node { int data ; struct node * left ; struct node * right ; } ; void printGivenLevel ( struct node * root , int level ) ; int height ( struct node * node ) ; struct node * newNode ( int data ) ; void reverseLevelOrder ( struct node * root ) { int h = height ( root ) ; int i ; for ( i = h ; i >= 1 ; i -- ) printGivenLevel ( root , i ) ; } void printGivenLevel ( struct node * root , int level ) { if ( root == NULL ) return ; if ( level == 1 ) printf ( \\\" % d \u2581 \\\" , root -> data ) ; else if ( level > 1 ) { printGivenLevel ( root -> left , level - 1 ) ; printGivenLevel ( root -> right , level - 1 ) ; } } int height ( struct node * node ) { if ( node == NULL ) return 0 ; else { int lheight = height ( node -> left ) ; int rheight = height ( node -> right ) ; if ( lheight > rheight ) return ( lheight + 1 ) ; else return ( rheight + 1 ) ; } } struct node * newNode ( int data ) { struct node * node = ( struct node * ) malloc ( sizeof ( struct node ) ) ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } int main ( ) { struct node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; printf ( \\\" Level \u2581 Order \u2581 traversal \u2581 of \u2581 binary \u2581 tree \u2581 is \u2581 \\n \\\" ) ; reverseLevelOrder ( root ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Pell Number | calculate nth pell number ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function pell ( $ n ) { if ( $ n <= 2 ) return $ n ; $ a = 1 ; $ b = 2 ; $ c ; $ i ; for ( $ i = 3 ; $ i <= $ n ; $ i ++ ) { $ c = 2 * $ b + $ a ; $ a = $ b ; $ b = $ c ; } return $ b ; } $ n = 4 ; echo ( pell ( $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum operations to make all elements equal using the second array | C ++ implementation to find the minimum operations make all elements equal using the second array ; Function to find the minimum operations required to make all elements of the array equal ; Minimum element of A [ ] ; Traverse through all final values ; Variable indicating whether all elements can be converted to x or not ; Total operations ; Traverse through all array elements ; All elements can 't be converted to x ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int minOperations ( int a [ ] , int b [ ] , int n ) { int minA = * min_element ( a , a + n ) ; for ( int x = minA ; x >= 0 ; x -- ) { bool check = 1 ; int operations = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( x % b [ i ] == a [ i ] % b [ i ] ) { operations += ( a [ i ] - x ) \\/ b [ i ] ; } else { check = 0 ; break ; } } if ( check ) return operations ; } return -1 ; } int main ( ) { int N = 5 ; int A [ N ] = { 5 , 7 , 10 , 5 , 15 } ; int B [ N ] = { 2 , 2 , 1 , 3 , 5 } ; cout << minOperations ( A , B , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Delete odd and even numbers at alternate step such that sum of remaining elements is minimized | Java implementation of the approach ; Function to find the minimized sum ; If more odd elements ; Sort the elements ; Left - over elements ; Find the sum of leftover elements ; Return the sum ; If more even elements ; Sort the elements ; Left - over elements ; Find the sum of leftover elements ; Return the sum ; If same elements ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static int MinimizeleftOverSum ( int a [ ] , int n ) { Vector < Integer > v1 = new Vector < Integer > ( ) , v2 = new Vector < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 1 ) v1 . add ( a [ i ] ) ; else v2 . add ( a [ i ] ) ; } if ( v1 . size ( ) > v2 . size ( ) ) { Collections . sort ( v1 ) ; Collections . sort ( v2 ) ; int x = v1 . size ( ) - v2 . size ( ) - 1 ; int sum = 0 ; int i = 0 ; while ( i < x ) { sum += v1 . get ( i ++ ) ; } return sum ; } else if ( v2 . size ( ) > v1 . size ( ) ) { Collections . sort ( v1 ) ; Collections . sort ( v2 ) ; int x = v2 . size ( ) - v1 . size ( ) - 1 ; int sum = 0 ; int i = 0 ; while ( i < x ) { sum += v2 . get ( i ++ ) ; } return sum ; } else return 0 ; } public static void main ( String [ ] args ) { int a [ ] = { 2 , 2 , 2 , 2 } ; int n = a . length ; System . out . println ( MinimizeleftOverSum ( a , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count number of common elements between a sorted array and a reverse sorted array | C ++ program for the above approach ; Function to count the number of elements common in both the arrays ; Used to traverse array A [ ] and B [ ] from the front and the back ; Stores the count of numbers common in both array ; If A [ first ] is less than B [ second ] ; Increment the value of first ; IF B [ second ] is less than A [ first ] ; Decrement the value of second ; A [ first ] is equal to B [ second ] ; Increment the value of count ; Increment the value of first ; Decrement the value of second ; Return the value of count ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int countEqual ( int A [ ] , int B [ ] , int N ) { int first = 0 ; int second = N - 1 ; int count = 0 ; while ( first < N && second >= 0 ) { if ( A [ first ] < B [ second ] ) { first ++ ; } else if ( B [ second ] < A [ first ] ) { second -- ; } else { count ++ ; first ++ ; second -- ; } } return count ; } int main ( ) { int A [ ] = { 2 , 4 , 5 , 8 , 12 , 13 , 17 , 18 , 20 , 22 , 309 , 999 } ; int B [ ] = { 109 , 99 , 68 , 54 , 22 , 19 , 17 , 13 , 11 , 5 , 3 , 1 } ; int N = sizeof ( A ) \\/ sizeof ( int ) ; cout << countEqual ( A , B , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Check for Majority Element in a sorted array | C Program to check for majority element in a sorted array ; If x is present in arr [ low ... high ] then returns the index of first occurrence of x , otherwise returns - 1 ; Check if arr [ mid ] is the first occurrence of x . arr [ mid ] is first occurrence if x is one of the following is true : ( i ) mid == 0 and arr [ mid ] = = x ( ii ) arr [ mid - 1 ] < x and arr [ mid ] == x ; This function returns true if the x is present more than n \\/ 2 times in arr [ ] of size n ; Find the index of first occurrence of x in arr [ ] ; If element is not present at all , return false ; check if the element is present more than n \\/ 2 times ; Driver program to check above functions\\nHow can the above be solved in C?\",\"targets\":\"# include \\n# include \\nint _binarySearch ( int arr [ ] , int low , int high , int x ) { if ( high >= low ) { int mid = ( low + high ) \\/ 2 ; if ( ( mid == 0 x > arr [ mid - 1 ] ) && ( arr [ mid ] == x ) ) return mid ; else if ( x > arr [ mid ] ) return _binarySearch ( arr , ( mid + 1 ) , high , x ) ; else return _binarySearch ( arr , low , ( mid - 1 ) , x ) ; } return -1 ; } bool isMajority ( int arr [ ] , int n , int x ) { int i = _binarySearch ( arr , 0 , n - 1 , x ) ; if ( i == -1 ) return false ; if ( ( ( i + n \\/ 2 ) <= ( n - 1 ) ) && arr [ i + n \\/ 2 ] == x ) return true ; else return false ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 3 , 3 , 3 , 10 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int x = 3 ; if ( isMajority ( arr , n , x ) ) printf ( \\\" % d \u2581 appears \u2581 more \u2581 than \u2581 % d \u2581 times \u2581 in \u2581 arr [ ] \\\" , x , n \\/ 2 ) ; else printf ( \\\" % d \u2581 does \u2581 not \u2581 appear \u2581 more \u2581 than \u2581 % d \u2581 times \u2581 in \u2581 arr [ ] \\\" , x , n \\/ 2 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Average of even numbers till a given even number | Function to calculate the average of even numbers ; count even numbers ; store the sum of even numbers ; driver function\\\"\\nSolution in Python:\",\"targets\":\"def averageEven ( n ) :\\n\\tif ( n % 2 != 0 ) :\\n\\t\\tprint ( \\\" Invalid \u2581 Input \\\" )\\n\\t\\treturn - 1\\n\\tsm = 0\\n\\tcount = 0\\n\\twhile ( n >= 2 ) :\\n\\t\\tcount = count + 1\\n\\t\\tsm = sm + n\\n\\t\\tn = n - 2\\n\\treturn sm \\/\\/ count\\nn = 16\\nprint ( averageEven ( n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"Check if array contains contiguous integers with duplicates allowed | Sorting based C ++ implementation to check whether the array contains a set of contiguous integers ; function to check whether the array contains a set of contiguous integers ; Sort the array ; After sorting , check if current element is either same as previous or is one more . ; Driver program to test above\\nHow can the above be solved in C?\",\"targets\":\"#include \\nusing namespace std ; bool areElementsContiguous ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] - arr [ i - 1 ] > 1 ) return false ; return true ; } int main ( ) { int arr [ ] = { 5 , 2 , 3 , 6 , 4 , 4 , 6 , 6 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; if ( areElementsContiguous ( arr , n ) ) cout << \\\" Yes \\\" ; else cout << \\\" No \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Sum of products of all combination taken ( 1 to n ) at a time | to store sum of every combination ; if we have reached sufficient depth ; find the product of combination ; add the product into sum ; recursion to produce different combination ; function to print sum of products of all combination taken 1 - N at a time ; creating temporary array for storing combination ; call combination with r = i for combination taken i at a time ; displaying sum ; Driver Code ; storing numbers from 1 - N in array ; calling allCombination\\\"\\nSolution in Python:\",\"targets\":\"def Combination ( a , combi , n , r , depth , index ) :\\n\\tglobal Sum\\n\\tif index == r :\\n\\t\\tproduct = 1\\n\\t\\tfor i in range ( r ) :\\n\\t\\t\\tproduct = product * combi [ i ]\\n\\t\\tSum += product\\n\\t\\treturn\\n\\tfor i in range ( depth , n ) :\\n\\t\\tcombi [ index ] = a [ i ]\\n\\t\\tCombination ( a , combi , n , r , i + 1 , index + 1 )\\ndef allCombination ( a , n ) :\\n\\tglobal Sum\\n\\tfor i in range ( 1 , n + 1 ) :\\n\\t\\tcombi = [ 0 ] * i\\n\\t\\tCombination ( a , combi , n , i , 0 , 0 )\\n\\t\\tprint ( \\\" f ( \\\" , i , \\\" ) \u2581 - - > \u2581 \\\" , Sum )\\n\\t\\tSum = 0\\nSum = 0\\nn = 5\\na = [ 0 ] * n\\nfor i in range ( n ) :\\n\\ta [ i ] = i + 1\\nallCombination ( a , n )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"k | C # program to find k - th absolute difference between two elements ; returns number of pairs with absolute difference less than or equal to mid ; Upper bound returns pointer to position of next higher number than a [ i ] + mid in a [ i . . n - 1 ] . We subtract ( ub + i + 1 ) from this position to count ; returns the upper bound ; Returns k - th absolute difference ; Sort array ; Minimum absolute difference ; Maximum absolute difference ; Do binary search for k - th absolute difference ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int countPairs ( int [ ] a , int n , int mid ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int ub = upperbound ( a , n , a [ i ] + mid ) ; res += ( ub - ( i - 1 ) ) ; } return res ; } static int upperbound ( int [ ] a , int n , int value ) { int low = 0 ; int high = n ; while ( low < high ) { int mid = ( low + high ) \\/ 2 ; if ( value >= a [ mid ] ) low = mid + 1 ; else high = mid ; } return low ; } static int kthDiff ( int [ ] a , int n , int k ) { Array . Sort ( a ) ; int low = a [ 1 ] - a [ 0 ] ; for ( int i = 1 ; i <= n - 2 ; ++ i ) low = Math . Min ( low , a [ i + 1 ] - a [ i ] ) ; int high = a [ n - 1 ] - a [ 0 ] ; while ( low < high ) { int mid = ( low + high ) >> 1 ; if ( countPairs ( a , n , mid ) < k ) low = mid + 1 ; else high = mid ; } return low ; } public static void Main ( String [ ] args ) { int k = 3 ; int [ ] a = { 1 , 2 , 3 , 4 } ; int n = a . Length ; Console . WriteLine ( kthDiff ( a , n , k ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count of subarrays having sum equal to its length | Set 2 | Function that counts the subarrays with sum of its elements as its length ; Store count of elements upto current element with length i ; Stores the final count of subarray ; Stores the prefix sum ; If size of subarray is 1 ; Iterate the array ; Find the sum ; Update frequency in map ; Print the total count ; Given array arr [ ] ; Size of array ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function countOfSubarray ( arr , N ) { var mp = new Map ( ) ; var answer = 0 ; var sum = 0 ; if ( ! mp . has ( 1 ) ) mp . set ( 1 , 1 ) else mp . set ( 1 , mp . get ( 1 ) + 1 ) for ( var i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; answer += mp . has ( sum - i ) ? mp . get ( sum - i ) : 0 ; if ( mp . has ( sum - i ) ) mp . set ( sum - i , mp . get ( sum - i ) + 1 ) else mp . set ( sum - i , 1 ) } document . write ( answer ) ; } var arr = [ 1 , 0 , 2 , 1 , 2 , - 2 , 2 , 4 ] ; var N = arr . length ; countOfSubarray ( arr , N ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of increment \\/ decrement operations such that array contains all elements from 1 to N | C # implementation of the above approach ; Function to find the minimum operations ; Sort the given array ; Count operations by assigning a [ i ] = i + 1 ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static long minimumMoves ( int [ ] a , int n ) { long operations = 0 ; Array . Sort ( a ) ; for ( int i = 0 ; i < n ; i ++ ) operations += ( long ) Math . Abs ( a [ i ] - ( i + 1 ) ) ; return operations ; } static public void Main ( ) { int [ ] arr = { 5 , 3 , 2 } ; int n = arr . Length ; Console . WriteLine ( minimumMoves ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Largest palindromic number in an array | Function to check if n is palindrome ; Find the appropriate divisor to extract the leading digit ; If first and last digits are not same then return false ; Removing the leading and trailing digits from the number ; Reducing divisor by a factor of 2 as 2 digits are dropped ; Function to find the largest palindromic number ; Sort the array ; If number is palindrome ; If no palindromic number found ; Driver Code ; print required answer\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def isPalindrome ( n ) :\\n\\tdivisor = 1\\n\\twhile ( n \\/ divisor >= 10 ) :\\n\\t\\tdivisor *= 10\\n\\twhile ( n != 0 ) :\\n\\t\\tleading = n \\/\\/ divisor\\n\\t\\ttrailing = n % 10\\n\\t\\tif ( leading != trailing ) :\\n\\t\\t\\treturn False\\n\\t\\tn = ( n % divisor ) \\/\\/ 10\\n\\t\\tdivisor = divisor \\/\\/ 100\\n\\treturn True\\ndef largestPalindrome ( A , n ) :\\n\\tA . sort ( )\\n\\tfor i in range ( n - 1 , - 1 , - 1 ) :\\n\\t\\tif ( isPalindrome ( A [ i ] ) ) :\\n\\t\\t\\treturn A [ i ]\\n\\treturn - 1\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tA = [ 1 , 232 , 54545 , 999991 ]\\n\\tn = len ( A )\\n\\tprint ( largestPalindrome ( A , n ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimize swaps of same | C ++ program for the above approach ; Function to count the number of swaps required to make the sum of ASCII values of the characters of both strings odd ; Initialize alphabets with value ; Initialize values for each alphabet ; Size of the string ; Sum of string S ; Sum of string T ; Stores whether there is any index i such that S [ i ] and T [ i ] have different parities ; Traverse the strings ; Update sum1 and sum2 ; If S [ i ] and T [ i ] have different parities ; If sum1 and sum2 are both odd ; If sum1 and sum2 are both even ; If exists print 1 ; Otherwise ; If sum1 and sum2 are of different parities ; Driver Code ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void countSwaps ( string S , string T ) { int value [ 26 ] ; for ( int i = 0 ; i < 26 ; i ++ ) value [ i ] = i + 1 ; int N = S . size ( ) ; int sum1 = 0 ; int sum2 = 0 ; bool flag = false ; for ( int i = 0 ; i < N ; i ++ ) { sum1 += value [ S [ i ] - ' a ' ] ; sum2 += value [ T [ i ] - ' a ' ] ; if ( ( value [ S [ i ] - ' a ' ] % 2 == 0 && value [ T [ i ] - ' a ' ] % 2 == 1 ) || ( value [ S [ i ] - ' a ' ] % 2 == 1 && value [ T [ i ] - ' a ' ] % 2 == 0 ) ) flag = false ; } if ( sum1 % 2 == 1 && sum2 % 2 == 1 ) cout << \\\"0 \\n \\\" ; else if ( sum1 % 2 == 0 && sum2 % 2 == 0 ) { if ( flag ) cout << \\\"1\\\" ; else cout << \\\" - 1\\\" ; } else { cout << \\\" - 1\\\" ; } } int main ( ) { string S = \\\" acd \\\" ; string T = \\\" dbf \\\" ; countSwaps ( S , T ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check whether a point exists in circle sector or not . | Python3 program to check if a point lies inside a circle sector . ; calculate endAngle ; Calculate polar co - ordinates ; Check whether polarradius is less then radius of circle or not and Angle is between startAngle and endAngle or not ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import math\\ndef checkPoint ( radius , x , y , percent , startAngle ) :\\n\\tendAngle = 360 \\/ percent + startAngle\\n\\tpolarradius = math . sqrt ( x * x + y * y )\\n\\tAngle = math . atan ( y \\/ x )\\n\\tif ( Angle >= startAngle and Angle <= endAngle and polarradius < radius ) :\\n\\t\\tprint ( \\\" Point \u2581 ( \\\" , x , \\\" , \\\" , y , \\\" ) \u2581 \\\" \\\" exist \u2581 in \u2581 the \u2581 circle \u2581 sector \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" Point \u2581 ( \\\" , x , \\\" , \\\" , y , \\\" ) \u2581 \\\" \\\" does \u2581 not \u2581 exist \u2581 in \u2581 the \u2581 circle \u2581 sector \\\" )\\nradius , x , y = 8 , 3 , 4\\npercent , startAngle = 12 , 0\\ncheckPoint ( radius , x , y , percent , startAngle )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"All about Bit Manipulation | Function to clear the ith bit of the given number N ; Create the mask for the ith bit unset ; Return the update value\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def clearBit ( num , i ) :\\n\\tmask = ~ ( 1 << i )\\n\\treturn num & mask\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count of integers of length N and value less than K such that they contain digits only from the given set | Java implementation of the approach ; Function to convert a number into vector ; Push all the digits of N from the end one by one to the vector ; If the original number was 0 ; Reverse the vector elements ; Return the required vector ; Function to return the count of B length integers which are less than C and they contain digits from set A [ ] only ; Convert number to digit array ; Case 1 : No such number possible as the generated numbers will always be greater than C ; Case 2 : All integers of length B are valid as they all are less than C ; contain 0 ; Case 3 ; Update the lower [ ] array such that lower [ i ] stores the count of elements in A [ ] which are less than i ; For first index we can 't use 0 ; Whether ( i - 1 ) digit of generated number can be equal to ( i - 1 ) digit of C ; Is digit [ i - 1 ] present in A ? ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static int MAX = 10 ; static Vector < Integer > numToVec ( int N ) { Vector < Integer > digit = new Vector < Integer > ( ) ; while ( N != 0 ) { digit . add ( N % 10 ) ; N = N \\/ 10 ; } if ( digit . size ( ) == 0 ) digit . add ( 0 ) ; Collections . reverse ( digit ) ; return digit ; } static int solve ( Vector < Integer > A , int B , int C ) { Vector < Integer > digit = new Vector < Integer > ( ) ; int d , d2 ; digit = numToVec ( C ) ; d = A . size ( ) ; if ( B > digit . size ( ) d == 0 ) return 0 ; else if ( B < digit . size ( ) ) { if ( A . get ( 0 ) == 0 && B != 1 ) return ( int ) ( ( d - 1 ) * Math . pow ( d , B - 1 ) ) ; else return ( int ) Math . pow ( d , B ) ; } else { int [ ] dp = new int [ B + 1 ] ; int [ ] lower = new int [ MAX + 1 ] ; for ( int i = 0 ; i < d ; i ++ ) lower [ A . get ( i ) + 1 ] = 1 ; for ( int i = 1 ; i <= MAX ; i ++ ) lower [ i ] = lower [ i - 1 ] + lower [ i ] ; boolean flag = true ; dp [ 0 ] = 0 ; for ( int i = 1 ; i <= B ; i ++ ) { d2 = lower [ digit . get ( i - 1 ) ] ; dp [ i ] = dp [ i - 1 ] * d ; if ( i == 1 && A . get ( 0 ) == 0 && B != 1 ) d2 = d2 - 1 ; if ( flag ) dp [ i ] += d2 ; flag = ( flag & ( lower [ digit . get ( i - 1 ) + 1 ] == lower [ digit . get ( i - 1 ) ] + 1 ) ) ; } return dp [ B ] ; } } public static void main ( String [ ] args ) { Integer arr [ ] = { 0 , 1 , 2 , 5 } ; Vector < Integer > A = new Vector < > ( Arrays . asList ( arr ) ) ; int N = 2 ; int k = 21 ; System . out . println ( solve ( A , N , k ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Majority Element | Program for finding out majority element in an array ; Function to find the candidate for Majority ; Function to check if the candidate occurs more than n \\/ 2 * times ; Function to print Majority Element ; Find the candidate for Majority ; Print the candidate if it is Majority ; Driver code ; Function call\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#define bool int\\nint findCandidate ( int * , int ) ; bool isMajority ( int * , int , int ) ; int findCandidate ( int a [ ] , int size ) { int maj_index = 0 , count = 1 ; int i ; for ( i = 1 ; i < size ; i ++ ) { if ( a [ maj_index ] == a [ i ] ) count ++ ; else count -- ; if ( count == 0 ) { maj_index = i ; count = 1 ; } } return a [ maj_index ] ; } bool isMajority ( int a [ ] , int size , int cand ) { int i , count = 0 ; for ( i = 0 ; i < size ; i ++ ) if ( a [ i ] == cand ) count ++ ; if ( count > size \\/ 2 ) return 1 ; else return 0 ; } void printMajority ( int a [ ] , int size ) { int cand = findCandidate ( a , size ) ; if ( isMajority ( a , size , cand ) ) printf ( \\\" \u2581 % d \u2581 \\\" , cand ) ; else printf ( \\\" No \u2581 Majority \u2581 Element \\\" ) ; } int main ( ) { int a [ ] = { 1 , 3 , 3 , 1 , 2 } ; int size = ( sizeof ( a ) ) \\/ sizeof ( a [ 0 ] ) ; printMajority ( a , size ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Volume of largest right circular cylinder within a Sphere | Python 3 Program to find the biggest right circular cylinder that can be fit within a sphere ; Function to find the biggest right circular cylinder ; radius cannot be negative ; volume of cylinder ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"import math\\ndef cyl ( R ) :\\n\\tif ( R < 0 ) :\\n\\t\\treturn - 1\\n\\tV = ( ( 2 * 3.14 * math . pow ( R , 3 ) ) \\/ ( 3 * math . sqrt ( 3 ) ) ) ;\\n\\treturn float ( V )\\nR = 4\\nprint ( cyl ( R ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if a number is an Unusual Number or not | Python Program to check Unusual number ; Utility function to find largest prime factor of a number ; Initialize the maximum prime factor variable with the lowest one ; Print the number of 2 s that divide n ; n must be odd at this point , thus skip the even numbers and iterate only for odd integers ; This condition is to handle the case when n is a prime number greater than 2 ; Function to check Unusual number ; Get the largest Prime Factor of the number ; Check if largest prime factor is greater than sqrt ( n ) ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"from math import sqrt\\ndef largestPrimeFactor ( n ) :\\n\\tmax = - 1\\n\\twhile n % 2 == 0 :\\n\\t\\tmax = 2 ;\\n\\tfor i in range ( 3 , int ( sqrt ( n ) ) + 1 , 2 ) :\\n\\t\\twhile n % i == 0 :\\n\\t\\t\\tmax = i ;\\n\\t\\t\\tn = n \\/ i ;\\n\\tif n > 2 :\\n\\t\\tmax = n\\n\\treturn max\\ndef checkUnusual ( n ) :\\n\\tfactor = largestPrimeFactor ( n )\\n\\tif factor > sqrt ( n ) :\\n\\t\\treturn True\\n\\telse :\\n\\t\\treturn False\\nif __name__ == ' _ _ main _ _ ' :\\n\\tn = 14\\n\\tif checkUnusual ( n ) :\\n\\t\\tprint ( \\\" YES \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" NO \\\" )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Smallest string obtained by removing all occurrences of 01 and 11 from Binary String | Set 2 | Function to find the length of the smallest string possible by removing substrings \\\"01\\\" and \\\"11\\\" ; Stores the length of the smallest string ; Traverse the string S ; If st is greater than 0 and S [ i ] is '1' ; Delete the last character and decrement st by 1 ; Otherwise ; Increment st by 1 ; Return the answer in st ; Input ; Function call\\\"\\nSolution in Javascript:\",\"targets\":\"function shortestString ( S , N ) { let st = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( st > 0 && S [ i ] == ' ' ) { st -- ; } else { st ++ ; } } return st ; } let S = \\\" \\\" ; let N = S . length ; document . write ( shortestString ( S , N ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum count of numbers required with unit digit X that sums up to N | Function to calculate and return the minimum number of times a number with unit digit X needs to be added to get a sum N ; Calculate the number of additions required to get unit digit of N ; If unit digit of N cannot be obtained ; Function to return the minimum number required to represent N ; Stores unit digit of N ; Stores minimum addition of X required to obtain unit digit of N ; If unit digit of N cannot be obtained ; Otherwise ; If N is greater than or equal to ( X * times ) ; Minimum count of numbers that needed to represent N ; Representation not possible ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function check ( unit_digit , X ) { let times , digit ; for ( times = 1 ; times <= 10 ; times ++ ) { digit = ( X * times ) % 10 ; if ( digit == unit_digit ) return times ; } return - 1 ; } function getNum ( N , X ) { let unit_digit ; unit_digit = N % 10 ; let times = check ( unit_digit , X ) ; if ( times == - 1 ) return times ; else { if ( N >= ( times * X ) ) return times ; else return - 1 ; } } let N = 58 , X = 7 ; document . write ( getNum ( N , X ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program for Goldbach\u00e2 \u20ac\u2122 s Conjecture ( Two Primes with given Sum ) | PHP program to implement Goldbach 's conjecture ; Array to store all prime less than and equal to 10 ^ 6 ; Utility function for Sieve of Sundaram ; In general Sieve of Sundaram , produces primes smaller than ( 2 * x + 2 ) for a number given number x . Since we want primes smaller than MAX , we reduce MAX to half . This array is used to separate numbers of the form i + j + 2 * i * j from others where 1 <= i <= j ; Main logic of Sundaram . Mark all numbers which do not generate prime number by doing 2 * i + 1 ; Since 2 is a prime number ; Print other primes . Remaining primes are of the form 2 * i + 1 such that marked [ i ] is false . ; Function to perform Goldbach 's conjecture ; Return if number is not even or less than 3 ; Check only upto half of number ; find difference by subtracting current prime from n ; Search if the difference is also a prime number ; Express as a sum of primes ; Finding all prime numbers before limit ; Express number as a sum of two primes\\\"\\nSolution in php:\",\"targets\":\"< ? php $ MAX = 10000 ; $ primes = array ( ) ; function sieveSundaram ( ) { global $ MAX , $ primes ; $ marked = array_fill ( 0 , ( int ) ( $ MAX \\/ 2 ) + 100 , false ) ; for ( $ i = 1 ; $ i <= ( sqrt ( $ MAX ) - 1 ) \\/ 2 ; $ i ++ ) for ( $ j = ( $ i * ( $ i + 1 ) ) << 1 ; $ j <= $ MAX \\/ 2 ; $ j = $ j + 2 * $ i + 1 ) $ marked [ $ j ] = true ; array_push ( $ primes , 2 ) ; for ( $ i = 1 ; $ i <= $ MAX \\/ 2 ; $ i ++ ) if ( $ marked [ $ i ] == false ) array_push ( $ primes , 2 * $ i + 1 ) ; } function findPrimes ( $ n ) { global $ MAX , $ primes ; if ( $ n <= 2 $ n % 2 != 0 ) { print ( \\\" Invalid \u2581 Input \u2581 \\n \\\" ) ; return ; } for ( $ i = 0 ; $ primes [ $ i ] <= $ n \\/ 2 ; $ i ++ ) { $ diff = $ n - $ primes [ $ i ] ; if ( in_array ( $ diff , $ primes ) ) { print ( $ primes [ $ i ] . \\\" + \\\" \u2581 . \u2581 $ diff \u2581 . \u2581 \\\" = \\\" \u2581 . \u2581 $ n \u2581 . \u2581 \\\" \\\" return ; } } } sieveSundaram ( ) ; findPrimes ( 4 ) ; findPrimes ( 38 ) ; findPrimes ( 100 ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimize count of adjacent row swaps to convert given Matrix to a Lower Triangular Matrix | C ++ program to implement the above approach ; Function to count the minimum number of adjacent swaps ; Stores the size of the given matrix ; Stores the count of zero at the end of each row ; Traverse the given matrix ; Count of 0 s at the end of the ith row ; Stores the count of swaps ; Traverse the cntZero array ; If count of zero in the i - th row < ( N - i - 1 ) ; Stores the index of the row where count of zero > ( N - i - 1 ) ; If no row found that satisfy the condition ; Swap the adjacent row ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int minAdjSwaps ( vector < vector < int > > & mat ) { int N = mat . size ( ) ; vector < int > cntZero ( N , 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = N - 1 ; j >= 0 && mat [ i ] [ j ] == 0 ; j -- ) { cntZero [ i ] ++ ; } } int cntSwaps = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( cntZero [ i ] < ( N - i - 1 ) ) { int First = i ; while ( First < N && cntZero [ First ] < ( N - i - 1 ) ) { First ++ ; } if ( First == N ) { return -1 ; } while ( First > i ) { swap ( cntZero [ First ] , cntZero [ First - 1 ] ) ; First -- ; cntSwaps ++ ; } } } return cntSwaps ; } int main ( ) { vector < vector < int > > mat = { { 0 , 0 , 2 } , { 3 , 1 , 0 } , { 4 , 0 , 0 } } ; cout << minAdjSwaps ( mat ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Lexicographically smallest binary string formed by flipping bits at indices not divisible K1 or K2 such that count of 1 s is always greater than 0 s from left | Java program for the above approach ; Function to find lexicographically smallest String having number of 1 s greater than number of 0 s ; C1s And C0s stores the count of 1 s and 0 s at every position ; Traverse the String S ; If the position is not divisible by k1 and k2 ; If C0s >= C1s and pos [ ] is empty then the String can 't be formed ; If pos [ ] is not empty then flip the bit of last position present in pos [ ] ; Print the result ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void generateString ( int k1 , int k2 , char [ ] s ) { int C1s = 0 , C0s = 0 ; int flag = 0 ; Vector < Integer > pos = new Vector < Integer > ( ) ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == '0' ) { C0s ++ ; if ( ( i + 1 ) % k1 != 0 && ( i + 1 ) % k2 != 0 ) { pos . add ( i ) ; } } else { C1s ++ ; } if ( C0s >= C1s ) { if ( pos . size ( ) == 0 ) { System . out . print ( - 1 ) ; flag = 1 ; break ; } else { int k = pos . get ( pos . size ( ) - 1 ) ; s [ k ] = '1' ; C0s -- ; C1s ++ ; pos . remove ( pos . size ( ) - 1 ) ; } } } if ( flag == 0 ) { System . out . print ( s ) ; } } public static void main ( String [ ] args ) { int K1 = 2 , K2 = 4 ; String S = \\\"11000100\\\" ; generateString ( K1 , K2 , S . toCharArray ( ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Centered Dodecagonal Number | C # Program to find nth centered dodecagonal number ; Function to calculate centered dodecagonal number ; Formula to calculate nth centered dodecagonal number ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static long centeredDodecagonal ( long n ) { return 6 * n * ( n - 1 ) + 1 ; } public static void Main ( String [ ] args ) { long n = 2 ; Console . WriteLine ( centeredDodecagonal ( n ) ) ; n = 9 ; Console . WriteLine ( centeredDodecagonal ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count of ways to split a given number into prime segments | C # implementation to count total number of ways to split a String to get prime numbers ; Function to build sieve ; If p is a prime ; Update all multiples of p as non prime ; Function to check whether a number is a prime number or not ; Function to find the count of ways to split String into prime numbers ; Number should not have a leading zero and it should be a prime number ; Function to count the number of prime Strings ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int MOD = 1000000007 ; static bool [ ] sieve = new bool [ 1000000 ] ; static void buildSieve ( ) { for ( int j = 0 ; j < sieve . Length ; j ++ ) sieve [ j ] = true ; sieve [ 0 ] = false ; sieve [ 1 ] = false ; for ( int p = 2 ; p * p <= 1000000 ; p ++ ) { if ( sieve [ p ] == true ) { for ( int i = p * p ; i < 1000000 ; i += p ) sieve [ i ] = false ; } } } static bool isPrime ( String number ) { int num = Int32 . Parse ( number ) ; return sieve [ num ] ; } static int rec ( String number , int i , int [ ] dp ) { if ( dp [ i ] != - 1 ) return dp [ i ] ; int cnt = 0 ; for ( int j = 1 ; j <= 6 ; j ++ ) { if ( i - j >= 0 && number [ i - j ] != '0' && isPrime ( number . Substring ( i - j , j ) ) ) { cnt += rec ( number , i - j , dp ) ; cnt %= MOD ; } } return dp [ i ] = cnt ; } static int countPrimeStrings ( String number ) { int n = number . Length ; int [ ] dp = new int [ n + 1 ] ; for ( int j = 0 ; j < dp . Length ; j ++ ) dp [ j ] = - 1 ; dp [ 0 ] = 1 ; return rec ( number , n , dp ) ; } public static void Main ( String [ ] args ) { buildSieve ( ) ; String s1 = \\\"3175\\\" ; Console . Write ( countPrimeStrings ( s1 ) + \\\" \\n \\\" ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Modify a given matrix by placing sorted boundary elements in clockwise manner | Function to print the elements of the matrix in row - wise manner ; Function to sort boundary elements of a matrix starting from the outermost to the innermost boundary and place them in a clockwise manner ; k - starting row index m - ending row index l - starting column index n - ending column index i - iterator ; Stores the current boundary elements ; Push the first row ; Push the last column ; Push the last row ; Push the first column ; Sort the boundary elements ; Update the first row ; Update the last column ; Update the last row ; Update the first column ; Print the resultant matrix ; Given matrix\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function printMatrix ( a ) { for ( let i = 0 ; i < a . length ; i ++ ) { for ( let j = 0 ; j < a [ i ] . length ; j ++ ) { document . write ( a [ i ] [ j ] + \\\" \\\" ) ; } document . write ( \\\" \\\" ) ; } } function sortBoundaryWise ( a ) { let i , k = 0 , l = 0 ; let m = a . length , n = a [ 0 ] . length ; let n_i , n_k = 0 , n_l = 0 , n_m = m , n_n = n ; while ( k < m && l < n ) { let boundary = [ ] ; for ( i = l ; i < n ; ++ i ) { boundary . push ( a [ k ] [ i ] ) ; } k ++ ; for ( i = k ; i < m ; ++ i ) { boundary . push ( a [ i ] [ n - 1 ] ) ; } n -- ; if ( k < m ) { for ( i = n - 1 ; i >= l ; -- i ) { boundary . push ( a [ m - 1 ] [ i ] ) ; } m -- ; } if ( l < n ) { for ( i = m - 1 ; i >= k ; -- i ) { boundary . push ( a [ i ] [ l ] ) ; } l ++ ; } boundary . sort ( function ( a , b ) { return a - b ; } ) ; let ind = 0 ; for ( i = n_l ; i < n_n ; ++ i ) { a [ n_k ] [ i ] = boundary [ ind ] ; ind ++ ; } n_k += 1 ; for ( i = n_k ; i < n_m ; ++ i ) { a [ i ] [ n_n - 1 ] = boundary [ ind ] ; ind ++ ; } n_n -- ; if ( n_k < n_m ) { for ( i = n_n - 1 ; i >= n_l ; -- i ) { a [ n_m - 1 ] [ i ] = boundary [ ind ] ; ind ++ ; } n_m -- ; } if ( n_l < n_n ) { for ( i = n_m - 1 ; i >= n_k ; -- i ) { a [ i ] [ n_l ] = boundary [ ind ] ; ind ++ ; } n_l ++ ; } } printMatrix ( a ) ; } let matrix = [ ] ; let list1 = [ 9 , 7 , 4 , 5 ] ; let list2 = [ 1 , 6 , 2 , - 6 ] ; let list3 = [ 12 , 20 , 2 , 0 ] ; let list4 = [ - 5 , - 6 , 7 , - 2 ] ; matrix . push ( list1 ) ; matrix . push ( list2 ) ; matrix . push ( list3 ) ; matrix . push ( list4 ) ; sortBoundaryWise ( matrix ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count possible decoding of a given digit sequence with hidden characters | C # program for the above approach ; If s [ i ] = = ' * ' there can be 9 possible values of * ; If previous character is 1 then words that can be formed are K ( 11 ) , L ( 12 ) , M ( 13 ) , N ( 14 ) O ( 15 ) , P ( 16 ) , Q ( 17 ) , R ( 18 ) , S ( 19 ) ; If previous character is 2 then the words that can be formed are U ( 21 ) , V ( 22 ) , W ( 23 ) , X ( 24 ) Y ( 25 ) , Z ( 26 ) ; If the previous digit is * then all 15 2 - digit characters can be formed ; If s [ i ] != ' * ' ; Adding first in second if s [ i - 1 ] = 1 ; Adding first in second if s [ i - 1 ] = = 2 and s [ i ] <= '6' ; if s [ i - 1 ] == ' * ' the union of above 2 cases has to be done ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int M = 1000000007 ; static int waysOfDecoding ( string s ) { long first = 1 , second = s [ 0 ] == ' * ' ? 9 : s [ 0 ] == '0' ? 0 : 1 ; for ( int i = 1 ; i < s . Length ; i ++ ) { long temp = second ; if ( s [ i ] == ' * ' ) { second = 9 * second ; if ( s [ i - 1 ] == '1' ) second = ( second + 9 * first ) % M ; else if ( s [ i - 1 ] == '2' ) second = ( second + 6 * first ) % M ; else if ( s [ i - 1 ] == ' * ' ) second = ( second + 15 * first ) % M ; } else { second = s [ i ] != '0' ? second : 0 ; if ( s [ i - 1 ] == '1' ) second = ( second + first ) % M ; else if ( s [ i - 1 ] == '2' && s [ i ] <= '6' ) second = ( second + first ) % M ; else if ( s [ i - 1 ] == ' * ' ) second = ( second + ( s [ i ] <= '6' ? 2 : 1 ) * first ) % M ; } first = temp ; } return ( int ) second ; } static public void Main ( ) { string s = \\\" * \\\" ; Console . WriteLine ( waysOfDecoding ( s ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find the repeating and the missing number using two equations | Function to print the required numbers ; Sum of first n natural numbers ; Sum of squares of first n natural numbers ; To store the sum and sum of squares of the array elements ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findNumbers ( $ arr , $ n ) { $ sumN = ( $ n * ( $ n + 1 ) ) \\/ 2 ; $ sumSqN = ( $ n * ( $ n + 1 ) * ( 2 * $ n + 1 ) ) \\/ 6 ; $ sum = 0 ; $ sumSq = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ sum += $ arr [ $ i ] ; $ sumSq += pow ( $ arr [ $ i ] , 2 ) ; } $ B = ( ( ( $ sumSq - $ sumSqN ) \\/ ( $ sum - $ sumN ) ) + $ sumN - $ sum ) \\/ 2 ; $ A = $ sum - $ sumN + $ B ; echo \\\" A = \\\" , \u2581 $ A , \u2581 \\\" B = \\\" } $ arr = array ( 1 , 2 , 2 , 3 , 4 ) ; $ n = sizeof ( $ arr ) ; findNumbers ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find a pair with the given difference | C program to find a pair with the given difference ; The function assumes that the array is sorted ; Initialize positions of two elements ; Search for a pair ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\nbool findPair ( int arr [ ] , int size , int n ) { int i = 0 ; int j = 1 ; while ( i < size && j < size ) { if ( i != j && arr [ j ] - arr [ i ] == n ) { printf ( \\\" Pair \u2581 Found : \u2581 ( % d , \u2581 % d ) \\\" , arr [ i ] , arr [ j ] ) ; return true ; } else if ( arr [ j ] - arr [ i ] < n ) j ++ ; else i ++ ; } printf ( \\\" No \u2581 such \u2581 pair \\\" ) ; return false ; } int main ( ) { int arr [ ] = { 1 , 8 , 30 , 40 , 100 } ; int size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int n = 60 ; findPair ( arr , size , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Remove all characters other than alphabets from string | CPP program to remove all the characters other then alphabets ; function to remove characters and print new string ; Finding the character whose ASCII value fall under this range ; erase function to erase the character ; driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void removeSpecialCharacter ( string s ) { for ( int i = 0 ; i < s . size ( ) ; i ++ ) { if ( s [ i ] < ' A ' s [ i ] > ' Z ' && s [ i ] < ' a ' s [ i ] > ' z ' ) { s . erase ( i , 1 ) ; i -- ; } } cout << s ; } int main ( ) { string s = \\\" $ Gee * k ; s . . fo , \u2581 r ' Ge ^ eks ? \\\" ; removeSpecialCharacter ( s ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count possible decoding of a given digit sequence with hidden characters | C # program for the above approach ; Check the first character of the string if it is ' * ' then 9 ways ; Traverse the string ; If s [ i ] = = ' * ' there can be 9 possible values of * ; If previous character is 1 then words that can be formed are K ( 11 ) , L ( 12 ) , M ( 13 ) , N ( 14 ) O ( 15 ) , P ( 16 ) , Q ( 17 ) , R ( 18 ) , S ( 19 ) ; If previous character is 2 then the words that can be formed are U ( 21 ) , V ( 22 ) , W ( 23 ) , X ( 24 ) Y ( 25 ) , Z ( 26 ) ; If the previous digit is * then all 15 2 - digit characters can be formed ; Taking the value from previous step ; If previous character is 1 then the i - 1 th character and ith character can be decoded in a single character therefore , adding dp [ i - 1 ] . ; If previous character is 2 and ith character is less than 6 then the i - 1 th character and ith character can be decoded in a single character therefore , adding dp [ i - 1 ] . ; If previous character is * then it will contain the above 2 cases ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int M = 1000000007 ; static int waysOfDecoding ( String s ) { long [ ] dp = new long [ s . Length + 1 ] ; dp [ 0 ] = 1 ; dp [ 1 ] = s [ 0 ] == ' * ' ? 9 : s [ 0 ] == '0' ? 0 : 1 ; for ( int i = 1 ; i < s . Length ; i ++ ) { if ( s [ i ] == ' * ' ) { dp [ i + 1 ] = 9 * dp [ i ] ; if ( s [ i - 1 ] == '1' ) dp [ i + 1 ] = ( dp [ i + 1 ] + 9 * dp [ i - 1 ] ) % M ; else if ( s [ i - 1 ] == '2' ) dp [ i + 1 ] = ( dp [ i + 1 ] + 6 * dp [ i - 1 ] ) % M ; else if ( s [ i - 1 ] == ' * ' ) dp [ i + 1 ] = ( dp [ i + 1 ] + 15 * dp [ i - 1 ] ) % M ; } else { dp [ i + 1 ] = s [ i ] != '0' ? dp [ i ] : 0 ; if ( s [ i - 1 ] == '1' ) dp [ i + 1 ] = ( dp [ i + 1 ] + dp [ i - 1 ] ) % M ; else if ( s [ i - 1 ] == '2' && s [ i ] <= '6' ) dp [ i + 1 ] = ( dp [ i + 1 ] + dp [ i - 1 ] ) % M ; else if ( s [ i - 1 ] == ' * ' ) dp [ i + 1 ] = ( dp [ i + 1 ] + ( s [ i ] <= '6' ? 2 : 1 ) * dp [ i - 1 ] ) % M ; } } return ( int ) dp [ s . Length ] ; } public static void Main ( ) { String s = \\\"12\\\" ; Console . WriteLine ( waysOfDecoding ( s ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Binary Insertion Sort | iterative implementation ; Function to sort an array a [ ] of size ' n ' ; find location where selected should be inseretd ; Move all elements after location to create space ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\nint binarySearch ( int a [ ] , int item , int low , int high ) { while ( low <= high ) { int mid = low + ( high - low ) \\/ 2 ; if ( item == a [ mid ] ) return mid + 1 ; else if ( item > a [ mid ] ) low = mid + 1 ; else high = mid - 1 ; } return low ; } void insertionSort ( int a [ ] , int n ) { int i , loc , j , k , selected ; for ( i = 1 ; i < n ; ++ i ) { j = i - 1 ; selected = a [ i ] ; loc = binarySearch ( a , selected , 0 , j ) ; while ( j >= loc ) { a [ j + 1 ] = a [ j ] ; j -- ; } a [ j + 1 ] = selected ; } } int main ( ) { int a [ ] = { 37 , 23 , 0 , 17 , 12 , 72 , 31 , 46 , 100 , 88 , 54 } ; int n = sizeof ( a ) \\/ sizeof ( a [ 0 ] ) , i ; insertionSort ( a , n ) ; printf ( \\\" Sorted \u2581 array : \u2581 \\n \\\" ) ; for ( i = 0 ; i < n ; i ++ ) printf ( \\\" % d \u2581 \\\" , a [ i ] ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to remove HTML tags from a given String | C # program for the above approach ; Function to remove the HTML tags from the given tags ; Use replaceAll function in regex to erase every tags enclosed in < > str = Regex . Replace ( str , \\\" < . * ? > \\\" , String . Empty ) ; Print string after removing tags ; Driver code ; Given String ; Function call to print the HTML string after removing tags\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void RemoveHTMLTags ( String str ) { System . Text . RegularExpressions . Regex rx = new System . Text . RegularExpressions . Regex ( \\\" < [ ^ > ] * > \\\" ) ; str = rx . Replace ( str , \\\" \\\" ) ; Console . WriteLine ( str ) ; } public static void Main ( String [ ] args ) { String str ; str = \\\" < div > < b > Geeks \u2581 for \u2581 Geeks < \\/ b > < \\/ div > \\\" ; RemoveHTMLTags ( str ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Swap all odd and even bits | C program to swap even and odd bits of a given number ; Function to swap even and odd bits ; Get all even bits of x ; Get all odd bits of x ; Right shift even bits ; Left shift odd bits ; Combine even and odd bits ; Driver program to test above function ; 00010111 ; Output is 43 ( 00101011 )\\\"\\nSolution in C:\",\"targets\":\"#include \\nunsigned int swapBits ( unsigned int x ) { unsigned int even_bits = x & 0xAAAAAAAA ; unsigned int odd_bits = x & 0x55555555 ; even_bits >>= 1 ; odd_bits <<= 1 ; return ( even_bits odd_bits ) ; } int main ( ) { unsigned int x = 23 ; printf ( \\\" % u \u2581 \\\" , swapBits ( x ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Search an element in a sorted and rotated array | Returns index of key in arr [ l . . h ] if key is present , otherwise returns - 1 ; If arr [ l ... mid ] is sorted ; As this subarray is sorted , we can quickly check if key lies in half or other half ; If key not lies in first half subarray , Divide other half into two subarrays , such that we can quickly check if key lies in other half ; If arr [ l . . mid ] is not sorted , then arr [ mid ... r ] must be sorted ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function search ( $ arr , $ l , $ h , $ key ) { if ( $ l > $ h ) return -1 ; $ mid = ( $ l + $ h ) \\/ 2 ; if ( $ arr [ $ mid ] == $ key ) return $ mid ; if ( $ arr [ $ l ] <= $ arr [ $ mid ] ) { if ( $ key >= $ arr [ $ l ] && $ key <= $ arr [ $ mid ] ) return search ( $ arr , $ l , $ mid - 1 , $ key ) ; return search ( $ arr , $ mid + 1 , $ h , $ key ) ; } if ( $ key >= $ arr [ $ mid ] && $ key <= $ arr [ $ h ] ) return search ( $ arr , $ mid + 1 , $ h , $ key ) ; return search ( $ arr , $ l , $ mid - 1 , $ key ) ; } $ arr = array ( 4 , 5 , 6 , 7 , 8 , 9 , 1 , 2 , 3 ) ; $ n = sizeof ( $ arr ) ; $ key = 6 ; $ i = search ( $ arr , 0 , $ n - 1 , $ key ) ; if ( $ i != -1 ) echo \\\" Index : \u2581 \\\" , floor ( $ i ) , \\\" \u2581 \\n \\\" ; else echo \\\" Key \u2581 not \u2581 found \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Smallest power of 2 greater than or equal to n | ; Finds next power of two for n . If n itself is a power of two then returns n ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\nunsigned int nextPowerOf2 ( unsigned int n ) { n -- ; n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; n ++ ; return n ; } int main ( ) { unsigned int n = 5 ; printf ( \\\" % d \\\" , nextPowerOf2 ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check duplicates in a stream of strings | Function to insert the names and check whether they appear for the first time ; To store the names of the employees ; If current name is appearing for the first time ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def insertNames ( arr , n ) :\\n\\tstring = set ( ) ;\\n\\tfor i in range ( n ) :\\n\\t\\tif arr [ i ] not in string :\\n\\t\\t\\tprint ( \\\" No \\\" ) ;\\n\\t\\t\\tstring . add ( arr [ i ] ) ;\\n\\t\\telse :\\n\\t\\t\\tprint ( \\\" Yes \\\" ) ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ \\\" geeks \\\" , \\\" for \\\" , \\\" geeks \\\" ] ;\\n\\tn = len ( arr ) ;\\n\\tinsertNames ( arr , n ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Coin Change | DP | Recursive C program for coin change problem . ; Returns the count of ways we can sum S [ 0. . . m - 1 ] coins to get sum n ; If n is 0 then there is 1 solution ( do not include any coin ) ; If n is less than 0 then no solution exists ; If there are no coins and n is greater than 0 , then no solution exist ; count is sum of solutions ( i ) including S [ m - 1 ] ( ii ) excluding S [ m - 1 ] ; Driver program to test above function\\\"\\nSolution in C++:\",\"targets\":\"#include \\nint count ( int S [ ] , int m , int n ) { if ( n == 0 ) return 1 ; if ( n < 0 ) return 0 ; if ( m <= 0 && n >= 1 ) return 0 ; return count ( S , m - 1 , n ) + count ( S , m , n - S [ m - 1 ] ) ; } int main ( ) { int i , j ; int arr [ ] = { 1 , 2 , 3 } ; int m = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" % d \u2581 \\\" , count ( arr , m , 4 ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Number of N digit integers with weight W | Function to find total possible numbers with n digits and weight w ; When Weight of an integer is Positive ; Subtract the weight from 9 ; When weight of an integer is negative ; add the weight to 10 to make it positive ; number of digits in an integer and w as weight ; print the total possible numbers with n digits and weight w\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findNumbers ( $ n , $ w ) { $ x = 0 ; $ sum = 0 ; if ( $ w >= 0 && $ w <= 8 ) { $ x = 9 - $ w ; } else if ( $ w >= -9 && $ w <= -1 ) { $ x = 10 + $ w ; } $ sum = pow ( 10 , $ n - 2 ) ; $ sum = ( $ x * $ sum ) ; return $ sum ; } $ n = 3 ; $ w = 4 ; echo findNumbers ( $ n , $ w ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the N | PHP program to find n - th number containing only 3 and 5. ; If n is odd , append 3 and move to parent ; If n is even , append 5 and move to parent ; Reverse res and return . ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findNthNo ( $ n ) { $ res = \\\" \\\" ; while ( $ n >= 1 ) { if ( $ n & 1 ) { $ res = $ res + \\\"3\\\" ; $ n = ( $ n - 1 ) \\/ 2 ; } else { $ res = $ res . \\\"5\\\" ; $ n = ( $ n - 2 ) \\/ 2 ; } } $ res = strrev ( $ res ) ; return $ res ; } $ n = 5 ; echo findNthNo ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Given a binary tree , how do you remove all the half nodes ? | C program to remove all half nodes ; Binary tree node ; ; For inorder traversal ; Removes all nodes with only one child and returns new root ( note that root may change ) ; if current nodes is a half node with left child NULL left , then it 's right child is returned and replaces it in the given tree ; if current nodes is a half node with right child NULL right , then it 's right child is returned and replaces it in the given tree ; Driver program\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nstruct node { int data ; struct node * left , * right ; } ; struct node * newNode ( int data ) { struct node * node = ( struct node * ) malloc ( sizeof ( struct node ) ) ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } void printInoder ( struct node * root ) { if ( root != NULL ) { printInoder ( root -> left ) ; printf ( \\\" % d \u2581 \\\" , root -> data ) ; printInoder ( root -> right ) ; } } struct node * RemoveHalfNodes ( struct node * root ) { if ( root == NULL ) return NULL ; root -> left = RemoveHalfNodes ( root -> left ) ; root -> right = RemoveHalfNodes ( root -> right ) ; if ( root -> left == NULL && root -> right == NULL ) return root ; if ( root -> left == NULL ) { struct node * new_root = root -> right ; free ( root ) ; return new_root ; } if ( root -> right == NULL ) { struct node * new_root = root -> left ; free ( root ) ; return new_root ; } return root ; } int main ( void ) { struct node * NewRoot = NULL ; struct node * root = newNode ( 2 ) ; root -> left = newNode ( 7 ) ; root -> right = newNode ( 5 ) ; root -> left -> right = newNode ( 6 ) ; root -> left -> right -> left = newNode ( 1 ) ; root -> left -> right -> right = newNode ( 11 ) ; root -> right -> right = newNode ( 9 ) ; root -> right -> right -> left = newNode ( 4 ) ; printf ( \\\" Inorder \u2581 traversal \u2581 of \u2581 given \u2581 tree \u2581 \\n \\\" ) ; printInoder ( root ) ; NewRoot = RemoveHalfNodes ( root ) ; printf ( \\\" Inorder traversal of the modified tree \\\" printInoder ( NewRoot ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of palindromic permutations | Set 1 | Java program to find number of palindromic permutations of a given string ; Returns factorial of n ; Returns count of palindromic permutations of str . ; Count frequencies of all characters ; Since half of the characters decide count of palindromic permutations , we take ( n \\/ 2 ) ! ; To make sure that there is at most one odd occurring char ; Traverse through all counts ; To make sure that the string can permute to form a palindrome ; If there are more than one odd occurring chars ; Divide all permutations with repeated characters ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static final int MAX = 256 ; static long fact ( int n ) { long res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } static int countPalinPermutations ( String str ) { int n = str . length ( ) ; int freq [ ] = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ str . charAt ( i ) ] ++ ; long res = fact ( n \\/ 2 ) ; boolean oddFreq = false ; for ( int i = 0 ; i < MAX ; i ++ ) { int half = freq [ i ] \\/ 2 ; if ( freq [ i ] % 2 != 0 ) { if ( oddFreq == true ) return 0 ; oddFreq = true ; } res = res \\/ fact ( half ) ; } return ( int ) res ; } public static void main ( String [ ] args ) { String str = \\\" gffg \\\" ; System . out . print ( countPalinPermutations ( str ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all the Composite Numbers from Odd indices of the given array | Function to check for composite numbers ; Check if the factors are greater than 2 ; Check if the number is composite or not ; Function to print the sum of all composite numbers in the array ; Iterate for odd indices in the array ; Check if the number is composite then add it to sum ; return the sum ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function composite ( n ) { let flag = 0 ; let c = 0 ; for ( let j = 1 ; j <= n ; j ++ ) { if ( n % j == 0 ) { c += 1 ; } } if ( c >= 3 ) flag = 1 ; return flag ; } function odd_indices ( arr , n ) { let sum = 0 ; for ( let k = 0 ; k < n ; k += 2 ) { let check = composite ( arr [ k ] ) ; if ( check == 1 ) sum += arr [ k ] ; } document . write ( sum + \\\" \\\" ) ; } let arr = [ 13 , 5 , 8 , 16 , 25 ] ; let n = arr . length odd_indices ( arr , n ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Generate an array of minimum sum whose XOR of same | C # program to implement the above approach ; Function to generate an array whose XOR with same - indexed elements of the given array is always a prime ; Traverse the array ; If current array element is 2 ; Print its XOR with 3 ; Otherwise ; Print its XOR with 2 ; Driver code ; Given array ; Size of the array ; Prints the required array\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { private static void minXOR ( int [ ] Arr , int N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( Arr [ i ] == 2 ) { Console . Write ( ( Arr [ i ] ^ 3 ) + \\\" \u2581 \\\" ) ; } else { Console . Write ( ( Arr [ i ] ^ 2 ) + \\\" \u2581 \\\" ) ; } } } public static void Main ( ) { int [ ] Arr = { 5 , 4 , 7 , 6 } ; int N = Arr . Length ; minXOR ( Arr , N ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count of substrings from given Ternary strings containing characters at least once | Java program for the above approach ; Function to count the number of substrings consists of 0 , 1 , and 2 ; Initialize frequency array of size 3 ; Stores the resultant count ; Traversing string str ; Update frequency array ; If all the characters are present counting number of substrings possible ; Update number of substrings ; Return the number of substrings ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { public static int countSubstrings ( String str ) { int [ ] freq = new int [ 3 ] ; int count = 0 ; int i = 0 ; for ( int j = 0 ; j < str . length ( ) ; j ++ ) { freq [ str . charAt ( j ) - '0' ] ++ ; while ( freq [ 0 ] > 0 && freq [ 1 ] > 0 && freq [ 2 ] > 0 ) { freq [ str . charAt ( i ++ ) - '0' ] -- ; } count += i ; } return count ; } public static void main ( String [ ] args ) { String str = \\\"00021\\\" ; System . out . println ( countSubstrings ( str ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Twin Prime Numbers between 1 and n | C ++ program print all twin primes using Sieve of Eratosthenes . ; Create a boolean array \\\" prime [ 0 . . n ] \\\" and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; to check for twin prime numbers display the twin primes ; Driver Program to test above function ; Calling the function\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void printTwinPrime ( int n ) { bool prime [ n + 1 ] ; memset ( prime , true , sizeof ( prime ) ) ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } for ( int p = 2 ; p <= n - 2 ; p ++ ) if ( prime [ p ] && prime [ p + 2 ] ) cout << \\\" ( \\\" << p << \\\" , \u2581 \\\" << p + 2 << \\\" ) \\\" ; } int main ( ) { int n = 25 ; printTwinPrime ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Write you own Power without using multiplication ( * ) and division ( \\/ ) operators | ; Works only if a >= 0 and b >= 0 ; driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint pow ( int a , int b ) { if ( b == 0 ) return 1 ; int answer = a ; int increment = a ; int i , j ; for ( i = 1 ; i < b ; i ++ ) { for ( j = 1 ; j < a ; j ++ ) { answer += increment ; } increment = answer ; } return answer ; } int main ( ) { printf ( \\\" % d \\\" , pow ( 5 , 3 ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum removals required to make frequency of each array element equal to its value | C ++ program to implement the above approach ; Function to find the minimum count of elements required to be removed such that frequency of arr [ i ] equal to arr [ i ] ; Stores frequency of each element of the array ; Traverse the array ; Update frequency of arr [ i ] ; Stores minimum count of removals ; Traverse the map ; Stores key value of the map ; If frequency of i is less than i ; Update cntMinRem ; If frequency of i is greater than i ; Update cntMinRem ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int min_elements ( int arr [ ] , int N ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < N ; i ++ ) { mp [ arr [ i ] ] ++ ; } int cntMinRem = 0 ; for ( auto it : mp ) { int i = it . first ; if ( mp [ i ] < i ) { cntMinRem += mp [ i ] ; } else if ( mp [ i ] > i ) { cntMinRem += ( mp [ i ] - i ) ; } } return cntMinRem ; } int main ( ) { int arr [ ] = { 2 , 4 , 1 , 4 , 2 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << min_elements ( arr , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Insert minimum number in array so that sum of array becomes prime | PHP program to find minimum number to insert in array so their sum is prime ; function to calculate primes using sieve of eratosthenes ; Find prime number greater than a number ; To return prime number greater than n ; check if num is prime ; increment num ; To find number to be added so sum of array is prime ; call sieveOfEratostheneses to calculate primes ; To find sum of array elements ; To find prime number greater then sum ; Return difference of sum and num ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php $ MAX = 100005 ; function sieveOfEratostheneses ( ) { $ isPrime = array_fill ( true , $ MAX , NULL ) ; $ isPrime [ 1 ] = false ; for ( $ i = 2 ; $ i * $ i < $ MAX ; $ i ++ ) { if ( $ isPrime [ $ i ] ) { for ( $ j = 2 * $ i ; $ j < $ MAX ; $ j += $ i ) $ isPrime [ $ j ] = false ; } } } function findPrime ( $ n ) { $ num = $ n + 1 ; while ( $ num ) { if ( $ isPrime [ $ num ] ) return $ num ; $ num = $ num + 1 ; } return 0 ; } function minNumber ( & $ arr , $ n ) { sieveOfEratostheneses ( ) ; $ sum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ sum += $ arr [ $ i ] ; if ( $ isPrime [ $ sum ] ) return 0 ; $ num = findPrime ( $ sum ) ; return $ num - $ sum ; } $ arr = array ( 2 , 4 , 6 , 8 , 12 ) ; $ n = sizeof ( $ arr ) \\/ sizeof ( $ arr [ 0 ] ) ; echo minNumber ( $ arr , $ n ) ; return 0 ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if any subarray can be made palindromic by replacing less than half of its elements | Java program for the above approach ; A Utility Function to check if a subarray can be palindromic by replacing less than half of the elements present in it ; Stores frequency of array elements ; Traverse the array ; Update frequency of each array element ; Iterator over the Map ; If frequency of any element exceeds 1 ; If no repetition is found ; Function to check and print if any subarray can be made palindromic by replacing less than half of its elements ; Driver Code ; Given array arr [ ] ; Size of array ; Function Call\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static boolean isConsistingSubarrayUtil ( int arr [ ] , int n ) { TreeMap < Integer , Integer > mp = new TreeMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { mp . put ( arr [ i ] , mp . getOrDefault ( arr [ i ] , 0 ) + 1 ) ; } for ( Map . Entry < Integer , Integer > it : mp . entrySet ( ) ) { if ( it . getValue ( ) > 1 ) { return true ; } } return false ; } static void isConsistingSubarray ( int arr [ ] , int N ) { if ( isConsistingSubarrayUtil ( arr , N ) ) { System . out . println ( \\\" Yes \\\" ) ; } else { System . out . println ( \\\" No \\\" ) ; } } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 1 } ; int N = arr . length ; isConsistingSubarray ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if the string contains consecutive letters and each letter occurs exactly once | C ++ program to implement the above approach ; Function to check if the condition holds ; Get the length of the string ; sort the given string ; Iterate for every index and check for the condition ; If are not consecutive ; Driver code ; 1 st example ; 2 nd example\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool check ( string s ) { int l = s . length ( ) ; sort ( s . begin ( ) , s . end ( ) ) ; for ( int i = 1 ; i < l ; i ++ ) { if ( s [ i ] - s [ i - 1 ] != 1 ) return false ; } return true ; } int main ( ) { string str = \\\" dcef \\\" ; if ( check ( str ) ) cout << \\\" Yes \\n \\\" ; else cout << \\\" No \\n \\\" ; str = \\\" xyza \\\" ; if ( check ( str ) ) cout << \\\" Yes \\n \\\" ; else cout << \\\" No \\n \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Segregate 0 s and 1 s in an array | Function to segregate 0 s and 1 s ; Counts the no of zeros in arr ; Loop fills the arr with 0 until count ; Loop fills remaining arr space with 1 ; Function to print segregated array ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function segregate0and1 ( & $ arr , $ n ) { $ count = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] == 0 ) $ count ++ ; } for ( $ i = 0 ; $ i < $ count ; $ i ++ ) $ arr [ $ i ] = 0 ; for ( $ i = $ count ; $ i < $ n ; $ i ++ ) $ arr [ $ i ] = 1 ; } function toprint ( & $ arr , $ n ) { echo ( \\\" Array \u2581 after \u2581 segregation \u2581 is \u2581 \\\" ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo ( $ arr [ $ i ] . \\\" \u2581 \\\" ) ; } $ arr = array ( 0 , 1 , 0 , 1 , 1 , 1 ) ; $ n = sizeof ( $ arr ) ; segregate0and1 ( $ arr , $ n ) ; toprint ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Euler 's criterion (Check if square root under modulo p exists) | A Simple C # program to check if square root of a number under modulo p exists or not ; Returns true if square root of n under modulo p exists ; One by one check all numbers from 2 to p - 1 ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static bool squareRootExists ( int n , int p ) { n = n % p ; for ( int x = 2 ; x < p ; x ++ ) if ( ( x * x ) % p == n ) return true ; return false ; } public static void Main ( ) { int p = 7 ; int n = 2 ; if ( squareRootExists ( n , p ) ) Console . WriteLine ( \\\" Yes \\\" ) ; else Console . WriteLine ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find repeated character present first in a string | C program to find the first character that is repeated ; this is O ( N ^ 2 ) method ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nint findRepeatFirstN2 ( char * s ) { int p = -1 , i , j ; for ( i = 0 ; i < strlen ( s ) ; i ++ ) { for ( j = i + 1 ; j < strlen ( s ) ; j ++ ) { if ( s [ i ] == s [ j ] ) { p = i ; break ; } } if ( p != -1 ) break ; } return p ; } int main ( ) { char str [ ] = \\\" geeksforgeeks \\\" ; int pos = findRepeatFirstN2 ( str ) ; if ( pos == -1 ) printf ( \\\" Not \u2581 found \\\" ) ; else printf ( \\\" % c \\\" , str [ pos ] ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the Volume of a Triangular Prism | function to find the Volume of triangular prism ; formula to find Volume ; Driver Code ; function calling\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findVolume ( $ l , $ b , $ h ) { $ volume = ( $ l * $ b * $ h ) \\/ 2 ; return $ volume ; } $ l = 18 ; $ b = 12 ; $ h = 9 ; echo \\\" Volume \u2581 of \u2581 triangular \u2581 prism : \u2581 \\\" . findVolume ( $ l , $ b , $ h ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Seeds ( Or Seed Roots ) of a number | PHP program to find Seed of a number ; Stores product of digits of x in prodDig [ x ] ; If x has single digit ; If digit product is already computed ; If digit product is not computed before . ; Prints all seeds of n ; Find all seeds using prodDig [ ] ; If there was no seed ; Print seeds ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ MAX = 10000 ; $ prodDig = array_fill ( 0 , $ MAX , 0 ) ; function getDigitProduct ( $ x ) { global $ prodDig ; if ( $ x < 10 ) return $ x ; if ( $ prodDig [ $ x ] != 0 ) return $ prodDig [ $ x ] ; $ prod = ( int ) ( $ x % 10 ) * getDigitProduct ( ( int ) ( $ x \\/ 10 ) ) ; $ prodDig [ $ x ] = $ prod ; return $ prod ; } function findSeed ( $ n ) { $ res = array ( ) ; for ( $ i = 1 ; $ i <= ( int ) ( $ n \\/ 2 + 1 ) ; $ i ++ ) if ( $ i * getDigitProduct ( $ i ) == $ n ) array_push ( $ res , $ i ) ; if ( count ( $ res ) == 0 ) { echo \\\" NO \u2581 seed \u2581 exists \\n \\\" ; return ; } for ( $ i = 0 ; $ i < count ( $ res ) ; $ i ++ ) echo $ res [ $ i ] . \\\" \u2581 \\\" ; } $ n = 138 ; findSeed ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Logarithm tricks for Competitive Programming | C implementation count the number of digits in a number ; Function to count the number of digits in a number ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nint countDigit ( long long n ) { return ( floor ( log10 ( n ) + 1 ) ) ; } int main ( ) { double N = 80 ; printf ( \\\" % d \\\" , countDigit ( N ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Smallest square formed with given rectangles | Recursive function to return gcd of a and b ; Everything divides 0 ; Base case ; a is greater ; Function to find the area of the smallest square ; the length or breadth or side cannot be negative ; LCM of length and breadth ; squaring to get the area ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function gcd ( $ a , $ b ) { if ( $ a == 0 $ b == 0 ) return 0 ; if ( $ a == $ b ) return $ a ; if ( $ a > $ b ) return gcd ( $ a - $ b , $ b ) ; return gcd ( $ a , $ b - $ a ) ; } function squarearea ( $ l , $ b ) { if ( $ l < 0 $ b < 0 ) return -1 ; $ n = ( $ l * $ b ) \\/ gcd ( $ l , $ b ) ; return $ n * $ n ; } $ l = 6 ; $ b = 4 ; echo squarearea ( $ l , $ b ) . \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if end of given Binary string can be reached by choosing jump value in between given range | Java program for the above approach ; Function to check if it is possible to reach the end of the binary string using the given jumps ; Stores the DP states ; Initial state ; Stores count of indices from which it is possible to reach index i ; Traverse the given string ; Update the values of pre accordingly ; If the jump size is out of the range [ L , R ] ; Return answer ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"public class GFG { static int canReach ( String s , int L , int R ) { int dp [ ] = new int [ s . length ( ) ] ; dp [ 0 ] = 1 ; int pre = 0 ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { if ( i >= L ) { pre += dp [ i - L ] ; } if ( i > R ) { pre -= dp [ i - R - 1 ] ; } if ( pre > 0 && s . charAt ( i ) == '0' ) dp [ i ] = 1 ; else dp [ i ] = 0 ; } return dp [ s . length ( ) - 1 ] ; } public static void main ( String [ ] args ) { String S = \\\"01101110\\\" ; int L = 2 , R = 3 ; if ( canReach ( S , L , R ) == 1 ) System . out . println ( \\\" Yes \\\" ) ; else System . out . println ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Fast Exponention using Bit Manipulation | C # program to implement the above approach ; Function to return a ^ n ; Stores readonly answer ; Check if current LSB is set ; Right shift ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int powerOptimised ( int a , int n ) { int ans = 1 ; while ( n > 0 ) { int last_bit = ( n & 1 ) ; if ( last_bit > 0 ) { ans = ans * a ; } a = a * a ; n = n >> 1 ; } return ans ; } public static void Main ( String [ ] args ) { int a = 3 , n = 5 ; Console . Write ( powerOptimised ( a , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find Cube Pairs | Set 2 ( A n ^ ( 1 \\/ 3 ) Solution ) | Function to find pairs that can represent the given number as sum of two cubes ; find cube root of n ; create a array of size of size ' cubeRoot ' ; for index i , cube [ i ] will contain i ^ 3 ; Find all pairs in above sorted array cube [ ] whose sum is equal to n ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findPairs ( $ n ) { $ cubeRoot = pow ( $ n , 1.0 \\/ 3.0 ) ; $ cube = array ( ) ; for ( $ i = 1 ; $ i <= $ cubeRoot ; $ i ++ ) $ cube [ $ i ] = $ i * $ i * $ i ; $ l = 1 ; $ r = $ cubeRoot ; while ( $ l < $ r ) { if ( $ cube [ $ l ] + $ cube [ $ r ] < $ n ) $ l ++ ; else if ( $ cube [ $ l ] + $ cube [ $ r ] > $ n ) $ r -- ; else { echo \\\" ( \\\" , $ l , \\\" , \u2581 \\\" , floor ( $ r ) , \\\" ) \\\" ; echo \\\" \\n \\\" ; $ l ++ ; $ r -- ; } } } $ n = 20683 ; findPairs ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Area of the circumcircle of any triangles with sides given | C # Program to find the area the circumcircle of the given triangle ; Function to find the area of the circumcircle ; the sides cannot be negative ; semi - perimeter of the circle ; area of triangle ; area of the circle ; Driver code ; Get the sides of the triangle ; Find and print the area of the circumcircle\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class gfg { public double circlearea ( double a , double b , double c ) { if ( a < 0 b < 0 c < 0 ) return - 1 ; double p = ( a + b + c ) \\/ 2 ; double At = Math . Sqrt ( p * ( p - a ) * ( p - b ) * ( p - c ) ) ; double A = 3.14 * Math . Pow ( ( ( a * b * c ) \\/ ( 4 * At ) ) , 2 ) ; return A ; } } class geek { public static int Main ( ) { gfg g = new gfg ( ) ; double a = 4 , b = 5 , c = 3 ; Console . WriteLine ( g . circlearea ( a , b , c ) ) ; return 0 ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"An efficient way to check whether n | Returns true if n - th Fibonacci number is multiple of 10. ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function isMultipleOf10 ( $ n ) { return ( $ n % 15 == 0 ) ; } $ n = 30 ; if ( isMultipleOf10 ( $ n ) ) echo \\\" Yes \\n \\\" ; else echo \\\" No \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Smallest length of number divisible by K formed by using D only | C ++ program for the above approach ; Function to form the smallest number possible ; Array to mark the remainders counted already ; Iterate over the range ; If that remainder is already found , return - 1 ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int smallest ( int k , int d ) { int cnt = 1 ; int m = d % k ; vector < int > v ( k , 0 ) ; v [ m ] = 1 ; while ( 1 ) { if ( m == 0 ) return cnt ; m = ( ( ( m * ( 10 % k ) ) % k ) + ( d % k ) ) % k ; if ( v [ m ] == 1 ) return -1 ; v [ m ] = 1 ; cnt ++ ; } return -1 ; } int main ( ) { int d = 1 ; int k = 41 ; cout << smallest ( k , d ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count of interesting primes upto N | C # program to find the number of interesting primes up to N . ; Function to find all prime numbers ; Create a bool array \\\" prime [ 0 . . n ] \\\" and initialize all entries as true . A value in prime [ i ] will finally be false if i is Not a prime . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p greater than or equal to the square of it ; Store all prime numbers ; Function to check if a number is perfect square or not ; To store all primes ; To store all interseting primes ; Store all perfect squares ; Store all perfect quadruples ; Store all interseting primes ; Return count of interseting primes ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void SieveOfEratosthenes ( int n , HashSet < int > allPrimes ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } for ( int p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) allPrimes . Add ( p ) ; } static int countInterestingPrimes ( int n ) { HashSet < int > allPrimes = new HashSet < int > ( ) ; SieveOfEratosthenes ( n , allPrimes ) ; HashSet < int > intersetingPrimes = new HashSet < int > ( ) ; List < int > squares = new List < int > ( ) , quadruples = new List < int > ( ) ; for ( int i = 1 ; i * i <= n ; i ++ ) { squares . Add ( i * i ) ; } for ( int i = 1 ; i * i * i * i <= n ; i ++ ) { quadruples . Add ( i * i * i * i ) ; } foreach ( int a in squares ) { foreach ( int b in quadruples ) { if ( allPrimes . Contains ( a + b ) ) intersetingPrimes . Add ( a + b ) ; } } return intersetingPrimes . Count ; } public static void Main ( String [ ] args ) { int N = 10 ; Console . Write ( countInterestingPrimes ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check if K palindromic strings can be formed from a given string | C # program to check whether the string is K palindrome or not ; Function to check whether the string is K palindrome or not ; Map to frequency of character ; Check when k is given as same as length of string ; Storing the frequency of every character in map ; If K is greater than size of then return false ; Check that number of character having the odd frequency ; If k is less than number of odd frequency character then it is again false otherwise true ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static bool can_Construct ( String S , int K ) { Dictionary < char , int > m = new Dictionary < char , int > ( ) ; int p = 0 ; if ( S . Length == K ) return true ; for ( int i = 0 ; i < S . Length ; i ++ ) if ( ! m . ContainsKey ( S [ i ] ) ) m . Add ( S [ i ] , 1 ) ; else m [ S [ i ] ] = m [ S [ i ] ] + 1 ; if ( K > S . Length ) return false ; else { foreach ( int h in m . Values ) { if ( h % 2 != 0 ) p = p + 1 ; } } if ( K < p ) return false ; return true ; } public static void Main ( String [ ] args ) { String S = \\\" annabelle \\\" ; int K = 4 ; if ( can_Construct ( S , K ) ) Console . WriteLine ( \\\" Yes \\\" ) ; else Console . WriteLine ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Lagrange 's Interpolation | To represent a data point corresponding to x and y = f ( x ) ; function to interpolate the given data points using Lagrange 's formula xi -> corresponds to the new data point whose value is to be obtained n -> represents the number of known data points ; Initialize result ; Compute individual terms of above formula ; Add current term to result ; Driver Code ; creating an array of 4 known data points ; Using the interpolate function to obtain a data point corresponding to x = 3\\\"\\nHow can the above be solved in Python?\",\"targets\":\"class Data :\\n\\tdef __init__ ( self , x , y ) :\\n\\t\\tself . x = x\\n\\t\\tself . y = y\\ndef interpolate ( f : list , xi : int , n : int ) -> float :\\n\\tresult = 0.0\\n\\tfor i in range ( n ) :\\n\\t\\tterm = f [ i ] . y\\n\\t\\tfor j in range ( n ) :\\n\\t\\t\\tif j != i :\\n\\t\\t\\t\\tterm = term * ( xi - f [ j ] . x ) \\/ ( f [ i ] . x - f [ j ] . x )\\n\\t\\tresult += term\\n\\treturn result\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tf = [ Data ( 0 , 2 ) , Data ( 1 , 3 ) , Data ( 2 , 12 ) , Data ( 5 , 147 ) ]\\n\\tprint ( \\\" Value \u2581 of \u2581 f ( 3 ) \u2581 is \u2581 : \\\" , interpolate ( f , 3 , 4 ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count subarrays made up of single | Function to count of subarrays made up of single digit integers only ; Stores count of subarrays ; Stores the count of consecutive single digit numbers in the array ; Traverse the array ; Increment size of block by 1 ; Increment res by count ; Assign count = 0 ; Given array ; Size of the array\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function singleDigitSubarrayCount ( arr , N ) { let res = 0 ; let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] <= 9 ) { count ++ ; res += count ; } else { count = 0 ; } } document . write ( res ) ; } let arr = [ 0 , 1 , 14 , 2 , 5 ] ; let N = arr . length ; singleDigitSubarrayCount ( arr , N ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of points required to cover all blocks of a 2 | Function to find the minimum number of Polets required to cover a grid ; If number of block is even ; Return the minimum polets ; Given size of grid ; Function Call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function minPolets ( n , m ) { let ans = 0 ; if ( ( n % 2 != 0 ) && ( m % 2 != 0 ) ) { ans = Math . floor ( ( n * m ) \\/ 2 ) + 1 ; } else { ans = Math . floor ( ( n * m ) \\/ 2 ) ; } return ans ; } let N = 5 , M = 7 ; document . write ( minPolets ( N , M ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find the product of sum of two diagonals of a square Matrix | Function to find the product of the sum of diagonals . ; Initialize sums of diagonals ; Return the answer ; Driven code ; Function call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function product ( mat , n ) { let d1 = 0 , d2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { d1 += mat [ i ] [ i ] ; d2 += mat [ i ] [ n - i - 1 ] ; } return d1 * d2 ; } let mat = [ [ 5 , 8 , 1 ] , [ 5 , 10 , 3 ] , [ - 6 , 17 , - 9 ] ] ; let n = mat . length ; document . write ( product ( mat , n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count cubes of size K inscribed in a cube of size N | C ++ implementation of the above approach ; Function to find the number of the cubes of the size K ; Stores the number of cubes ; Stores the number of cubes of size k ; Driver Code ; Size of the bigger cube ; Size of the smaller cube\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int No_of_cubes ( int N , int K ) { int No = 0 ; No = ( N - K + 1 ) ; No = pow ( No , 3 ) ; return No ; } int main ( ) { int N = 5 ; int K = 2 ; cout << No_of_cubes ( N , K ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if a number is Bleak | Function to get no of set bits in binary representation of passed binary no . ; A function to return ceiling of log x in base 2. For example , it returns 3 for 8 and 4 for 9. ; Returns true if n is Bleak ; Check for all numbers ' x ' smaller than n . If x + countSetBits ( x ) becomes n , then n can 't be Bleak ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function countSetBits ( $ x ) { $ count = 0 ; while ( $ x ) { $ x &= ( $ x - 1 ) ; $ count ++ ; } return $ count ; } function ceilLog2 ( $ x ) { $ count = 0 ; $ x -- ; while ( $ x > 0 ) { $ x = $ x >> 1 ; $ count ++ ; } return $ count ; } function isBleak ( $ n ) { for ( $ x = $ n - ceilLog2 ( $ n ) ; $ x < $ n ; $ x ++ ) if ( $ x + countSetBits ( $ x ) == $ n ) return false ; return true ; } if ( isBleak ( 3 ) ) echo \\\" Yes \\n \\\" ; else echo \\\" No \\n \\\" ; if ( isBleak ( 4 ) ) echo \\\" Yes \\n \\\" ; else echo \\\" No \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Length of the perpendicular bisector of the line joining the centers of two circles | C # program to find the Length of the perpendicular bisector of the line joining the centers of two circles in which one lies completely inside touching the bigger circle at one point ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void lengperpbisect ( double r1 , double r2 ) { double z = 2 * Math . Sqrt ( ( r1 * r1 ) - ( ( r1 - r2 ) * ( r1 - r2 ) \\/ 4 ) ) ; Console . WriteLine ( \\\" The \u2581 length \u2581 of \u2581 the \u2581 \\\" + \\\" perpendicular \u2581 bisector \u2581 is \u2581 \\\" + z ) ; } public static void Main ( ) { double r1 = 5 , r2 = 3 ; lengperpbisect ( r1 , r2 ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find politeness of a number | python program for the above approach ; Function to find politeness ; sqrt ( 2 * n ) as max length will be when the sum starts from 1 which follows the equation n ^ 2 - n - ( 2 * sum ) = 0 ; Driver program to test above function\\\"\\nSolution in Python:\",\"targets\":\"import math\\ndef politness ( n ) :\\n\\tcount = 0\\n\\tfor i in range ( 2 , int ( math . sqrt ( 2 * n ) ) + 1 ) :\\n\\t\\tif ( ( 2 * n ) % i != 0 ) :\\n\\t\\t\\tcontinue\\n\\t\\ta = 2 * n\\n\\t\\ta = a \\/ i\\n\\t\\ta = a - ( i - 1 )\\n\\t\\tif ( a % 2 != 0 ) :\\n\\t\\t\\tcontinue\\n\\t\\ta \\/= 2\\n\\t\\tif ( a > 0 ) :\\n\\t\\t\\tcount = count + 1\\n\\treturn count\\nn = 90\\nprint \\\" Politness \u2581 of \u2581 \\\" , n , \\\" \u2581 = \u2581 \\\" , politness ( n )\\nn = 15\\nprint \\\" Politness \u2581 of \u2581 \\\" , n , \\\" \u2581 = \u2581 \\\" , politness ( n )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Number of occurrences of 2 as a digit in numbers from 0 to n | Counts the number of '2' digits in a single number ; Counts the number of '2' digits between 0 and n ; Initialize result ; Count 2 's in every number from 2 to n ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function number0f2s ( $ n ) { $ count = 0 ; while ( $ n > 0 ) { if ( $ n % 10 == 2 ) $ count ++ ; $ n = $ n \\/ 10 ; } return $ count ; } function numberOf2sinRange ( $ n ) { $ count = 0 ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) $ count += number0f2s ( $ i ) ; return $ count ; } echo ( numberOf2sinRange ( 22 ) ) ; echo \\\" \\n \\\" ; echo numberOf2sinRange ( 100 ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Increment a number by one by manipulating the bits | C # implementation to increment a number by one by manipulating the bits ; function to find the position of rightmost set bit ; function to toggle the last m bits ; calculating a number ' num ' having ' m ' bits and all are set ; toggle the last m bits and return the number ; function to increment a number by one by manipulating the bits ; get position of rightmost unset bit if all bits of ' n ' are set , then the bit left to the MSB is the rightmost unset bit ; kth bit of n is being set by this operation ; from the right toggle all the bits before the k - th bit ; required number ; Driver Program\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int getPosOfRightmostSetBit ( int n ) { return ( int ) ( Math . Log ( n & - n ) \\/ Math . Log ( 2 ) ) ; } static int toggleLastKBits ( int n , int k ) { int num = ( 1 << k ) - 1 ; return ( n ^ num ) ; } static int incrementByOne ( int n ) { int k = getPosOfRightmostSetBit ( ~ n ) ; n = ( ( 1 << k ) n ) ; if ( k != 0 ) n = toggleLastKBits ( n , k ) ; return n ; } public static void Main ( ) { int n = 15 ; Console . WriteLine ( incrementByOne ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Longest subsequence where each character occurs at least k times | Function to find the subsequence ; Taking an extra array to keep record for character count in s ; Counting occurrences of all characters in str [ ] ; Printing characters with count >= k in same order as they appear in str . ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function findSubsequence ( $ str , $ k ) { $ a = array ( 1024 ) ; for ( $ i = 0 ; $ i < 26 ; $ i ++ ) $ a [ $ i ] = 0 ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) { $ temp = ord ( $ str [ $ i ] ) - ord ( ' a ' ) ; $ a [ $ temp ] += 1 ; } for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) if ( $ a [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) ] >= $ k ) echo $ str [ $ i ] ; } $ k = 2 ; findSubsequence ( \\\" geeksforgeeks \\\" , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Trinomial Triangle | CPP Program to print trinomial triangle . ; Function to find the trinomial triangle value . ; Using property of trinomial triangle . ; If value already calculated , return that . ; base case ; base case ; recursive step and storing the value . ; Function to print Trinomial Triangle of height n . ; printing n rows . ; printing first half of triangle ; printing second half of triangle . ; Driven Program\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#define MAX 10\\nusing namespace std ; int TrinomialValue ( int dp [ MAX ] [ MAX ] , int n , int k ) { if ( k < 0 ) k = - k ; if ( dp [ n ] [ k ] != 0 ) return dp [ n ] [ k ] ; if ( n == 0 && k == 0 ) return 1 ; if ( k < - n k > n ) return 0 ; return ( dp [ n ] [ k ] = TrinomialValue ( dp , n - 1 , k - 1 ) + TrinomialValue ( dp , n - 1 , k ) + TrinomialValue ( dp , n - 1 , k + 1 ) ) ; } void printTrinomial ( int n ) { int dp [ MAX ] [ MAX ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = - i ; j <= 0 ; j ++ ) cout << TrinomialValue ( dp , i , j ) << \\\" \u2581 \\\" ; for ( int j = 1 ; j <= i ; j ++ ) cout << TrinomialValue ( dp , i , j ) << \\\" \u2581 \\\" ; cout << endl ; } } int main ( ) { int n = 4 ; printTrinomial ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count subarrays having an equal count of 0 s and 1 s segregated | Function to count subarrays having equal count of 0 s and 1 s with all 0 s and all 1 s grouped together ; Stores the count of subarrays ; If current element is different from the next array element ; Increment count ; Count the frequency of 1 s and 0 s ; Increment count ; Prlet the final count ; Driver Code ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function countSubarrays ( A , N ) { let ans = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] != A [ i + 1 ] ) { ans ++ ; for ( let j = i - 1 , k = i + 2 ; j >= 0 && k < N && A [ j ] == A [ i ] && A [ k ] == A [ i + 1 ] ; j -- , k ++ ) { ans ++ ; } } } document . write ( ans + \\\" \\\" ) ; } let A = [ 1 , 1 , 0 , 0 , 1 , 0 ] ; let N = A . length ; countSubarrays ( A , N ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program to find transpose of a matrix | javascript Program to find transpose of a matrix ; This function stores transpose of A in B ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"var M = 3 ; var N = 4 ; function transpose ( A , B ) { var i , j ; for ( i = 0 ; i < N ; i ++ ) for ( j = 0 ; j < M ; j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ; } var A = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] ] ; var B = Array ( N ) ; for ( i = 0 ; i < N ; i ++ ) B [ i ] = Array ( M ) . fill ( 0 ) ; transpose ( A , B ) ; document . write ( \\\" \\\" ) ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < M ; j ++ ) document . write ( B [ i ] [ j ] + \\\" \\\" ) ; document . write ( \\\" \\\" ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Decrypt a string encrypted by repeating i | Function to return the decrypted string ; Initial jump will be 1 ; Increment jump by 1 with every character ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def decryptString ( str , n ) :\\n\\ti = 0\\n\\tjump = 1\\n\\tdecryptedStr = \\\" \\\"\\n\\twhile ( i < n ) :\\n\\t\\tdecryptedStr += str [ i ] ;\\n\\t\\ti += jump\\n\\t\\tjump += 1\\n\\treturn decryptedStr\\nif __name__ == ' _ _ main _ _ ' :\\n\\tstr = \\\" geeeeekkkksssss \\\"\\n\\tn = len ( str )\\n\\tprint ( decryptString ( str , n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Reduce string by removing outermost parenthesis from each primitive substring | C # program to implement the above approach ; Function to remove the outermost parentheses of every primitive substring from the given string ; Stores the resultant string ; Stores the count of opened parentheses ; Traverse the string ; If opening parenthesis is encountered and their count exceeds 0 ; Include the character ; If closing parenthesis is encountered and their count is less than count of opening parentheses ; Include the character ; Return the resultant string ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static string removeOuterParentheses ( string S ) { string res = \\\" \\\" ; int count = 0 ; for ( int c = 0 ; c < S . Length ; c ++ ) { if ( S == ' ( ' && count ++ > 0 ) res += S ; if ( S == ' ) ' && count -- > 1 ) res += S ; } return res ; } public static void Main ( ) { string S = \\\" ( ( ) ( ) ) ( ( ) ) ( ) \\\" ; Console . Write ( removeOuterParentheses ( S ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count swaps required to sort an array using Insertion Sort | Stores the sorted array elements ; Function to count the number of swaps required to merge two sorted subarray in a sorted form ; Stores the count of swaps ; Function to count the total number of swaps required to sort the array ; Stores the total count of swaps required ; Find the middle index splitting the two halves ; Count the number of swaps required to sort the left subarray ; Count the number of swaps required to sort the right subarray ; Count the number of swaps required to sort the two sorted subarrays ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"let temp = new Array ( 100000 ) . fill ( 0 ) ; function merge ( A , left , mid , right ) { let swaps = 0 ; let i = left , j = mid , k = left ; while ( i < mid && j <= right ) { if ( A [ i ] <= A [ j ] ) { temp [ k ] = A [ i ] ; k ++ ; i ++ ; } else { temp [ k ] = A [ j ] ; k ++ ; j ++ ; swaps += mid - i ; } } while ( i < mid ) { temp [ k ] = A [ i ] ; k ++ ; i ++ ; } while ( j <= right ) { temp [ k ] = A [ j ] ; k ++ ; j ++ ; } while ( left <= right ) { A [ left ] = temp [ left ] ; left ++ ; } return swaps ; } function mergeInsertionSwap ( A , left , right ) { let swaps = 0 ; if ( left < right ) { let mid = left + ( right - left ) \\/ 2 ; swaps += mergeInsertionSwap ( A , left , mid ) ; swaps += mergeInsertionSwap ( A , mid + 1 , right ) ; swaps += merge ( A , left , mid + 1 , right ) ; } return swaps ; } let A = [ 2 , 1 , 3 , 1 , 2 ] ; let N = A . length ; document . write ( mergeInsertionSwap ( A , 0 , N - 1 ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Search an element in a Linked List ( Iterative and Recursive ) | Recursive C program to search an element in linked list ; Link list node ; Given a reference ( pointer to pointer ) to the head of a list and an int , push a new node on the front of the list . ; allocate node put in the key ; link the old list off the new node ; move the head to point to the new node ; Checks whether the value x is present in linked list ; Base case ; If key is present in current node , return true ; Recur for remaining list ; Driver program to test count function ; Start with the empty list ; Use push ( ) to construct below list 14 -> 21 -> 11 -> 30 -> 10\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\n#include \\nstruct Node { int key ; struct Node * next ; } ; void push ( struct Node * * head_ref , int new_key ) { struct Node * new_node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; new_node -> key = new_key ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } bool search ( struct Node * head , int x ) { if ( head == NULL ) return false ; if ( head -> key == x ) return true ; return search ( head -> next , x ) ; } int main ( ) { struct Node * head = NULL ; int x = 21 ; push ( & head , 10 ) ; push ( & head , 30 ) ; push ( & head , 11 ) ; push ( & head , 21 ) ; push ( & head , 14 ) ; search ( head , 21 ) ? printf ( \\\" Yes \\\" ) : printf ( \\\" No \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Queries to find the count of shortest paths in a Tree that contains a given edge | C # implementation for the above approach ; Adjacency list to represent the tree ; Number of vertices ; Mark visited \\/ unvisited vertices ; Stores the subtree size of the corresponding nodes ; Function to create an edge between two vertices ; Add a to b 's list ; Add b to a 's list ; Function to perform DFS ; Mark the vertex visited ; Include the node in the subtree ; Traverse all its children ; Function to print the required number of paths ; Driver Code ; Number of vertices ; Calling modified dfs function ; Count pairs of vertices in the tree\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int sz = ( int ) 1e5 ; static List < int > [ ] tree = new List < int > [ sz ] ; static int n ; static bool [ ] vis = new bool [ sz ] ; static int [ ] subtreeSize = new int [ sz ] ; static void addEdge ( int a , int b ) { tree [ a ] . Add ( b ) ; tree [ b ] . Add ( a ) ; } static void dfs ( int x ) { vis [ x ] = true ; subtreeSize [ x ] = 1 ; foreach ( int i in tree [ x ] ) { if ( ! vis [ i ] ) { dfs ( i ) ; subtreeSize [ x ] += subtreeSize [ i ] ; } } } static void countPairs ( int a , int b ) { int sub = Math . Min ( subtreeSize [ a ] , subtreeSize [ b ] ) ; Console . Write ( sub * ( n - sub ) + \\\" \\n \\\" ) ; } public static void Main ( String [ ] args ) { n = 6 ; for ( int i = 0 ; i < tree . Length ; i ++ ) tree [ i ] = new List < int > ( ) ; addEdge ( 0 , 1 ) ; addEdge ( 0 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 3 , 4 ) ; addEdge ( 3 , 5 ) ; dfs ( 0 ) ; countPairs ( 1 , 3 ) ; countPairs ( 0 , 2 ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Print characters and their frequencies in order of occurrence | PHP implementation to print the character and its frequency in order of its occurrence ; function to print the character and its frequency in order of its occurrence ; size of the string ' str ' ; ' freq [ ] ' implemented as hash table ; accumulate frequency of each character in ' str ' ; traverse ' str ' from left to right ; if frequency of character str [ i ] is not equal to 0 ; print the character along with its frequency ; update frequency of str [ i ] to 0 so that the same character is not printed again ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php $ SIZE = 26 ; function printCharWithFreq ( $ str ) { global $ SIZE ; $ n = strlen ( $ str ) ; $ freq = array_fill ( 0 , $ SIZE , NULL ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ freq [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) ] ++ ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ freq [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) ] != 0 ) { echo $ str [ $ i ] . $ freq [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) ] . \\\" \\\" ; $ freq [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) ] = 0 ; } } } $ str = \\\" geeksforgeeks \\\" ; printCharWithFreq ( $ str ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find sum in range L to R in given sequence of integers | C # program to find the sum in given range L to R ; Function to find the sum within the given range ; Generating array from given sequence ; Calculate the desired sum ; return the sum ; Driver code ; Initialise the range\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections ; class GFG { public static int findSum ( int L , int R ) { ArrayList arr = new ArrayList ( ) ; int i = 0 ; int x = 2 ; while ( i <= R ) { arr . Add ( i + x ) ; if ( i + 1 <= R ) arr . Add ( i + 1 + x ) ; x *= - 1 ; i += 2 ; } int sum = 0 ; for ( i = L ; i <= R ; ++ i ) sum += ( int ) arr [ i ] ; return sum ; } public static void Main ( string [ ] args ) { int L = 0 , R = 5 ; Console . Write ( findSum ( L , R ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count of Octal numbers upto N digits | Java program to find the count of natural octal numbers upto N digits ; Function to return the count of natural octal numbers upto N digits ; Loop to iterate from 1 to N and calculating number of octal numbers for every ' i ' th digit . ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"public class GFG { static int count ( int N ) { int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += 7 * Math . pow ( 8 , i - 1 ) ; } return sum ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( count ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sum of elements in given range from Array formed by infinitely concatenating given array | C ++ program for the above approach ; Function to find the sum of elements in a given range of an infinite array ; Stores the prefix sum ; Calculate the prefix sum ; Stores the sum of elements from 1 to L - 1 ; Stores the sum of elements from 1 to R ; Print the resultant sum ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void rangeSum ( int arr [ ] , int N , int L , int R ) { int prefix [ N + 1 ] ; prefix [ 0 ] = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] + arr [ i - 1 ] ; } int leftsum = ( ( L - 1 ) \\/ N ) * prefix [ N ] + prefix [ ( L - 1 ) % N ] ; int rightsum = ( R \\/ N ) * prefix [ N ] + prefix [ R % N ] ; cout << rightsum - leftsum ; } int main ( ) { int arr [ ] = { 5 , 2 , 6 , 9 } ; int L = 10 , R = 13 ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; rangeSum ( arr , N , L , R ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if given four integers ( or sides ) make rectangle | A simple program to find if given 4 values can represent 4 sides of rectangle ; Function to check if the given integers value make a rectangle ; Square is also a rectangle ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool isRectangle ( int a , int b , int c , int d ) { if ( a == b == c == d ) return true ; else if ( a == b && c == d ) return true ; else if ( a == d && c == b ) return true ; else if ( a == c && d == b ) return true ; else return false ; } int main ( ) { int a , b , c , d ; a = 1 , b = 2 , c = 3 , d = 4 ; if ( isRectangle ( a , b , c , d ) ) cout << \\\" Yes \\\" ; else cout << \\\" No \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"k | Javascript program to find k - th element in the Odd - Even sequence . ; insert all the odd numbers from 1 to n . ; insert all the even numbers from 1 to n . ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function findK ( n , k ) { let a = [ ] ; for ( let i = 1 ; i < n ; i ++ ) if ( i % 2 == 1 ) a . push ( i ) ; for ( let i = 1 ; i < n ; i ++ ) if ( i % 2 == 0 ) a . push ( i ) ; return ( a [ k - 1 ] ) ; } let n = 10 , k = 3 ; document . write ( findK ( n , k ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum flips required to generate continuous substrings of 0 \u00e2 \u20ac\u2122 s and 1 \u00e2 \u20ac\u2122 s | Java implementation of the above approach ; Traverse input string and store the count of 0 ; Traverse the input string again to find minimum number of flips ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int minChanges ( String str , int N ) { int res ; int count0 = 0 , count1 = 0 ; for ( char x : str . toCharArray ( ) ) { if ( x == '0' ) count0 ++ ; } res = count0 ; for ( char x : str . toCharArray ( ) ) { if ( x == '0' ) count0 -- ; if ( x == '1' ) count1 ++ ; res = Math . min ( res , count1 + count0 ) ; } return res ; } public static void main ( String [ ] args ) { int N = 9 ; String str = \\\"000101001\\\" ; System . out . println ( minChanges ( str , N ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimize cost to replace all the vowels of a given String by a single vowel | Java program for the above approach ; Function that return true if the given character is a vowel ; Function to return the minimum cost to convert all the vowels of a string to a single one ; Stores count of respective vowels ; Iterate through the string ; If a vowel is encountered ; Calculate the cost ; Return the minimum cost ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static boolean isVowel ( char ch ) { if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) return true ; else return false ; } static int minCost ( String S ) { int cA = 0 ; int cE = 0 ; int cI = 0 ; int cO = 0 ; int cU = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( isVowel ( S . charAt ( i ) ) ) { cA += Math . abs ( S . charAt ( i ) - ' a ' ) ; cE += Math . abs ( S . charAt ( i ) - ' e ' ) ; cI += Math . abs ( S . charAt ( i ) - ' i ' ) ; cO += Math . abs ( S . charAt ( i ) - ' o ' ) ; cU += Math . abs ( S . charAt ( i ) - ' u ' ) ; } } return Math . min ( Math . min ( Math . min ( Math . min ( cA , cE ) , cI ) , cO ) , cU ) ; } public static void main ( String [ ] args ) { String S = \\\" geeksforgeeks \\\" ; System . out . println ( minCost ( S ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to reach the nth stair using step 1 , 2 or 3 | A recursive function used by countWays ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function countWays ( $ n ) { $ res [ 0 ] = 1 ; $ res [ 1 ] = 1 ; $ res [ 2 ] = 2 ; for ( $ i = 3 ; $ i <= $ n ; $ i ++ ) $ res [ $ i ] = $ res [ $ i - 1 ] + $ res [ $ i - 2 ] + $ res [ $ i - 3 ] ; return $ res [ $ n ] ; } $ n = 4 ; echo countWays ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximize volume of cuboid with given sum of sides | Return the maximum volume . ; for length ; for breadth ; for height ; calculating maximum volume . ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function maxvolume ( $ s ) { $ maxvalue = 0 ; for ( $ i = 1 ; $ i <= $ s - 2 ; $ i ++ ) { for ( $ j = 1 ; $ j <= $ s - 1 ; $ j ++ ) { $ k = $ s - $ i - $ j ; $ maxvalue = max ( $ maxvalue , $ i * $ j * $ k ) ; } } return $ maxvalue ; } $ s = 8 ; echo ( maxvolume ( $ s ) ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to find whether a no is power of two | Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function isPowerOfTwo ( $ x ) { return $ x && ( ! ( $ x & ( $ x - 1 ) ) ) ; } if ( isPowerOfTwo ( 31 ) ) echo \\\" Yes \\n \\\" ; else echo \\\" No \\n \\\" ; if ( isPowerOfTwo ( 64 ) ) echo \\\" Yes \\n \\\" ; else echo \\\" No \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the element in the matrix generated by given rules | Function to return the element in the rth row and cth column from the required matrix ; Condition for lower half of matrix ; Condition if element is in first row ; Starting element of AP in row r ; Common difference of AP in row r ; Position of element to find in AP in row r ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function getElement ( N , r , c ) { if ( r > c ) return 0 ; if ( r == 1 ) { return c ; } let a = ( r + 1 ) * parseInt ( Math . pow ( 2 , ( r - 2 ) ) ) ; let d = parseInt ( Math . pow ( 2 , ( r - 1 ) ) ) ; c = c - r ; let element = a + d * c ; return element ; } let N = 4 , R = 3 , C = 4 ; document . write ( getElement ( N , R , C ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Print string of odd length in ' X ' format | Function to print given string in cross pattern ; i and j are the indexes of characters to be displayed in the ith iteration i = 0 initially and go upto length of string j = length of string initially in each iteration of i , we increment i and decrement j , we print character only of k == i or k == j ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function pattern ( $ str , $ len ) { for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ j = $ len - 1 - $ i ; for ( $ k = 0 ; $ k < $ len ; $ k ++ ) { if ( $ k == $ i $ k == $ j ) echo $ str [ $ k ] ; else echo \\\" \u2581 \\\" ; } echo \\\" \\n \\\" ; } } $ str = \\\" geeksforgeeks \\\" ; $ len = strlen ( $ str ) ; pattern ( $ str , $ len ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Lexicographically smallest binary string formed by flipping bits at indices not divisible K1 or K2 such that count of 1 s is always greater than 0 s from left | C # program for the above approach ; Function to find lexicographically smallest String having number of 1 s greater than number of 0 s ; C1s And C0s stores the count of 1 s and 0 s at every position ; Traverse the String S ; If the position is not divisible by k1 and k2 ; If C0s >= C1s and pos [ ] is empty then the String can 't be formed ; If pos [ ] is not empty then flip the bit of last position present in pos [ ] ; Print the result ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void generateString ( int k1 , int k2 , char [ ] s ) { int C1s = 0 , C0s = 0 ; int flag = 0 ; List < int > pos = new List < int > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ i ] == '0' ) { C0s ++ ; if ( ( i + 1 ) % k1 != 0 && ( i + 1 ) % k2 != 0 ) { pos . Add ( i ) ; } } else { C1s ++ ; } if ( C0s >= C1s ) { if ( pos . Count == 0 ) { Console . WriteLine ( - 1 ) ; flag = 1 ; break ; } else { int k = pos [ ( pos . Count - 1 ) ] ; s [ k ] = '1' ; C0s -- ; C1s ++ ; pos . Remove ( pos . Count - 1 ) ; } } } if ( flag == 0 ) { Console . WriteLine ( s ) ; } } public static void Main ( ) { int K1 = 2 , K2 = 4 ; string S = \\\"11000100\\\" ; generateString ( K1 , K2 , S . ToCharArray ( ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximum count of common divisors of A and B such that all are co | Python3 implementation of the approach ; Function to return the count of common factors of a and b such that all the elements are co - prime to one another ; GCD of a and b ; Include 1 initially ; Find all the prime factors of the gcd ; If gcd is prime ; Return the required answer ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import math\\ndef maxCommonFactors ( a , b ) :\\n\\tgcd = math . gcd ( a , b )\\n\\tans = 1 ;\\n\\ti = 2\\n\\twhile ( i * i <= gcd ) :\\n\\t\\tif ( gcd % i == 0 ) :\\n\\t\\t\\tans += 1\\n\\t\\t\\twhile ( gcd % i == 0 ) :\\n\\t\\t\\t\\tgcd = gcd \\/\\/ i\\n\\t\\ti += 1\\n\\tif ( gcd != 1 ) :\\n\\t\\tans += 1\\n\\treturn ans\\na = 12\\nb = 18\\nprint ( maxCommonFactors ( a , b ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check for Majority Element in a sorted array | C Program to check for majority element in a sorted array ; If x is present in arr [ low ... high ] then returns the index of first occurrence of x , otherwise returns - 1 ; Check if arr [ mid ] is the first occurrence of x . arr [ mid ] is first occurrence if x is one of the following is true : ( i ) mid == 0 and arr [ mid ] = = x ( ii ) arr [ mid - 1 ] < x and arr [ mid ] == x ; This function returns true if the x is present more than n \\/ 2 times in arr [ ] of size n ; Find the index of first occurrence of x in arr [ ] ; If element is not present at all , return false ; check if the element is present more than n \\/ 2 times ; Driver program to check above functions\\\"\\nSolution in C:\",\"targets\":\"# include \\n# include \\nint _binarySearch ( int arr [ ] , int low , int high , int x ) { if ( high >= low ) { int mid = ( low + high ) \\/ 2 ; if ( ( mid == 0 x > arr [ mid - 1 ] ) && ( arr [ mid ] == x ) ) return mid ; else if ( x > arr [ mid ] ) return _binarySearch ( arr , ( mid + 1 ) , high , x ) ; else return _binarySearch ( arr , low , ( mid - 1 ) , x ) ; } return -1 ; } bool isMajority ( int arr [ ] , int n , int x ) { int i = _binarySearch ( arr , 0 , n - 1 , x ) ; if ( i == -1 ) return false ; if ( ( ( i + n \\/ 2 ) <= ( n - 1 ) ) && arr [ i + n \\/ 2 ] == x ) return true ; else return false ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 3 , 3 , 3 , 10 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int x = 3 ; if ( isMajority ( arr , n , x ) ) printf ( \\\" % d \u2581 appears \u2581 more \u2581 than \u2581 % d \u2581 times \u2581 in \u2581 arr [ ] \\\" , x , n \\/ 2 ) ; else printf ( \\\" % d \u2581 does \u2581 not \u2581 appear \u2581 more \u2581 than \u2581 % d \u2581 times \u2581 in \u2581 arr [ ] \\\" , x , n \\/ 2 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find sum of divisors of all the divisors of a natural number | C # program to find sum of divisors of all the divisors of a natural number . ; Returns sum of divisors of all the divisors of n ; Calculating powers of prime factors and storing them in a map mp [ ] . ; If n is a prime number ; For each prime factor , calculating ( p ^ ( a + 1 ) - 1 ) \\/ ( p - 1 ) and adding it to answer . ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { public static int sumDivisorsOfDivisors ( int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int j = 2 ; j <= Math . Sqrt ( n ) ; j ++ ) { int count = 0 ; while ( n % j == 0 ) { n \\/= j ; count ++ ; } if ( count != 0 ) mp . Add ( j , count ) ; } if ( n != 1 ) mp . Add ( n , 1 ) ; int ans = 1 ; foreach ( KeyValuePair < int , int > entry in mp ) { int pw = 1 ; int sum = 0 ; for ( int i = entry . Value + 1 ; i >= 1 ; i -- ) { sum += ( i * pw ) ; pw = entry . Key ; } ans *= sum ; } return ans ; } public static void Main ( String [ ] args ) { int n = 10 ; Console . WriteLine ( sumDivisorsOfDivisors ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"Find the smallest positive number missing from an unsorted array | Set 1 | C program to find the smallest positive missing number ; Utility to swap to integers ; Utility function that puts all non - positive ( 0 and negative ) numbers on left side of arr [ ] and return count of such numbers ; increment count of non - positive integers ; Find the smallest positive missing number in an array that contains all positive integers ; Mark arr [ i ] as visited by making arr [ arr [ i ] - 1 ] negative . Note that 1 is subtracted because index start from 0 and positive numbers start from 1 ; Return the first index value at which is positive ; 1 is added because indexes start from 0 ; Find the smallest positive missing number in an array that contains both positive and negative integers ; First separate positive and negative numbers ; Shift the array and call findMissingPositive for positive part ; Driver code\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nvoid swap ( int * a , int * b ) { int temp ; temp = * a ; * a = * b ; * b = temp ; } int segregate ( int arr [ ] , int size ) { int j = 0 , i ; for ( i = 0 ; i < size ; i ++ ) { if ( arr [ i ] <= 0 ) { swap ( & arr [ i ] , & arr [ j ] ) ; j ++ ; } } return j ; } int findMissingPositive ( int arr [ ] , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) { if ( abs ( arr [ i ] ) - 1 < size && arr [ abs ( arr [ i ] ) - 1 ] > 0 ) arr [ abs ( arr [ i ] ) - 1 ] = - arr [ abs ( arr [ i ] ) - 1 ] ; } for ( i = 0 ; i < size ; i ++ ) if ( arr [ i ] > 0 ) return i + 1 ; return size + 1 ; } int findMissing ( int arr [ ] , int size ) { int shift = segregate ( arr , size ) ; return findMissingPositive ( arr + shift , size - shift ) ; } int main ( ) { int arr [ ] = { 0 , 10 , 2 , -10 , -20 } ; int arr_size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int missing = findMissing ( arr , arr_size ) ; printf ( \\\" The \u2581 smallest \u2581 positive \u2581 missing \u2581 number \u2581 is \u2581 % d \u2581 \\\" , missing ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Generate all integral points lying inside a rectangle | C # program to implement the above approach ; Function to generate coordinates lying within the rectangle ; Store all possible coordinates that lie within the rectangle ; Stores the number of possible coordinates that lie within the rectangle ; For random generator ; Generate all possible coordinates ; Generate all possible X - coordinates ; Generate all possible Y - coordinates ; If coordinates ( X , Y ) has not been generated already ; Insert the coordinates ( X , Y ) ; Print the coordinates ; Driver Code ; Rectangle dimensions\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections ; using System . Collections . Generic ; class GFG { public class store : IComparer < KeyValuePair < int , int > > { public int Compare ( KeyValuePair < int , int > x , KeyValuePair < int , int > y ) { if ( x . Key != y . Key ) { return x . Key . CompareTo ( y . Key ) ; } else { return x . Value . CompareTo ( y . Value ) ; } } } static void generatePoints ( int L , int W ) { SortedSet < KeyValuePair < int , int > > hash = new SortedSet < KeyValuePair < int , int > > ( new store ( ) ) ; int total = ( L * W ) ; Random rand = new Random ( ) ; while ( ( total -- ) != 0 ) { int X = rand . Next ( ) % L ; int Y = rand . Next ( ) % W ; while ( hash . Contains ( new KeyValuePair < int , int > ( X , Y ) ) ) { X = rand . Next ( ) % L ; Y = rand . Next ( ) % W ; } hash . Add ( new KeyValuePair < int , int > ( X , Y ) ) ; } foreach ( KeyValuePair < int , int > x in hash ) { Console . Write ( \\\" ( \\\" + x . Key + \\\" , \u2581 \\\" + x . Value + \\\" ) \u2581 \\\" ) ; } } public static void Main ( string [ ] args ) { int L = 3 , W = 2 ; generatePoints ( L , W ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Convert given integer X to the form 2 ^ N | C ++ implementation of the approach ; Function to return the count of operations required ; To store the powers of 2 ; Temporary variable to store x ; To store the index of smaller number larger than x ; To store the count of operations ; Stores the index of number in the form of 2 ^ n - 1 ; If x is already in the form 2 ^ n - 1 then no operation is required ; If number is less than x increase the index ; Calculate all the values ( x xor 2 ^ n - 1 ) for all possible n ; Only take value which is closer to the number ; If number is in the form of 2 ^ n - 1 then break ; Return the count of operations required to obtain the number ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; const int MAX = 24 ; int countOp ( int x ) { int arr [ MAX ] ; arr [ 0 ] = 1 ; for ( int i = 1 ; i < MAX ; i ++ ) arr [ i ] = arr [ i - 1 ] * 2 ; int temp = x ; bool flag = true ; int ans ; int operations = 0 ; bool flag2 = false ; for ( int i = 0 ; i < MAX ; i ++ ) { if ( arr [ i ] - 1 == x ) flag2 = true ; if ( arr [ i ] > x ) { ans = i ; break ; } } if ( flag2 ) return 0 ; while ( flag ) { if ( arr [ ans ] < x ) ans ++ ; operations ++ ; for ( int i = 0 ; i < MAX ; i ++ ) { int take = x ^ ( arr [ i ] - 1 ) ; if ( take <= arr [ ans ] - 1 ) { if ( take > temp ) temp = take ; } } if ( temp == arr [ ans ] - 1 ) { flag = false ; break ; } temp ++ ; operations ++ ; x = temp ; if ( x == arr [ ans ] - 1 ) flag = false ; } return operations ; } int main ( ) { int x = 39 ; cout << countOp ( x ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Reverse words in a given string | C program for above approach : ; temp is for word boundary ; STEP 1 of the above algorithm ; This condition is to make sure that the string start with valid character ( not space ) only ; STEP 2 of the above algorithm\\nHow can the above be solved in C?\",\"targets\":\"void reverseWords ( char * s ) { char * word_begin = NULL ; char * temp = s ; while ( * temp ) { if ( ( word_begin == NULL ) && ( * temp != ' \u2581 ' ) ) { word_begin = temp ; } if ( word_begin && ( ( * ( temp + 1 ) == ' \u2581 ' ) || ( * ( temp + 1 ) == ' \\\\0' ) ) ) { reverse ( word_begin , temp ) ; word_begin = NULL ; } temp ++ ; } reverse ( s , temp - 1 ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimize number of cuts required to break N length stick into N unit length sticks | C # program to find minimum time required to split a stick of N length into unit pieces ; Function to return the minimum time required to split stick of N into length into unit pieces ; Return the minimum unit of time required ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int min_time_to_cut ( int N ) { if ( N == 0 ) return 0 ; return ( int ) Math . Ceiling ( Math . Log ( N ) \\/ Math . Log ( 2 ) ) ; } public static void Main ( ) { int N = 100 ; Console . Write ( min_time_to_cut ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Angle between 3 given vertices in a n | Function that checks whether given angle can be created using any 3 sides ; Initialize x and y ; Calculate the number of vertices between i and j , j and k ; Calculate the angle subtended at the circumference ; Angle subtended at j can be found using the fact that the sum of angles of a triangle is equal to 180 degrees ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def calculate_angle ( n , i , j , k ) :\\n\\tx , y = 0 , 0\\n\\tif ( i < j ) :\\n\\t\\tx = j - i\\n\\telse :\\n\\t\\tx = j + n - i\\n\\tif ( j < k ) :\\n\\t\\ty = k - j\\n\\telse :\\n\\t\\ty = k + n - j\\n\\tang1 = ( 180 * x ) \\/\\/ n\\n\\tang2 = ( 180 * y ) \\/\\/ n\\n\\tans = 180 - ang1 - ang2\\n\\treturn ans\\nn = 5\\na1 = 1\\na2 = 2\\na3 = 5\\nprint ( calculate_angle ( n , a1 , a2 , a3 ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if a string has all characters with same frequency with one variation allowed | To check a string S can be converted to a variation string ; Run loop form 0 to length of string ; declaration of variables ; if first is true than countOfVal1 increase ; if second is true than countOfVal2 increase ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def checkForVariation ( strr ) :\\n\\tif ( len ( strr ) == 0 ) :\\n\\t\\treturn True\\n\\tmapp = { }\\n\\tfor i in range ( len ( strr ) ) :\\n\\t\\tif strr [ i ] in mapp :\\n\\t\\t\\tmapp [ strr [ i ] ] += 1\\n\\t\\telse :\\n\\t\\t\\tmapp [ strr [ i ] ] = 1\\n\\tfirst = True\\n\\tsecond = True\\n\\tval1 = 0\\n\\tval2 = 0\\n\\tcountOfVal1 = 0\\n\\tcountOfVal2 = 0\\n\\tfor itr in mapp :\\n\\t\\ti = itr\\n\\t\\tif ( first ) :\\n\\t\\t\\tval1 = i\\n\\t\\t\\tfirst = False\\n\\t\\t\\tcountOfVal1 += 1\\n\\t\\t\\tcontinue\\n\\t\\tif ( i == val1 ) :\\n\\t\\t\\tcountOfVal1 += 1\\n\\t\\t\\tcontinue\\n\\t\\tif ( second ) :\\n\\t\\t\\tval2 = i\\n\\t\\t\\tcountOfVal2 += 1\\n\\t\\t\\tsecond = False\\n\\t\\t\\tcontinue\\n\\t\\tif ( i == val2 ) :\\n\\t\\t\\tcountOfVal2 += 1\\n\\t\\t\\tcontinue\\n\\tif ( countOfVal1 > 1 and countOfVal2 > 1 ) :\\n\\t\\treturn False\\n\\telse :\\n\\t\\treturn True\\nprint ( checkForVariation ( \\\" abcbc \\\" ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Combinatorics on ordered trees | Function returns value of Binomial Coefficient C ( n , k ) ; Calculate value of Binomial Coefficient in bottom up manner ; Base Cases ; Calculate value using previously stored values ; Function to calculate the number of trees with exactly k leaves . ; Function to calculate total number of nodes of degree d in these trees . ; Function to calculate the number of trees in which the root has degree r . ; Driver program to test above functions Number of trees having 3 edges and exactly 2 leaves ; Number of nodes of degree 3 in a tree having 4 edges ; Number of trees having 3 edges where root has degree 2\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function binomialCoeff ( $ n , $ k ) { $ C = array ( array ( ) ) ; $ i ; $ j ; for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) { for ( $ j = 0 ; $ j <= min ( $ i , $ k ) ; $ j ++ ) { if ( $ j == 0 or $ j == $ i ) $ C [ $ i ] [ $ j ] = 1 ; else $ C [ $ i ] [ $ j ] = $ C [ $ i - 1 ] [ $ j - 1 ] + $ C [ $ i - 1 ] [ $ j ] ; } } return $ C [ $ n ] [ $ k ] ; } function k_Leaves ( $ n , $ k ) { $ ans = ( binomialCoeff ( $ n , $ k ) * binomialCoeff ( $ n , $ k - 1 ) ) \\/ $ n ; echo \\\" Number \u2581 of \u2581 trees \u2581 having \u2581 4 \u2581 edges \u2581 and \u2581 \\\" , \\\" exactly \u2581 2 \u2581 leaves \u2581 : \u2581 \\\" , $ ans , \\\" \\n \\\" ; return 0 ; } function numberOfNodes ( $ n , $ d ) { $ ans = binomialCoeff ( 2 * $ n - 1 - $ d , $ n - 1 ) ; echo \\\" Number \u2581 of \u2581 nodes \u2581 of \u2581 degree \u2581 1 \u2581 in \\\" , \\\" \u2581 a \u2581 tree \u2581 having \u2581 4 \u2581 edges \u2581 : \u2581 \\\" , $ ans , \\\" \\n \\\" ; return 0 ; } function rootDegreeR ( $ n , $ r ) { $ ans = $ r * binomialCoeff ( 2 * $ n - 1 - $ r , $ n - 1 ) ; $ ans = $ ans \\/ $ n ; echo \\\" Number \u2581 of \u2581 trees \u2581 having \u2581 4 \u2581 edges \\\" , \\\" \u2581 where \u2581 root \u2581 has \u2581 degree \u2581 2 \u2581 : \u2581 \\\" , $ ans ; return 0 ; } k_Leaves ( 3 , 2 ) ; numberOfNodes ( 3 , 1 ) ; rootDegreeR ( 3 , 2 ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Count number of rotated strings which have more number of vowels in the first half than second half | C implementation of the approach ; Function to return the count of rotated strings which have more number of vowels in the first half than the second half ; Compute the number of vowels in first - half ; Compute the number of vowels in second - half ; Check if first - half has more vowels ; Check for all possible rotations ; Return the answer ; Driver code ; Function call\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nint cntRotations ( char s [ ] , int n ) { int lh = 0 , rh = 0 , i , ans = 0 ; for ( i = 0 ; i < n \\/ 2 ; ++ i ) if ( s [ i ] == ' a ' s [ i ] == ' e ' s [ i ] == ' i ' s [ i ] == ' o ' s [ i ] == ' u ' ) { lh ++ ; } for ( i = n \\/ 2 ; i < n ; ++ i ) if ( s [ i ] == ' a ' s [ i ] == ' e ' s [ i ] == ' i ' s [ i ] == ' o ' s [ i ] == ' u ' ) { rh ++ ; } if ( lh > rh ) ans ++ ; for ( i = 1 ; i < n ; ++ i ) { if ( s [ i - 1 ] == ' a ' s [ i - 1 ] == ' e ' s [ i - 1 ] == ' i ' s [ i - 1 ] == ' o ' s [ i - 1 ] == ' u ' ) { rh ++ ; lh -- ; } if ( s [ ( i - 1 + n \\/ 2 ) % n ] == ' a ' || s [ ( i - 1 + n \\/ 2 ) % n ] == ' e ' || s [ ( i - 1 + n \\/ 2 ) % n ] == ' i ' || s [ ( i - 1 + n \\/ 2 ) % n ] == ' o ' || s [ ( i - 1 + n \\/ 2 ) % n ] == ' u ' ) { rh -- ; lh ++ ; } if ( lh > rh ) ans ++ ; } return ans ; } int main ( ) { char s [ ] = \\\" abecidft \\\" ; int n = strlen ( s ) ; printf ( \\\" % d \\\" , cntRotations ( s , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Write a program to calculate pow ( x , n ) | Extended version of power function that can work for float x and negative y ; Program to test function power\\\"\\nSolution in C:\",\"targets\":\"#include \\nfloat power ( float x , int y ) { float temp ; if ( y == 0 ) return 1 ; temp = power ( x , y \\/ 2 ) ; if ( y % 2 == 0 ) return temp * temp ; else { if ( y > 0 ) return x * temp * temp ; else return ( temp * temp ) \\/ x ; } } int main ( ) { float x = 2 ; int y = -3 ; printf ( \\\" % f \\\" , power ( x , y ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Space and time efficient Binomial Coefficient | Program to calculate C ( n , k ) ; Returns value of Binomial Coefficient C ( n , k ) ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] \\/ [ k * ( k - 1 ) * -- -- * 1 ] ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\nint binomialCoeff ( int n , int k ) { int res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res \\/= ( i + 1 ) ; } return res ; } int main ( ) { int n = 8 , k = 2 ; printf ( \\\" Value \u2581 of \u2581 C ( % d , \u2581 % d ) \u2581 is \u2581 % d \u2581 \\\" , n , k , binomialCoeff ( n , k ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Longest alternating sub | Function to calculate alternating sub - array for each index of array elements ; Initialize count variable for storing length of sub - array ; Initialize ' prev ' variable which indicates the previous element while traversing for index ' i ' ; If both elements are same print elements because alternate element is not found for current index ; print count and decrement it . ; Increment count for next element ; Re - initialize previous variable ; If elements are still available after traversing whole array , print it ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function alternateSubarray ( $ arr , $ n ) { $ count = 1 ; $ prev = $ arr [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; ++ $ i ) { if ( ( $ arr [ $ i ] ^ $ prev ) == 0 ) { while ( $ count ) echo $ count -- , \\\" \u2581 \\\" ; } ++ $ count ; $ prev = $ arr [ $ i ] ; } while ( $ count ) echo $ count -- , \\\" \u2581 \\\" ; } $ arr = array ( 1 , 0 , 1 , 0 , 0 , 1 ) ; $ n = sizeof ( $ arr ) ; alternateSubarray ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if N is a Factorial Prime | Utility function to check if a number is prime or not ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function that returns true if n is a factorial prime ; If n is not prime then return false ; Calculate factorial ; If n is a factorial prime ; n is not a factorial prime ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function isPrime ( $ n ) { if ( $ n <= 1 ) return false ; if ( $ n <= 3 ) return true ; if ( $ n % 2 == 0 $ n % 3 == 0 ) return false ; for ( $ i = 5 ; $ i * $ i <= $ n ; $ i = $ i + 6 ) if ( $ n % $ i == 0 || $ n % ( $ i + 2 ) == 0 ) return false ; return true ; } function isFactorialPrime ( $ n ) { if ( ! isPrime ( $ n ) ) return false ; $ fact = 1 ; $ i = 1 ; while ( $ fact <= $ n + 1 ) { $ fact = $ fact * $ i ; if ( $ n + 1 == $ fact $ n - 1 == $ fact ) return true ; $ i ++ ; } return false ; } $ n = 23 ; if ( isFactorialPrime ( $ n ) ) echo \\\" Yes \\\" ; else echo \\\" No \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count of contiguous subarrays possible for every index by including the element at that index | C # program to find the number of contiguous subarrays including the element at every index of the array of size N ; Function to find the number of subarrays including the element at every index of the array ; Creating an array of size N ; The loop is iterated till half the length of the array ; Condition to avoid overwriting the middle element for the array with even length . ; Computing the number of subarrays ; The ith element from the beginning and the ending have the same number of possible subarray ; Function to print the vector ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { public static int [ ] calculateWays ( int N ) { int x = 0 ; int [ ] v = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) v [ i ] = 0 ; for ( int i = 0 ; i < N \\/ 2 ; i ++ ) { if ( N % 2 == 0 && i == N \\/ 2 ) break ; x = N * ( i + 1 ) - ( i + 1 ) * i ; v [ i ] = x ; v [ N - i - 1 ] = x ; } return v ; } public static void printArray ( int [ ] v ) { for ( int i = 0 ; i < v . Length ; i ++ ) { Console . Write ( v [ i ] + \\\" \u2581 \\\" ) ; } } public static void Main ( string [ ] args ) { int [ ] v ; v = calculateWays ( 4 ) ; printArray ( v ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximize sum by selecting M elements from the start or end of rows of a Matrix | Java program for the above approach ; Function to select m elements having maximum sum ; Base case ; If precomputed subproblem occurred ; Either skip the current row ; Iterate through all the possible segments of current row ; Check if it is possible to select elements from i to j ; Compuete the sum of i to j as calculated ; Store the computed answer and return ; Function to precompute the prefix sum for every row of the matrix ; Preprocessing to calculate sum from i to j ; Utility function to select m elements having maximum sum ; Preprocessing step ; Initialize dp array with - 1 ; Stores maximum sum of M elements ; Driver Code ; Given N ; Given M ; Given matrix ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; public class GFG { public static long mElementsWithMaxSum ( long [ ] [ ] matrix , int M , int block , long [ ] [ ] dp ) { if ( block == matrix . length ) return 0 ; if ( dp [ block ] [ M ] != - 1 ) return dp [ block ] [ M ] ; long ans = mElementsWithMaxSum ( matrix , M , block + 1 , dp ) ; for ( int i = 0 ; i < matrix [ block ] . length ; i ++ ) { for ( int j = i ; j < matrix [ block ] . length ; j ++ ) { if ( j - i + 1 <= M ) { ans = Math . max ( ans , matrix [ block ] [ j ] - ( ( i - 1 ) >= 0 ? matrix [ block ] [ i - 1 ] : 0 ) + mElementsWithMaxSum ( matrix , M - j + i - 1 , block + 1 , dp ) ) ; } } } return dp [ block ] [ M ] = ans ; } public static void preComputing ( long [ ] [ ] matrix , int N ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < matrix [ i ] . length ; j ++ ) { matrix [ i ] [ j ] = ( j > 0 ? matrix [ i ] [ j - 1 ] : 0 ) + matrix [ i ] [ j ] ; } } } public static void mElementsWithMaxSumUtil ( long [ ] [ ] matrix , int M , int N ) { preComputing ( matrix , N ) ; long dp [ ] [ ] = new long [ N + 5 ] [ M + 5 ] ; for ( long i [ ] : dp ) Arrays . fill ( i , - 1 ) ; long sum = mElementsWithMaxSum ( matrix , M , 0 , dp ) ; System . out . print ( sum ) ; } public static void main ( String args [ ] ) { int N = 3 ; int M = 4 ; long [ ] [ ] matrix = { { 2 , 3 , 5 } , { - 1 , 7 } , { 8 , 10 } } ; mElementsWithMaxSumUtil ( matrix , M , N ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if string is right to left diagonal or not | C ++ program to Check if the given string is right to left diagonal or not ; Function to check if the given string is right to left diagonal or not ; Iterate over string ; If character is not same as the first character then return false ; Driver Code ; Given String str ; Function Call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int is_rtol ( string s ) { int tmp = sqrt ( s . length ( ) ) - 1 ; char first = s [ tmp ] ; for ( int pos = tmp ; pos < s . length ( ) - 1 ; pos += tmp ) { if ( s [ pos ] != first ) { return false ; } } return true ; } int main ( ) { string str = \\\" abcxabxcaxbcxabc \\\" ; if ( is_rtol ( str ) ) { cout << \\\" Yes \\\" << endl ; } else { cout << \\\" No \\\" << endl ; } return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Length of longest common prefix possible by rearranging strings in a given array | Python3 program to implement the above approach ; Function to get the length of the longest common prefix by rearranging the strings ; freq [ i ] [ j ] : stores the frequency of a character ( = j ) in a arr [ i ] ; Traverse the given array ; Stores length of current string ; Traverse current string of the given array ; Update the value of freq [ i ] [ arr [ i ] [ j ] ] ; Stores the length of longest common prefix ; Count the minimum frequency of each character in in all the strings of arr [ ] ; Stores minimum value in each row of freq [ ] [ ] ; Calculate minimum frequency of current character in all the strings . ; Update minRowVal ; Update maxLen ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"import sys\\ndef longComPre ( arr , N ) :\\n\\tfreq = [ [ 0 for i in range ( 256 ) ] for i in range ( N ) ]\\n\\tfor i in range ( N ) :\\n\\t\\tM = len ( arr [ i ] )\\n\\t\\tfor j in range ( M ) :\\n\\t\\t\\tfreq [ i ] [ ord ( arr [ i ] [ j ] ) ] += 1\\n\\tmaxLen = 0\\n\\tfor j in range ( 256 ) :\\n\\t\\tminRowVal = sys . maxsize\\n\\t\\tfor i in range ( N ) :\\n\\t\\t\\tminRowVal = min ( minRowVal , freq [ i ] [ j ] )\\n\\t\\tmaxLen += minRowVal\\n\\treturn maxLen\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ \\\" aabdc \\\" , \\\" abcd \\\" , \\\" aacd \\\" ]\\n\\tN = 3\\n\\tprint ( longComPre ( arr , N ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimum time required to print given string from a circular container based on given conditions | C # implementation for the above approach ; Function to calculate minimum time to print all characters in the string ; Current element where the pointer is pointing ; Find index of that element ; Calculate absolute difference between pointer index and character index as clockwise distance ; Subtract clockwise time from 26 to get anti - clockwise time ; Add minimum of both times to the answer ; Add one unit time to print the character ; Print the final answer ; Driver code ; Given string word ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void minTime ( string word ) { int ans = 0 ; int curr = 0 ; for ( int i = 0 ; i < word . Length ; i ++ ) { int k = ( int ) word [ i ] - 97 ; int a = Math . Abs ( curr - k ) ; int b = 26 - Math . Abs ( curr - k ) ; ans += Math . Min ( a , b ) ; ans ++ ; curr = ( int ) word [ i ] - 97 ; } Console . Write ( ans ) ; } public static void Main ( ) { string str = \\\" zjpc \\\" ; minTime ( str ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Rearrange a given linked list in | Python3 implementation ; ; Function to print the list ; Function to rearrange ; We set left = null , when we reach stop condition , so no processing required after that ; Stop condition : odd case : left = right , even case : left . next = right ; Stop condition , set null to left nodes ; Even case ; Odd case ; Driver code ; Print original list ; Modify the list ; Print modified list\\\"\\nHow can the above be solved in Python?\",\"targets\":\"class Node :\\n\\tdef __init__ ( self , key ) :\\n\\t\\tself . data = key\\n\\t\\tself . next = None\\nleft = None\\ndef printlist ( head ) :\\n\\twhile ( head != None ) :\\n\\t\\tprint ( head . data , end = \\\" \u2581 \\\" )\\n\\t\\tif ( head . next != None ) :\\n\\t\\t\\tprint ( \\\" - > \\\" , end = \\\" \\\" )\\n\\t\\thead = head . next\\n\\tprint ( )\\ndef rearrange ( head ) :\\n\\tglobal left\\n\\tif ( head != None ) :\\n\\t\\tleft = head\\n\\t\\treorderListUtil ( left )\\ndef reorderListUtil ( right ) :\\n\\tglobal left\\n\\tif ( right == None ) :\\n\\t\\treturn\\n\\treorderListUtil ( right . next )\\n\\tif ( left == None ) :\\n\\t\\treturn\\n\\tif ( left != right and left . next != right ) :\\n\\t\\ttemp = left . next\\n\\t\\tleft . next = right\\n\\t\\tright . next = temp\\n\\t\\tleft = temp\\n\\telse :\\n\\t\\tif ( left . next == right ) :\\n\\t\\t\\tleft . next . next = None\\n\\t\\t\\tleft = None\\n\\t\\telse :\\n\\t\\t\\tleft . next = None\\n\\t\\t\\tleft = None\\nhead = Node ( 1 )\\nhead . next = Node ( 2 )\\nhead . next . next = Node ( 3 )\\nhead . next . next . next = Node ( 4 )\\nhead . next . next . next . next = Node ( 5 )\\nprintlist ( head )\\nrearrange ( head )\\nprintlist ( head )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Dynamic Programming | C # program for the above approach ; Check if possible subset with given sum is possible or not ; Storing the value - 1 to the matrix ; If the sum is zero it means we got our expected sum ; If the value is not - 1 it means it already call the function with the same value . it will save our from the repetition . ; if the value of a [ n - 1 ] is greater than the sum . we call for the next value ; Here we do two calls because we don ' t \u2581 know \u2581 which \u2581 value \u2581 is \u2581 \u2581 full - fill \u2581 our \u2581 criteria \u2581 \u2581 that ' s why we doing two calls ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int subsetSum ( int [ ] a , int n , int sum ) { int [ , ] tab = new int [ n + 1 , sum + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { tab [ i , j ] = - 1 ; } } if ( sum == 0 ) return 1 ; if ( n <= 0 ) return 0 ; if ( tab [ n - 1 , sum ] != - 1 ) return tab [ n - 1 , sum ] ; if ( a [ n - 1 ] > sum ) return tab [ n - 1 , sum ] = subsetSum ( a , n - 1 , sum ) ; else { if ( subsetSum ( a , n - 1 , sum ) != 0 || subsetSum ( a , n - 1 , sum - a [ n - 1 ] ) != 0 ) { return tab [ n - 1 , sum ] = 1 ; } else return tab [ n - 1 , sum ] = 0 ; } } public static void Main ( String [ ] args ) { int n = 5 ; int [ ] a = { 1 , 5 , 3 , 7 , 4 } ; int sum = 12 ; if ( subsetSum ( a , n , sum ) != 0 ) { Console . Write ( \\\" YES \\n \\\" ) ; } else Console . Write ( \\\" NO \\n \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check if array can be sorted with one swap | A linear Python 3 program to check if array becomes sorted after one swap ; Create a sorted copy of original array ; Check if 0 or 1 swap required to get the sorted array ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def checkSorted ( n , arr ) :\\n\\tb = [ ]\\n\\tfor i in range ( n ) :\\n\\t\\tb . append ( arr [ i ] )\\n\\tb . sort ( )\\n\\tct = 0\\n\\tfor i in range ( n ) :\\n\\t\\tif arr [ i ] != b [ i ] :\\n\\t\\t\\tct += 1\\n\\tif ct == 0 or ct == 2 :\\n\\t\\treturn True\\n\\telse :\\n\\t\\treturn False\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 1 , 5 , 3 , 4 , 2 ]\\n\\tn = len ( arr )\\n\\tif checkSorted ( n , arr ) :\\n\\t\\tprint ( \\\" Yes \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Pythagorean Triplet with given sum | Java program to find Pythagorean Triplet of given sum . ; Considering triplets in sorted order . The value of first element in sorted triplet can be at - most n \\/ 3. ; The value of second element must be less than equal to n \\/ 2 ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static void pythagoreanTriplet ( int n ) { for ( int i = 1 ; i <= n \\/ 3 ; i ++ ) { for ( int j = i + 1 ; j <= n \\/ 2 ; j ++ ) { int k = n - i - j ; if ( i * i + j * j == k * k ) { System . out . print ( i + \\\" , \u2581 \\\" + j + \\\" , \u2581 \\\" + k ) ; return ; } } } System . out . print ( \\\" No \u2581 Triplet \\\" ) ; } public static void main ( String arg [ ] ) { int n = 12 ; pythagoreanTriplet ( n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find the smallest and second smallest elements in an array | Function to print first smallest and second smallest elements ; There should be atleast two elements ; If current element is smaller than first then update both first and second ; If arr [ i ] is in between first and second then update second ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function print2Smallest ( $ arr , $ arr_size ) { $ INT_MAX = 2147483647 ; if ( $ arr_size < 2 ) { echo ( \\\" \u2581 Invalid \u2581 Input \u2581 \\\" ) ; return ; } $ first = $ second = $ INT_MAX ; for ( $ i = 0 ; $ i < $ arr_size ; $ i ++ ) { if ( $ arr [ $ i ] < $ first ) { $ second = $ first ; $ first = $ arr [ $ i ] ; } else if ( $ arr [ $ i ] < $ second && $ arr [ $ i ] != $ first ) $ second = $ arr [ $ i ] ; } if ( $ second == $ INT_MAX ) echo ( \\\" There \u2581 is \u2581 no \u2581 second \u2581 smallest \u2581 element \\n \\\" ) ; else echo \\\" The \u2581 smallest \u2581 element \u2581 is \u2581 \\\" , $ first , \\\" \u2581 and \u2581 second \u2581 Smallest \u2581 element \u2581 is \u2581 \\\" , $ second ; } $ arr = array ( 12 , 13 , 1 , 10 , 34 , 1 ) ; $ n = count ( $ arr ) ; print2Smallest ( $ arr , $ n ) ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if a string can be made equal to another string by swapping or replacement of characters | Function to find if given strings are same or not ; Base Condition ; Stores frequency of characters of the str1 and str2 ; Traverse strings str1 & str2 and store frequencies in a [ ] and b [ ] ; Check if both strings have same characters or not ; If a character is present in one and is not in another string , return false ; Sort the array a [ ] and b [ ] ; Check arrays a and b contain the same frequency or not ; If the frequencies are not the same after sorting ; At this point , str1 can be converted to str2 ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def sameStrings ( str1 , str2 ) :\\n\\tN = len ( str1 )\\n\\tM = len ( str2 )\\n\\tif ( N != M ) :\\n\\t\\treturn False\\n\\ta , b = [ 0 ] * 256 , [ 0 ] * 256\\n\\tfor i in range ( N ) :\\n\\t\\ta [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] += 1\\n\\t\\tb [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] += 1\\n\\ti = 0\\n\\twhile ( i < 256 ) :\\n\\t\\tif ( ( a [ i ] == 0 and b [ i ] == 0 ) or ( a [ i ] != 0 and b [ i ] != 0 ) ) :\\n\\t\\t\\ti += 1\\n\\t\\telse :\\n\\t\\t\\treturn False\\n\\ta = sorted ( a )\\n\\tb = sorted ( b )\\n\\tfor i in range ( 256 ) :\\n\\t\\tif ( a [ i ] != b [ i ] ) :\\n\\t\\t\\treturn False\\n\\treturn True\\nif __name__ == ' _ _ main _ _ ' :\\n\\tS1 , S2 = \\\" cabbba \\\" , \\\" abbccc \\\"\\n\\tif ( sameStrings ( S1 , S2 ) ) :\\n\\t\\tprint ( \\\" YES \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" NO \\\" )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count words in a given string | Function to count total number of words in the string ; Check if the string is null or empty then return zero ; Converting the given string into a character array ; Check if the character is a letter and index of character array doesn 't equal to end of line that means, it is a word and set isWord by true ; Check if the character is not a letter that means there is a space , then we increment the wordCount by one and set the isWord by false ; Check for the last word of the sentence and increment the wordCount by one ; Return the total number of words in the string ; Given String str ; Print the result\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def countWords ( Str ) :\\n\\tif ( Str == None or len ( Str ) == 0 ) :\\n\\t\\treturn 0\\n\\twordCount = 0\\n\\tisWord = False\\n\\tendOfLine = len ( Str ) - 1\\n\\tch = list ( Str )\\n\\tfor i in range ( len ( ch ) ) :\\n\\t\\tif ( ch [ i ] . isalpha ( ) and i != endOfLine ) :\\n\\t\\t\\tisWord = True\\n\\t\\telif ( not ch [ i ] . isalpha ( ) and isWord ) :\\n\\t\\t\\twordCount += 1\\n\\t\\t\\tisWord = False\\n\\t\\telif ( ch [ i ] . isalpha ( ) and i == endOfLine ) :\\n\\t\\t\\twordCount += 1\\n\\treturn wordCount\\nStr = \\\" One two three\\n\\tfour five \\\"\\nprint ( \\\" No \u2581 of \u2581 words \u2581 : \\\" , countWords ( Str ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program to duplicate Vowels in String | Function to check for the Vowel ; Function to get the resultant string with vowels duplicated ; Another string to store the resultant string ; Loop to check for each character ; Driver Code ; Print the original string ; Print the resultant string\\\"\\nSolution in Javascript:\",\"targets\":\"function isVowel ( ch ) { ch = ch . toUpperCase ( ) ; return ( ch == ' ' ch == ' ' ch == ' ' ch == ' ' ch == ' ' ) ; } function duplicateVowels ( str ) { let t = str . length ; let res = \\\" \\\" ; for ( let i = 0 ; i < t ; i ++ ) { if ( isVowel ( str [ i ] ) ) res += str [ i ] ; res += str [ i ] ; } return res ; } let str = \\\" \\\" ; document . write ( \\\" \\\" + str + \\\" \\\" ) ; let res = duplicateVowels ( str ) ; document . write ( \\\" \\\" + res + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count of integers that divide all the elements of the given array | Function to return the count of the required integers ; To store the gcd of the array elements ; To store the count of factors of the found gcd ; If g is a perfect square ; Factors appear in pairs ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"from math import gcd as __gcd\\ndef getCount ( a , n ) :\\n\\tgcd = 0\\n\\tfor i in range ( n ) :\\n\\t\\tgcd = __gcd ( gcd , a [ i ] )\\n\\tcnt = 0\\n\\tfor i in range ( 1 , gcd + 1 ) :\\n\\t\\tif i * i > gcd :\\n\\t\\t\\tbreak\\n\\t\\tif ( gcd % i == 0 ) :\\n\\t\\t\\tif ( i * i == gcd ) :\\n\\t\\t\\t\\tcnt += 1\\n\\t\\t\\telse :\\n\\t\\t\\t\\tcnt += 2\\n\\treturn cnt\\na = [ 4 , 16 , 1024 , 48 ]\\nn = len ( a )\\nprint ( getCount ( a , n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count elements of same value placed at same indices of two given arrays | C ++ program for the above approach ; Function to count maximum matched elements from the arrays A [ ] and B [ ] ; Stores position of elements of array A [ ] in the array B [ ] ; Keep track of difference between the indices ; Traverse the array A [ ] ; Traverse the array B [ ] ; If difference is negative , add N to it ; Keep track of the number of shifts required to place elements at same indices ; Return the max matches ; Driver code ; Returns the count of matched elements\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int maxMatch ( int A [ ] , int B [ ] , int M , int N ) { map < int , int > Aindex ; map < int , int > diff ; for ( int i = 0 ; i < M ; i ++ ) { Aindex [ A [ i ] ] = i ; } for ( int i = 0 ; i < N ; i ++ ) { if ( i - Aindex [ B [ i ] ] < 0 ) { diff [ M + i - Aindex [ B [ i ] ] ] += 1 ; } else { diff [ i - Aindex [ B [ i ] ] ] += 1 ; } } int max = 0 ; for ( auto ele = diff . begin ( ) ; ele != diff . end ( ) ; ele ++ ) { if ( ele -> second > max ) { max = ele -> second ; } } return max ; } int main ( ) { int A [ ] = { 5 , 3 , 7 , 9 , 8 } ; int B [ ] = { 8 , 7 , 3 , 5 , 9 } ; int M = sizeof ( A ) \\/ sizeof ( A [ 0 ] ) ; int N = sizeof ( B ) \\/ sizeof ( B [ 0 ] ) ; cout << maxMatch ( A , B , M , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to check if a given number is Lucky ( all digits are different ) | This function returns true if n is lucky ; Create an array of size 10 and initialize all elements as false . This array is used to check if a digit is already seen or not . ; Traverse through all digits of given number ; Find the last digit ; If digit is already seen , return false ; Mark this digit as seen ; Remove the last digit from number ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function isLucky ( $ n ) { $ arr = array ( ) ; for ( $ i = 0 ; $ i < 10 ; $ i ++ ) $ arr [ $ i ] = false ; while ( $ n > 0 ) { $ digit = $ n % 10 ; if ( $ arr [ $ digit ] ) return false ; $ arr [ $ digit ] = true ; $ n = ( int ) ( $ n \\/ 10 ) ; } return true ; } $ arr = array ( 1291 , 897 , 4566 , 1232 , 80 , 700 ) ; $ n = sizeof ( $ arr ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( isLucky ( $ arr [ $ i ] ) ) echo $ arr [ $ i ] , \\\" \u2581 is \u2581 Lucky \u2581 \\n \\\" ; else echo $ arr [ $ i ] , \\\" \u2581 is \u2581 not \u2581 Lucky \u2581 \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all subsequences of a number | Returns numeric value of a subsequence of s . The subsequence to be picked is decided using bit pattern of num ( We pick all thosedigits for which there is a set bit in num ) ; Initialize the result ; till n != 0 ; if i - th bit is set then add this number ; right shintift i ; function to find combined sum of all individual subsequence sum ; length of string ; stores the combined ; 2 ^ n - 1 subsequences ; loop for all subsequences ; returns the combined sum ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function findSubSequence ( $ s , $ num ) { $ res = 0 ; $ i = 0 ; while ( $ num ) { if ( $ num & 1 ) $ res += $ s [ $ i ] - '0' ; $ i ++ ; $ num = $ num >> 1 ; } return $ res ; } function combinedSum ( string $ s ) { $ n = strlen ( $ s ) ; $ c_sum = 0 ; $ range = ( 1 << $ n ) - 1 ; for ( $ i = 0 ; $ i <= $ range ; $ i ++ ) $ c_sum += findSubSequence ( $ s , $ i ) ; return $ c_sum ; } $ s = \\\"123\\\" ; echo combinedSum ( $ s ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"k | C # program to find the k - th missing element in a given sequence ; Returns k - th missing element . It returns - 1 if no k is more than number of missing elements . ; Insert all elements of givens sequence b [ ] . ; Traverse through increasing sequence and keep track of count of missing numbers . ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int find ( int [ ] a , int [ ] b , int k , int n1 , int n2 ) { HashSet < int > s = new HashSet < int > ( ) ; for ( int i = 0 ; i < n2 ; i ++ ) s . Add ( b [ i ] ) ; int missing = 0 ; for ( int i = 0 ; i < n1 ; i ++ ) { if ( ! s . Contains ( a [ i ] ) ) missing ++ ; if ( missing == k ) return a [ i ] ; } return - 1 ; } public static void Main ( String [ ] args ) { int [ ] a = { 0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 , 15 } ; int [ ] b = { 4 , 10 , 6 , 8 , 12 } ; int n1 = a . Length ; int n2 = b . Length ; int k = 3 ; Console . WriteLine ( find ( a , b , k , n1 , n2 ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"All about Bit Manipulation | Function to clear the ith bit of the given number N ; Create the mask for the ith bit unset ; Return the update value\\\"\\nHow can the above be solved in Java?\",\"targets\":\"static int clearBit ( int num , int i ) { int mask = ~ ( 1 << i ) ; return num & mask ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Number of ways to remove a sub | Function to return the number of ways of removing a sub - string from s such that all the remaining characters are same ; To store the count of prefix and suffix ; Loop to count prefix ; Loop to count suffix ; First and last characters of the string are same ; Otherwise ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function no_of_ways ( s ) { let n = s . length ; let count_left = 0 , count_right = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( s [ i ] == s [ 0 ] ) { ++ count_left ; } else break ; } for ( let i = n - 1 ; i >= 0 ; -- i ) { if ( s [ i ] == s [ n - 1 ] ) { ++ count_right ; } else break ; } if ( s [ 0 ] == s [ n - 1 ] ) return ( ( count_left + 1 ) * ( count_right + 1 ) ) ; else return ( count_left + count_right + 1 ) ; } let s = \\\" \\\" ; document . write ( no_of_ways ( s ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Print characters having prime frequencies in order of occurrence | javaScript implementation of the approach ; Function to create Sieve to check primes Function to create Sieve to check primes ; False here indicates that it is not prime ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p , set them to non - prime ; Function to print the prime frequency characters in the order of their occurrence ; Function to create Sieve to check primes ; To store the frequency of each of the character of the string ; Initialize all elements of freq [ ] to 0 ; Update the frequency of each character ; Traverse str character by character ; If frequency of current character is prime ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"let SIZE = 26 ; function SieveOfEratosthenes ( prime , p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( let i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } return prime ; } function printChar ( str , n ) { let prime = [ ] ; for ( let i = 0 ; i < n + 1 ; i ++ ) { prime . push ( true ) ; } prime = SieveOfEratosthenes ( prime , str . length + 1 ) ; let freq = [ ] ; for ( let i = 0 ; i < 26 ; i ++ ) { freq . push ( 0 ) ; } for ( let i = 0 ; i < n ; i ++ ) freq [ str . charCodeAt ( i ) - 97 ] ++ ; for ( let i = 0 ; i < n ; i ++ ) { if ( prime [ freq [ str . charCodeAt ( i ) - 97 ] ] ) { document . write ( str [ i ] ) ; } } } let str = \\\" \\\" ; let n = str . length ; printChar ( str , n ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Cutting a Rod | DP | A Dynamic Programming solution for Rod cutting problem ; A utility function to get the maximum of two integers ; Returns the best obtainable price for a rod of length n and price [ ] as prices of different pieces ; Build the table val [ ] in bottom up manner and return the last entry from the table ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nint max ( int a , int b ) { return ( a > b ) ? a : b ; } int cutRod ( int price [ ] , int n ) { int val [ n + 1 ] ; val [ 0 ] = 0 ; int i , j ; for ( i = 1 ; i <= n ; i ++ ) { int max_val = INT_MIN ; for ( j = 0 ; j < i ; j ++ ) max_val = max ( max_val , price [ j ] + val [ i - j - 1 ] ) ; val [ i ] = max_val ; } return val [ n ] ; } int main ( ) { int arr [ ] = { 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 } ; int size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Maximum \u2581 Obtainable \u2581 Value \u2581 is \u2581 % d \\\" , cutRod ( arr , size ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find elements larger than half of the elements in an array | Prints elements larger than n \\/ 2 element ; Sort the array in ascending order ; Print last ceil ( n \\/ 2 ) elements ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function findLarger ( arr , n ) { arr . sort ( ) ; for ( let i = n - 1 ; i >= n \\/ 2 ; i -- ) document . write ( arr [ i ] + \\\" \\\" ) ; } let arr = [ 1 , 3 , 6 , 1 , 0 , 9 ] ; let n = arr . length ; findLarger ( arr , n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count the numbers which can convert N to 1 using given operation | C ++ program to count the numbers which can convert N to 1 using the given operation ; Function to count the numbers which can convert N to 1 using the given operation ; Store all the divisors of N ; If i is a divisor ; If i is not equal to N \\/ i ; Iterate through all the divisors of N - 1 and count them in answer ; Check if N - 1 is a divisor or not ; Iterate through all divisors and check for N mod d = 1 or ( N - 1 ) mod d = 0 ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int countValues ( int N ) { vector < int > div ; for ( int i = 2 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { div . push_back ( i ) ; if ( N != i * i ) { div . push_back ( N \\/ i ) ; } } } int answer = 0 ; for ( int i = 1 ; i * i <= N - 1 ; i ++ ) { if ( ( N - 1 ) % i == 0 ) { if ( i * i == N - 1 ) answer ++ ; else answer += 2 ; } } for ( auto d : div ) { int K = N ; while ( K % d == 0 ) K \\/= d ; if ( ( K - 1 ) % d == 0 ) answer ++ ; } return answer ; } int main ( ) { int N = 6 ; cout << countValues ( N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to find whether a no is power of two | ; Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\n#define bool int\\nbool isPowerOfTwo ( int x ) { return x && ( ! ( x & ( x - 1 ) ) ) ; } int main ( ) { isPowerOfTwo ( 31 ) ? printf ( \\\" Yes \\n \\\" ) : printf ( \\\" No \\n \\\" ) ; isPowerOfTwo ( 64 ) ? printf ( \\\" Yes \\n \\\" ) : printf ( \\\" No \\n \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Smallest power of 2 greater than or equal to n | PHP program to find smallest power of 2 greater than or equal to n ; First n in the below condition is for the case where n is 0 ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function nextPowerOf2 ( $ n ) { $ count = 0 ; if ( $ n && ! ( $ n & ( $ n - 1 ) ) ) return $ n ; while ( $ n != 0 ) { $ n >>= 1 ; $ count += 1 ; } return 1 << $ count ; } $ n = 0 ; echo ( nextPowerOf2 ( $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to check if matrix is lower triangular | PHP Program to check lower triangular matrix . ; Function to check matrix is in lower triangular form or not . ; Driver Code ; Function call\\\"\\nSolution in php:\",\"targets\":\"< ? php $ N = 4 ; function isLowerTriangularMatrix ( $ mat ) { global $ N ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) for ( $ j = $ i + 1 ; $ j < $ N ; $ j ++ ) if ( $ mat [ $ i ] [ $ j ] != 0 ) return false ; return true ; } $ mat = array ( array ( 1 , 0 , 0 , 0 ) , array ( 1 , 4 , 0 , 0 ) , array ( 4 , 6 , 2 , 0 ) , array ( 0 , 4 , 7 , 6 ) ) ; if ( isLowerTriangularMatrix ( $ mat ) ) echo ( \\\" Yes \\\" ) ; else echo ( \\\" No \\\" ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximum length of consecutive 1 s or 0 s after flipping at most K characters | C # program for the above approach ; Function to find the maximum length continuos segment of character c after flipping at most K characters ; Stores the maximum length ; Stores the count of char ' c ' ; Start of window ; Remove the extra ' c ' from left ; Increment the value of the left ; Update the resultant maximum length of character ch ; Function to find the maximum length of consecutive 0 s or 1 s by flipping at most K characters of the string ; Print the maximum of the maximum length of 0 s or 1 s ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; public class GFG { static int maxLength ( String str , int n , char c , int k ) { int ans = - 1 ; int cnt = 0 ; int left = 0 ; for ( int right = 0 ; right < n ; right ++ ) { if ( str [ right ] == c ) { cnt ++ ; } while ( cnt > k ) { if ( str [ left ] == c ) { cnt -- ; } left ++ ; } ans = Math . Max ( ans , right - left + 1 ) ; } return ans ; } static int maxConsecutiveSegment ( String S , int K ) { int N = S . Length ; return Math . Max ( maxLength ( S , N , '0' , K ) , maxLength ( S , N , '1' , K ) ) ; } public static void Main ( ) { String S = \\\"1001\\\" ; int K = 1 ; Console . WriteLine ( maxConsecutiveSegment ( S , K ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Kaprekar Constant | This function checks validity of kaprekar ' s \u2581 constant . \u2581 It \u2581 returns \u2581 kaprekar ' s constant for any four digit number \\\" n \\\" such that all digits of n are not same . ; Store current n as previous number ; Get four digits of given number ; Sort all four dgits in ascending order And giet in the form of number \\\" asc \\\" ; Get all four dgits in descending order in the form of number \\\" desc \\\" ; Get the difference of two numbers ; If difference is same as previous , we have reached kaprekar 's constant ; Else recur ; A wrapper over kaprekarRec ( ) ; Trying few four digit numbers , we always get 6174\\\"\\nSolution in Python:\",\"targets\":\"def kaprekarRec ( n , prev ) :\\n\\tif ( n == 0 ) :\\n\\t\\treturn 0 ;\\n\\tprev = n ;\\n\\tdigits = [ 0 ] * 4 ;\\n\\tfor i in range ( 4 ) :\\n\\t\\tdigits [ i ] = n % 10 ;\\n\\t\\tn = int ( n \\/ 10 ) ;\\n\\tdigits . sort ( ) ;\\n\\tasc = 0 ;\\n\\tfor i in range ( 4 ) :\\n\\t\\tasc = asc * 10 + digits [ i ] ;\\n\\tdigits . sort ( ) ;\\n\\tdesc = 0 ;\\n\\tfor i in range ( 3 , - 1 , - 1 ) :\\n\\t\\tdesc = desc * 10 + digits [ i ] ;\\n\\tdiff = abs ( asc - desc ) ;\\n\\tif ( diff == prev ) :\\n\\t\\treturn diff ;\\n\\treturn kaprekarRec ( diff , prev ) ;\\ndef kaprekar ( n ) :\\n\\trev = 0 ;\\n\\treturn kaprekarRec ( n , rev ) ;\\nprint ( kaprekar ( 1000 ) ) ;\\nprint ( kaprekar ( 1112 ) ) ;\\nprint ( kaprekar ( 9812 ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find sum of even index binomial coefficients | Python Program to find sum of even index term ; Return the sum of even index term ; Calculate value of Binomial Coefficient in bottom up manner ; Base Cases ; Calculate value using previously stored values ; Finding sum of even index term ; Driver method\\\"\\nSolution in Python:\",\"targets\":\"import math\\ndef evenSum ( n ) :\\n\\tC = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\\n\\tfor i in range ( 0 , n + 1 ) :\\n\\t\\tfor j in range ( 0 , min ( i , n + 1 ) ) :\\n\\t\\t\\tif j == 0 or j == i :\\n\\t\\t\\t\\tC [ i ] [ j ] = 1\\n\\t\\t\\telse :\\n\\t\\t\\t\\tC [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\\n\\tsum = 0 ;\\n\\tfor i in range ( 0 , n + 1 ) :\\n\\t\\tif n % 2 == 0 :\\n\\t\\t\\tsum = sum + C [ n ] [ i ]\\n\\treturn sum\\nn = 4\\nprint evenSum ( n )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to make the number formed by K concatenations of a numeric string divisible by 5 | Java program for the above approach ; Function to find the value of a ^ b modulo 1000000007 ; Stores the resultant value a ^ b ; Find the value of a ^ b ; Function to count the number of ways such that the formed number is divisible by 5 by removing digits ; Stores the count of ways ; Find the count for string S ; If the digit is 5 or 0 ; Find the count of string for K concatenation of string S ; Find the total count ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static long MOD = 1000000007 ; public static long exp_mod ( long a , long b ) { long ret = 1 ; for ( ; b > 0 ; b >>= 1 , a = a * a % MOD ) { if ( ( b & 1 ) > 0 ) ret = ret * a % MOD ; } return ret ; } public static long countOfWays ( String s , int k ) { int N = s . length ( ) ; long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == '5' || s . charAt ( 0 ) == '0' ) { ans = ( ans + exp_mod ( 2 , i ) ) % MOD ; } } long q = exp_mod ( 2 , N ) ; long qk = exp_mod ( q , k ) ; long inv = exp_mod ( q - 1 , MOD - 2 ) ; ans = ans * ( qk - 1 ) % MOD ; ans = ans * inv % MOD ; return ans ; } public static void main ( String args [ ] ) { String S = \\\"1256\\\" ; int K = 1 ; System . out . println ( countOfWays ( S , K ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Legendre 's formula (Given p and n, find the largest x such that p^x divides n!) | C program to find largest x such that p * x divides n ! ; Returns largest power of p that divides n ! ; Initialize result ; Calculate x = n \\/ p + n \\/ ( p ^ 2 ) + n \\/ ( p ^ 3 ) + ... . ; Driver program\\\"\\nSolution in C:\",\"targets\":\"#include \\nint largestPower ( int n , int p ) { int x = 0 ; while ( n ) { n \\/= p ; x += n ; } return x ; } int main ( ) { int n = 10 , p = 3 ; printf ( \\\" The \u2581 largest \u2581 power \u2581 of \u2581 % d \u2581 that \u2581 divides \u2581 % d ! \u2581 is \u2581 % d \\n \\\" , p , n , largestPower ( n , p ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"K | Python program to find k - th element from two sorted arrays\\\"\\nSolution in Python:\",\"targets\":\"def kth ( arr1 , arr2 , n , m , k ) :\\n\\tif n == 1 or m == 1 :\\n\\t\\tif m == 1 :\\n\\t\\t\\tarr2 , arr1 = arr1 , arr2\\n\\t\\t\\tm = n\\n\\t\\tif k == 1 :\\n\\t\\t\\treturn min ( arr1 [ 0 ] , arr2 [ 0 ] )\\n\\t\\telif k == m + 1 :\\n\\t\\t\\treturn max ( arr1 [ 0 ] , arr2 [ 0 ] )\\n\\t\\telse :\\n\\t\\t\\tif arr2 [ k - 1 ] < arr1 [ 0 ] :\\n\\t\\t\\t\\treturn arr2 [ k - 1 ]\\n\\t\\t\\telse :\\n\\t\\t\\t\\treturn max ( arr1 [ 0 ] , arr2 [ k - 2 ] )\\n\\tmid1 = ( n - 1 ) \\/\\/ 2\\n\\tmid2 = ( m - 1 ) \\/\\/ 2\\n\\tif mid1 + mid2 + 1 < k :\\n\\t\\tif arr1 [ mid1 ] < arr2 [ mid2 ] :\\n\\t\\t\\treturn kth ( arr1 [ mid1 + 1 : ] , arr2 , n - mid1 - 1 , m , k - mid1 - 1 )\\n\\t\\telse :\\n\\t\\t\\treturn kth ( arr1 , arr2 [ mid2 + 1 : ] , n , m - mid2 - 1 , k - mid2 - 1 )\\n\\telse :\\n\\t\\tif arr1 [ mid1 ] < arr2 [ mid2 ] :\\n\\t\\t\\treturn kth ( arr1 , arr2 [ : mid2 + 1 ] , n , mid2 + 1 , k )\\n\\t\\telse :\\n\\t\\t\\treturn kth ( arr1 [ : mid1 + 1 ] , arr2 , mid1 + 1 , m , k )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr1 = [ 2 , 3 , 6 , 7 , 9 ]\\n\\tarr2 = [ 1 , 4 , 8 , 10 ]\\n\\tk = 5\\n\\tprint ( kth ( arr1 , arr2 , 5 , 4 , k ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Form lexicographically smallest string with minimum replacements having equal number of 0 s , 1 s and 2 s | C ++ implementation of the approach ; Function that returns the modified lexicographically smallest string after performing minimum number of given operations ; Stores the initial frequencies of characters 0 s , 1 s and 2 s ; Stores number of processed characters upto that point of each type ; Required number of characters of each type ; If the current type has already reqd number of characters , no need to perform any operation ; Process all 3 cases ; Check for 1 first ; Else 2 ; Here we need to check processed [ 1 ] only for 2 since 0 is less than 1 and we can replace it anytime ; Here we can replace 2 with 0 and 1 anytime ; keep count of processed characters of each type ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; string formStringMinOperations ( string s ) { int count [ 3 ] = { 0 } ; for ( auto & c : s ) count ++ ; int processed [ 3 ] = { 0 } ; int reqd = ( int ) s . size ( ) \\/ 3 ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { if ( count [ s [ i ] - '0' ] == reqd ) continue ; if ( s [ i ] == '0' && count [ 0 ] > reqd && processed [ 0 ] >= reqd ) { if ( count [ 1 ] < reqd ) { s [ i ] = '1' ; count [ 1 ] ++ ; count [ 0 ] -- ; } else if ( count [ 2 ] < reqd ) { s [ i ] = '2' ; count [ 2 ] ++ ; count [ 0 ] -- ; } } if ( s [ i ] == '1' && count [ 1 ] > reqd ) { if ( count [ 0 ] < reqd ) { s [ i ] = '0' ; count [ 0 ] ++ ; count [ 1 ] -- ; } else if ( count [ 2 ] < reqd && processed [ 1 ] >= reqd ) { s [ i ] = '2' ; count [ 2 ] ++ ; count [ 1 ] -- ; } } if ( s [ i ] == '2' && count [ 2 ] > reqd ) { if ( count [ 0 ] < reqd ) { s [ i ] = '0' ; count [ 0 ] ++ ; count [ 2 ] -- ; } else if ( count [ 1 ] < reqd ) { s [ i ] = '1' ; count [ 1 ] ++ ; count [ 2 ] -- ; } } processed [ s [ i ] - '0' ] ++ ; } return s ; } int main ( ) { string s = \\\"011200\\\" ; cout << formStringMinOperations ( s ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Smallest power of 2 greater than or equal to n | ; First n in the below condition is for the case where n is 0 ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nunsigned int nextPowerOf2 ( unsigned int n ) { unsigned count = 0 ; if ( n && ! ( n & ( n - 1 ) ) ) return n ; while ( n != 0 ) { n >>= 1 ; count += 1 ; } return 1 << count ; } int main ( ) { unsigned int n = 0 ; printf ( \\\" % d \\\" , nextPowerOf2 ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximum sum of values of N items in 0 | C # implementation for the above approach ; Function to find the maximum value ; base condition ; K elements already reduced to half of their weight ; Dont include item ; If weight of the item is less than or equal to the remaining weight then include the item ; Return the maximum of both cases ; If the weight reduction to half is possible ; Skip the item ; Include item with full weight if weight of the item is less than the remaining weight ; Include item with half weight if half weight of the item is less than the remaining weight ; Return the maximum of all 3 cases ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GFG { static int maximum ( int [ ] value , int [ ] weight , int weight1 , int flag , int K , int index ) { if ( index >= value . Length ) { return 0 ; } if ( flag == K ) { int skip = maximum ( value , weight , weight1 , flag , K , index + 1 ) ; int full = 0 ; if ( weight [ index ] <= weight1 ) { full = value [ index ] + maximum ( value , weight , weight1 - weight [ index ] , flag , K , index + 1 ) ; } return Math . Max ( full , skip ) ; } else { int skip = maximum ( value , weight , weight1 , flag , K , index + 1 ) ; int full = 0 ; int half = 0 ; if ( weight [ index ] <= weight1 ) { full = value [ index ] + maximum ( value , weight , weight1 - weight [ index ] , flag , K , index + 1 ) ; } if ( weight [ index ] \\/ 2 <= weight1 ) { half = value [ index ] + maximum ( value , weight , weight1 - weight [ index ] \\/ 2 , flag , K , index + 1 ) ; } return Math . Max ( full , Math . Max ( skip , half ) ) ; } } public static void Main ( String [ ] args ) { int [ ] value = { 17 , 20 , 10 , 15 } ; int [ ] weight = { 4 , 2 , 7 , 5 } ; int K = 1 ; int W = 4 ; Console . WriteLine ( maximum ( value , weight , W , 0 , K , 0 ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Hyperfactorial of a number | function to calculate the value of hyperfactorial ; initialise the val to 1 ; returns the hyperfactorial of a number ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function boost_hyperfactorial ( $ num ) { $ val = 1 ; for ( $ i = 1 ; $ i <= $ num ; $ i ++ ) { $ val = $ val * pow ( $ i , $ i ) ; } return $ val ; } $ num = 5 ; echo boost_hyperfactorial ( $ num ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Bitwise AND of all the odd numbers from 1 to N | Java implementation of the approach ; Function to return the bitwise AND of all the odd integers from the range [ 1 , n ] ; Initialize result to 1 ; Starting from 3 , bitwise AND all the odd integers less than or equal to n ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int bitwiseAndOdd ( int n ) { int result = 1 ; for ( int i = 3 ; i <= n ; i = i + 2 ) { result = ( result & i ) ; } return result ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . println ( bitwiseAndOdd ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Check if each internal node of a BST has exactly one child | Check if each internal node of BST has only one child ; Initialize min and max using last two elements ; Every element must be either smaller than min or greater than max ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint hasOnlyOneChild ( int pre [ ] , int size ) { int min , max ; if ( pre [ size - 1 ] > pre [ size - 2 ] ) { max = pre [ size - 1 ] ; min = pre [ size - 2 ] ) : else { max = pre [ size - 2 ] ; min = pre [ size - 1 ] ; } for ( int i = size - 3 ; i >= 0 ; i -- ) { if ( pre [ i ] < min ) min = pre [ i ] ; else if ( pre [ i ] > max ) max = pre [ i ] ; else return false ; } return true ; } int main ( ) { int pre [ ] = { 8 , 3 , 5 , 7 , 6 } ; int size = sizeof ( pre ) \\/ sizeof ( pre [ 0 ] ) ; if ( hasOnlyOneChild ( pre , size ) ) printf ( \\\" Yes \\\" ) ; else printf ( \\\" No \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Queries to find longest subsequence having no similar adjacent elements with updates | C ++ program for the above approach ; Traverse the array arr [ ] ; If previous element is not same as current element ; Traverse the queries ; Replace element at index x with y ; Recalculate for index x ; Subtract contribution of element at index x ; Add contribution of y ; Recalculate for index x + 1 ; Subtract contribution of element at index x + 1 ; Adds contribution of y ; Replace the element ; Driver Code ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void longestSubsequence ( int N , int Q , int arr [ ] , int Queries [ ] [ 2 ] ) { int count = 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] != arr [ i - 1 ] ) { count += 1 ; } } for ( int i = 0 ; i < Q ; i ++ ) { int x = Queries [ i ] [ 0 ] ; int y = Queries [ i ] [ 1 ] ; if ( x > 1 ) { if ( arr [ x - 1 ] != arr [ x - 2 ] ) { count -= 1 ; } if ( arr [ x - 2 ] != y ) { count += 1 ; } } if ( x < N ) { if ( arr [ x ] != arr [ x - 1 ] ) { count -= 1 ; } if ( y != arr [ x ] ) { count += 1 ; } } cout << count << ' \u2581 ' ; arr [ x - 1 ] = y ; } } int main ( ) { int arr [ ] = { 1 , 1 , 2 , 5 , 2 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int Q = 2 ; int Queries [ Q ] [ 2 ] = { { 1 , 3 } , { 4 , 2 } } ; longestSubsequence ( N , Q , arr , Queries ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count triples with Bitwise AND equal to Zero | Function to find the number of triplets whose Bitwise AND is 0. ; Stores the count of triplets having bitwise AND equal to 0 ; Stores frequencies of all possible A [ i ] & A [ j ] ; Traverse the array ; Update frequency of Bitwise AND of all array elements with a ; Traverse the array ; Update frequency of Bitwise AND of all array elements with a ; If bitwise AND of triplet is zero , increment cnt ; Return the number of triplets whose Bitwise AND is 0. ; Input Array ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function countTriplets ( A ) { var cnt = 0 ; var tuples = new Map ( ) ; A . forEach ( a => { A . forEach ( b => { if ( tuples . has ( a & b ) ) tuples . set ( a & b , tuples . get ( a & b ) + 1 ) else tuples . set ( a & b , 1 ) } ) ; } ) ; A . forEach ( a => { tuples . forEach ( ( value , key ) => { if ( ( key & a ) == 0 ) cnt += value ; } ) ; } ) ; return cnt ; } var A = [ 2 , 1 , 3 ] ; document . write ( countTriplets ( A ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sum of divisors of factorial of a number | allPrimes [ ] stores all prime numbers less than or equal to n . ; Fills above vector allPrimes [ ] for a given n ; Create a boolean array \\\" prime [ 0 . . n ] \\\" and initialize all entries it as true . A value in prime [ i ] will finally be false if i is not a prime , else true . ; Loop to update prime [ ] ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Store primes in the vector allPrimes ; Function to find all result of factorial number ; Initialize result ; find exponents of all primes which divides n and less than n ; Current divisor ; Find the highest power ( stored in exp ) ' \u2581 \u2581 of \u2581 allPrimes [ i ] \u2581 that \u2581 divides \u2581 n \u2581 using \u2581 \u2581 Legendre ' s formula . ; Using the divisor function to calculate the sum ; return total divisors ; Driver program to run the cases\\\"\\nSolution in php:\",\"targets\":\"< ? php $ allPrimes = array ( ) ; function sieve ( $ n ) { global $ allPrimes ; $ prime = array_fill ( 0 , $ n + 1 , true ) ; for ( $ p = 2 ; $ p * $ p <= $ n ; $ p ++ ) { if ( $ prime [ $ p ] == true ) { for ( $ i = $ p * 2 ; $ i <= $ n ; $ i += $ p ) $ prime [ $ i ] = false ; } } for ( $ p = 2 ; $ p <= $ n ; $ p ++ ) if ( $ prime [ $ p ] ) array_push ( $ allPrimes , $ p ) ; } function factorialDivisors ( $ n ) { global $ allPrimes ; $ result = 1 ; for ( $ i = 0 ; $ i < count ( $ allPrimes ) ; $ i ++ ) { $ p = $ allPrimes [ $ i ] ; $ exp = 0 ; while ( $ p <= $ n ) { $ exp = $ exp + ( int ) ( $ n \\/ $ p ) ; $ p = $ p * $ allPrimes [ $ i ] ; } $ result = $ result * ( pow ( $ allPrimes [ $ i ] , $ exp +1 ) - 1 ) \\/ ( $ allPrimes [ $ i ] - 1 ) ; } return $ result ; } print ( factorialDivisors ( 4 ) ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Reduce given three Numbers by decrementing in Pairs | Function to find the minimum number operations ; Insert the three numbers in array ; Sort the array ; Case 2 ; Case 1 ; Given A , B , C ; Function call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function solution ( A , B , C ) { let arr = Array . from ( { length : 3 } , ( _ , i ) => 0 ) ; arr [ 0 ] = A ; arr [ 1 ] = B ; arr [ 2 ] = C ; arr . sort ( ) ; if ( arr [ 2 ] < arr [ 0 ] + arr [ 1 ] ) return ( ( arr [ 0 ] + arr [ 1 ] + arr [ 2 ] ) \\/ 2 ) ; else return ( arr [ 0 ] + arr [ 1 ] ) ; } let A = 8 , B = 1 , C = 5 ; document . write ( solution ( A , B , C ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Partition a string into palindromic strings of at least length 2 with every character present in a single string | Function to check if a string can be split into palindromic strings of at least length 2 by including every character exactly once ; Stores the frequency of each character ; Store the frequency of characters with frequencies 1 and even respectively ; Traverse the string s ; Iterate over all the characters ; If the frequency is 1 ; If frequency is even ; Print the result ; Stores the number of characters with frequency equal to 1 that are not part of a palindromic string ; Iterate over all the characters ; If o becomes less than 0 , then break out of the loop ; If frequency of the current character is > 2 and is odd ; Update the value of o ; If a single character is still remaining ; Increment o by 1 ; Set a [ i ] to 1 ; Print the result ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function checkPalindrome ( s ) { let a = [ 0 ] let o = 0 , e = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) a [ s . charCodeAt ( i ) - 97 ] ++ ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( a [ i ] == 1 ) o ++ ; else if ( a [ i ] % 2 == 0 && a [ i ] != 0 ) e += ( a [ i ] \\/ 2 ) ; } if ( e >= o ) document . write ( \\\" \\\" ) else { o = o - e ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( o <= 0 ) break ; if ( o > 0 && a [ i ] % 2 == 1 && a [ i ] > 2 ) { let k = o ; o = o - a [ i ] \\/ 2 ; if ( o > 0 2 * k + 1 == a [ i ] ) { o ++ ; a [ i ] = 1 ; } } } if ( o <= 0 ) document . write ( \\\" \\\" ) else document . write ( \\\" \\\" ) } } let S = \\\" \\\" ; checkPalindrome ( S ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Largest number in given Array formed by repeatedly combining two same elements | C ++ implementation of the above approach ; Function to return the largest sum ; Variable to store the largest sum ; Map to store the frequencies of each element ; Store the Frequencies ; Loop to combine duplicate elements and update the sum in the map ; If j is a duplicate element ; Update the frequency of 2 * j ; If the new sum is greater than maximum value , Update the maximum ; Returns the largest sum ; Driver Code ; Function Calling\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int largest_sum ( int arr [ ] , int n ) { int maximum = -1 ; map < int , int > m ; for ( int i = 0 ; i < n ; i ++ ) { m [ arr [ i ] ] ++ ; } for ( auto j : m ) { if ( j . second > 1 ) { m [ 2 * j . first ] = m [ 2 * j . first ] + j . second \\/ 2 ; if ( 2 * j . first > maximum ) maximum = 2 * j . first ; } } return maximum ; } int main ( ) { int arr [ ] = { 1 , 1 , 2 , 4 , 7 , 8 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << largest_sum ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find all factors of a natural number | Set 1 | method to print the divisors ; Driver method\\\"\\nSolution in Python:\",\"targets\":\"def printDivisors ( n ) :\\n\\ti = 1\\n\\twhile i <= n :\\n\\t\\tif ( n % i == 0 ) :\\n\\t\\t\\tprint i ,\\n\\t\\ti = i + 1\\nprint \\\" The \u2581 divisors \u2581 of \u2581 100 \u2581 are : \u2581 \\\"\\nprintDivisors ( 100 )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find all factors of a natural number | Set 1 | A Better ( than Naive ) Solution to find all divisors ; method to print the divisors ; Note that this loop runs till square root ; If divisors are equal , print only one ; else Otherwise print both ; Driver method\\\"\\nSolution in Java:\",\"targets\":\"class Test { static void printDivisors ( int n ) { for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n \\/ i == i ) System . out . print ( \\\" \u2581 \\\" + i ) ; System . out . print ( i + \\\" \u2581 \\\" + n \\/ i + \\\" \u2581 \\\" ) ; } } } public static void main ( String args [ ] ) { System . out . println ( \\\" The \u2581 divisors \u2581 of \u2581 100 \u2581 are : \u2581 \\\" ) ; printDivisors ( 100 ) ; ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sum of products of all combination taken ( 1 to n ) at a time | C # Program to find sum of all combination takne ( 1 to N ) at a time using dynamic programming ; find the postfix sum array ; modify the array such that we don 't have to compute the products which are obtained before ; finding sum of all combination taken 1 to N at a time ; sum taken 1 at time is simply sum of 1 - N ; for sum of products for all combination ; finding postfix array ; sum of products taken i + 1 at a time ; modify the array for overlapping problem ; Driver 's Code ; storing numbers from 1 to N ; calling allCombination\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void postfix ( int [ ] a , int n ) { for ( int i = n - 1 ; i > 0 ; i -- ) { a [ i - 1 ] = a [ i - 1 ] + a [ i ] ; } } static void modify ( int [ ] a , int n ) { for ( int i = 1 ; i < n ; i ++ ) { a [ i - 1 ] = i * a [ i ] ; } } static void allCombination ( int [ ] a , int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { sum += i ; } Console . WriteLine ( \\\" f ( 1 ) \u2581 - - > \u2581 \\\" + sum ) ; for ( int i = 1 ; i < n ; i ++ ) { postfix ( a , n - i + 1 ) ; sum = 0 ; for ( int j = 1 ; j <= n - i ; j ++ ) { sum += ( j * a [ j ] ) ; } Console . WriteLine ( \\\" f ( \\\" + ( i + 1 ) + \\\" ) \u2581 - - > \u2581 \\\" + sum ) ; modify ( a , n ) ; } } public static void Main ( String [ ] args ) { int n = 5 ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = i + 1 ; } allCombination ( a , n ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Program to print ' N ' alphabet using the number pattern from 1 to n | C implementation of the approach ; Function to print the desired Alphabet N Pattern ; Declaring the values of Right , Left and Diagonal values ; Main Loop for the rows ; For the left Values ; Spaces for the diagonals ; Condition for the diagonals ; Spaces for the Right Values ; For the right values ; Driver Code ; Size of the Pattern ; Calling the function to print the desired Pattern\\\"\\nSolution in C:\",\"targets\":\"#include \\nvoid Alphabet_N_Pattern ( int N ) { int index , side_index , size ; int Right = 1 , Left = 1 , Diagonal = 2 ; for ( index = 0 ; index < N ; index ++ ) { printf ( \\\" % d \\\" , Left ++ ) ; for ( side_index = 0 ; side_index < 2 * ( index ) ; side_index ++ ) printf ( \\\" \u2581 \\\" ) ; if ( index != 0 && index != N - 1 ) printf ( \\\" % d \\\" , Diagonal ++ ) ; else printf ( \\\" \u2581 \\\" ) ; for ( side_index = 0 ; side_index < 2 * ( N - index - 1 ) ; side_index ++ ) printf ( \\\" \u2581 \\\" ) ; printf ( \\\" % d \\\" , Right ++ ) ; printf ( \\\" \\n \\\" ) ; } } int main ( int argc , char * * argv ) { int Size = 6 ; Alphabet_N_Pattern ( Size ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Deletion at different positions in a Circular Linked List | Function to delete First node of Circular Linked List ; check if list doesn 't have any node if not then return ; check if list have single node if yes then delete it and return ; traverse second node to first ; now previous is last node and first node ( firstNode ) link address put in last node ( previous ) link ; make second node as head node\\nHow can the above be solved in C?\",\"targets\":\"void DeleteFirst ( struct Node * * head ) { struct Node * previous = * head , * firstNode = * head ; if ( * head == NULL ) { printf ( \\\" List is empty \\\" return ; } if ( previous -> next == previous ) { * head = NULL ; return ; } while ( previous -> next != * head ) { previous = previous -> next ; } previous -> next = firstNode -> next ; * head = previous -> next ; free ( firstNode ) ; return ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Generate all binary strings without consecutive 1 's | C # program to Generate all binary string without consecutive 1 's of size K ; Array conversion to String -- ; Base Condition when we reached at the end of Array * * ; Printing the Generated String * * Return to the previous case * ; If the first Character is Zero then adding * * ; If the Character is One then add Zero to next * * ; Calling Recursively for the next value of Array ; Initializing first character to Zero ; Generating Strings starting with Zero -- ; Initialized first Character to one -- ; Driver code ; Calling function fun with argument k\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static string toString ( char [ ] a ) { string String = new string ( a ) ; return String ; } static void generate ( int k , char [ ] ch , int n ) { if ( n == k ) { Console . Write ( toString ( ch ) + \\\" \u2581 \\\" ) ; return ; } if ( ch [ n - 1 ] == '0' ) { ch [ n ] = '0' ; generate ( k , ch , n + 1 ) ; ch [ n ] = '1' ; generate ( k , ch , n + 1 ) ; } if ( ch [ n - 1 ] == '1' ) { ch [ n ] = '0' ; generate ( k , ch , n + 1 ) ; } } static void fun ( int k ) { if ( k <= 0 ) { return ; } char [ ] ch = new char [ k ] ; ch [ 0 ] = '0' ; generate ( k , ch , 1 ) ; ch [ 0 ] = '1' ; generate ( k , ch , 1 ) ; } static void Main ( ) { int k = 3 ; fun ( k ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"The Knight 's tour problem | Backtracking | C program for Knight Tour problem ; A utility function to check if i , j are valid indexes for N * N chessboard ; A utility function to print solution matrix sol [ N ] [ N ] ; This function solves the Knight Tour problem using Backtracking . This function mainly uses solveKTUtil ( ) to solve the problem . It returns false if no complete tour is possible , otherwise return true and prints the tour . Please note that there may be more than one solutions , this function prints one of the feasible solutions . ; Initialization of solution matrix ; xMove [ ] and yMove [ ] define next move of Knight . xMove [ ] is for next value of x coordinate yMove [ ] is for next value of y coordinate ; Since the Knight is initially at the first block ; Start from 0 , 0 and explore all tours using solveKTUtil ( ) ; A recursive utility function to solve Knight Tour problem ; Try all next moves from the current coordinate x , y ; backtracking ; Driver Code ; Function Call\\\"\\nSolution in C:\",\"targets\":\"#include \\n#define N 8\\nint solveKTUtil ( int x , int y , int movei , int sol [ N ] [ N ] , int xMove [ ] , int yMove [ ] ) ; int isSafe ( int x , int y , int sol [ N ] [ N ] ) { return ( x >= 0 && x < N && y >= 0 && y < N && sol [ x ] [ y ] == -1 ) ; } void printSolution ( int sol [ N ] [ N ] ) { for ( int x = 0 ; x < N ; x ++ ) { for ( int y = 0 ; y < N ; y ++ ) printf ( \\\" \u2581 % 2d \u2581 \\\" , sol [ x ] [ y ] ) ; printf ( \\\" \\n \\\" ) ; } } int solveKT ( ) { int sol [ N ] [ N ] ; for ( int x = 0 ; x < N ; x ++ ) for ( int y = 0 ; y < N ; y ++ ) sol [ x ] [ y ] = -1 ; int xMove [ 8 ] = { 2 , 1 , -1 , -2 , -2 , -1 , 1 , 2 } ; int yMove [ 8 ] = { 1 , 2 , 2 , 1 , -1 , -2 , -2 , -1 } ; sol [ 0 ] [ 0 ] = 0 ; if ( solveKTUtil ( 0 , 0 , 1 , sol , xMove , yMove ) == 0 ) { printf ( \\\" Solution \u2581 does \u2581 not \u2581 exist \\\" ) ; return 0 ; } else printSolution ( sol ) ; return 1 ; } int solveKTUtil ( int x , int y , int movei , int sol [ N ] [ N ] , int xMove [ N ] , int yMove [ N ] ) { int k , next_x , next_y ; if ( movei == N * N ) return 1 ; for ( k = 0 ; k < 8 ; k ++ ) { next_x = x + xMove [ k ] ; next_y = y + yMove [ k ] ; if ( isSafe ( next_x , next_y , sol ) ) { sol [ next_x ] [ next_y ] = movei ; if ( solveKTUtil ( next_x , next_y , movei + 1 , sol , xMove , yMove ) == 1 ) return 1 ; else sol [ next_x ] [ next_y ] = -1 ; } } return 0 ; } int main ( ) { solveKT ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Smallest element greater than X not present in the array | Function to return the smallest element greater than x which is not present in a [ ] ; Sort the array ; Continue until low is less than or equals to high ; Find mid ; If element at mid is less than or equals to searching element ; If mid is equals to searching element ; Increment searching element ; Make high as N - 1 ; Make low as mid + 1 ; Make high as mid - 1 ; Return the next greater element ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function Next_greater ( $ a , $ n , $ x ) { sort ( $ a ) ; $ low = 0 ; $ high = $ n - 1 ; $ ans = $ x + 1 ; while ( $ low <= $ high ) { $ mid = ( $ low + $ high ) \\/ 2 ; if ( $ a [ $ mid ] <= $ ans ) { if ( $ a [ $ mid ] == $ ans ) { $ ans ++ ; $ high = $ n - 1 ; } $ low = $ mid + 1 ; } else $ high = $ mid - 1 ; } return $ ans ; } $ a = array ( 1 , 5 , 10 , 4 , 7 ) ; $ x = 4 ; $ n = count ( $ a ) ; echo Next_greater ( $ a , $ n , $ x ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of chairs required to ensure that every worker is seated at any instant | C # program to implement the above approach ; Function to find the minimum number of chairs required to ensure that every worker is seated at any time ; Stores the number of chairs required ; Pointer to iterate ; Stores minimum number of chairs required ; Iterate over every character ; If character is ' E ' ; Increase the count ; Otherwise ; Update maximum value of count obtained at any given time ; Return mini ; Driver code ; Given String ; Function call to find the minimum number of chairs\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int findMinimumChairs ( string s ) { int count = 0 ; int i = 0 ; int mini = Int32 . MinValue ; while ( i < s . Length ) { if ( s [ i ] == ' E ' ) count ++ ; else count -- ; mini = Math . Max ( count , mini ) ; i ++ ; } return mini ; } public static void Main ( ) { string s = \\\" EELEE \\\" ; Console . WriteLine ( findMinimumChairs ( s ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Program to find area of a Circular Segment | Function to find area of segment ; Calculating area of sector ; Calculating area of triangle ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function area_of_segment ( $ radius , $ angle ) { $ pi = 3.14159 ; $ area_of_sector = $ pi * ( $ radius * $ radius ) * ( $ angle \\/ 360 ) ; $ area_of_triangle = 1 \\/ 2 * ( $ radius * $ radius ) * sin ( ( $ angle * $ pi ) \\/ 180 ) ; return $ area_of_sector - $ area_of_triangle ; } $ radius = 10.0 ; $ angle = 90.0 ; echo ( \\\" Area \u2581 of \u2581 minor \u2581 segment \u2581 = \u2581 \\\" ) ; echo ( area_of_segment ( $ radius , $ angle ) ) ; echo ( \\\" \\n \\\" ) ; echo ( \\\" Area \u2581 of \u2581 major \u2581 segment \u2581 = \u2581 \\\" ) ; echo ( area_of_segment ( $ radius , ( 360 - $ angle ) ) ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to print modified Binary triangle pattern | C ++ implementation to print the modified binary triangle pattern ; Function to print the modified binary pattern ; Loop to traverse the rows ; Loop to traverse the numbers in each row ; Check if j is 1 or i In either case print 1 ; Else print 0 ; Change the cursor to next line after each row ; Driver Code ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void modifiedBinaryPattern ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { if ( j == 1 j == i ) cout << 1 ; else cout << 0 ; } cout << endl ; } } int main ( ) { int n = 7 ; modifiedBinaryPattern ( n ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to find whether a given number is power of 2 | ; Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\n#define bool int\\nbool isPowerOfTwo ( int x ) { return x && ( ! ( x & ( x - 1 ) ) ) ; } int main ( ) { isPowerOfTwo ( 31 ) ? printf ( \\\" Yes \\n \\\" ) : printf ( \\\" No \\n \\\" ) ; isPowerOfTwo ( 64 ) ? printf ( \\\" Yes \\n \\\" ) : printf ( \\\" No \\n \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Disjoint Set Union on trees | Set 1 | Python3 code to find maximum subtree such that all nodes are even in weight ; Structure for Edge ; ' id ' : stores parent of a node . ' sz ' : stores size of a DSU tree . ; Function to assign root ; Function to find Union ; Utility function for Union ; Edge between ' u ' and 'v ; 0 - indexed nodes ; If weights of both ' u ' and ' v ' are even then we make union of them . ; Function to find maximum size of DSU tree ; Driver code ; Weights of nodes ; Number of nodes in a tree ; Initializing every node as a tree with single node . ; Find maximum size of DSU tree .\\\"\\nHow can the above be solved in Python?\",\"targets\":\"N = 100010\\nclass Edge :\\n\\tdef __init__ ( self , u , v ) :\\n\\t\\tself . u = u\\n\\t\\tself . v = v\\nid = [ 0 for i in range ( N ) ]\\nsz = [ 0 for i in range ( N ) ] ;\\ndef Root ( idx ) :\\n\\ti = idx ;\\n\\twhile ( i != id [ i ] ) :\\n\\t\\tid [ i ] = id [ id [ i ] ]\\n\\t\\ti = id [ i ] ;\\n\\treturn i ;\\ndef Union ( a , b ) :\\n\\ti = Root ( a )\\n\\tj = Root ( b ) ;\\n\\tif ( i != j ) :\\n\\t\\tif ( sz [ i ] >= sz [ j ] ) :\\n\\t\\t\\tid [ j ] = i\\n\\t\\t\\tsz [ i ] += sz [ j ] ;\\n\\t\\t\\tsz [ j ] = 0 ;\\n\\t\\telse :\\n\\t\\t\\tid [ i ] = j\\n\\t\\t\\tsz [ j ] += sz [ i ] ;\\n\\t\\t\\tsz [ i ] = 0 ;\\ndef UnionUtil ( e , W , q ) :\\n\\tfor i in range ( q ) :\\n'\\n\\tu = e [ i ] . u\\n\\tv = e [ i ] . v\\n\\tu -= 1\\n\\tv -= 1\\n\\tif ( W [ u ] % 2 == 0 and W [ v ] % 2 == 0 ) :\\n\\t\\tUnion ( u , v ) ;\\ndef findMax ( n , W ) :\\n\\tmaxi = 0\\n\\tfor i in range ( 1 , n ) :\\n\\t\\tif ( W [ i ] % 2 == 0 ) :\\n\\t\\t\\tmaxi = max ( maxi , sz [ i ] ) ;\\n\\treturn maxi ;\\nif __name__ == ' _ _ main _ _ ' :\\n\\tW = [ 1 , 2 , 6 , 4 , 2 , 0 , 3 ]\\n\\tn = len ( W )\\n\\tfor i in range ( n ) :\\n\\t\\tid [ i ] = i\\n\\t\\tsz [ i ] = 1 ;\\n\\te = [ Edge ( 1 , 2 ) , Edge ( 1 , 3 ) , Edge ( 2 , 4 ) , Edge ( 2 , 5 ) , Edge ( 4 , 6 ) , Edge ( 6 , 7 ) ]\\n\\tq = len ( e )\\n\\tUnionUtil ( e , W , q ) ;\\n\\tmaxi = findMax ( n , W ) ;\\n\\tprint ( \\\" Maximum \u2581 size \u2581 of \u2581 the \u2581 subtree \u2581 with \u2581 \\\" , end = ' ' ) ;\\n\\tprint ( \\\" even \u2581 weighted \u2581 nodes \u2581 = \\\" , maxi ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Average of a stream of numbers | ; Returns the new average after including x ; Prints average of a stream of numbers ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int sum , n ; static float getAvg ( int x ) { sum += x ; return ( ( ( float ) sum ) \\/ ++ n ) ; } static void streamAvg ( float [ ] arr , int n ) { float avg = 0 ; for ( int i = 0 ; i < n ; i ++ ) { avg = getAvg ( ( int ) arr [ i ] ) ; Console . WriteLine ( \\\" Average \u2581 of \u2581 { 0 } \u2581 numbers \u2581 \\\" + \\\" is \u2581 { 1 } \\\" , ( i + 1 ) , avg ) ; } return ; } static int Main ( ) { float [ ] arr = new float [ ] { 10 , 20 , 30 , 40 , 50 , 60 } ; int n = arr . Length ; streamAvg ( arr , n ) ; return 0 ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sort a Rotated Sorted Array | C # implementation for restoring original sort in rotated sorted array using binary search ; Function to find start index of array ; Function to restore the Original Sort ; array is already sorted ; In reverse ( ) , the first parameter is iterator to beginning element and second parameter is iterator to last element plus one . ; Function to print the Array ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int findStartIndexOfArray ( int [ ] arr , int low , int high ) { if ( low > high ) { return - 1 ; } if ( low == high ) { return low ; } int mid = low + ( high - low ) \\/ 2 ; if ( arr [ mid ] > arr [ mid + 1 ] ) { return mid + 1 ; } if ( arr [ mid - 1 ] > arr [ mid ] ) { return mid ; } if ( arr [ low ] > arr [ mid ] ) { return findStartIndexOfArray ( arr , low , mid - 1 ) ; } else { return findStartIndexOfArray ( arr , mid + 1 , high ) ; } } static void restoreSortedArray ( int [ ] arr , int n ) { if ( arr [ 0 ] < arr [ n - 1 ] ) { return ; } int start = findStartIndexOfArray ( arr , 0 , n - 1 ) ; Array . Sort ( arr , 0 , start ) ; Array . Sort ( arr , start , n ) ; Array . Sort ( arr ) ; } static void printArray ( int [ ] arr , int size ) { for ( int i = 0 ; i < size ; i ++ ) { Console . Write ( arr [ i ] + \\\" \u2581 \\\" ) ; } } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . Length ; restoreSortedArray ( arr , n ) ; printArray ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check for Integer Overflow |\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\n#include \\nint addOvf ( int * result , int a , int b ) { if ( a > INT_MAX - b ) return -1 ; else { * result = a + b ; return 0 ; } } int main ( ) { int * res = ( int * ) malloc ( sizeof ( int ) ) ; int x = 2147483640 ; int y = 10 ; printf ( \\\" % d \\\" , addOvf ( res , x , y ) ) ; printf ( \\\" % d \\\" , * res ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Two Pointers Technique | Naive solution to find if there is a pair in A [ 0. . N - 1 ] with given sum . ; as equal i and j means same element ; pair exists ; as the array is sorted ; No pair found with given sum . ; Driver Code ; Function call\\\"\\nSolution in C:\",\"targets\":\"#include \\nint isPairSum ( int A [ ] , int N , int X ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( i == j ) continue ; if ( A [ i ] + A [ j ] == X ) return true ; if ( A [ i ] + A [ j ] > X ) break ; } } return 0 ; } int main ( ) { int arr [ ] = { 3 , 5 , 9 , 2 , 8 , 10 , 11 } ; int val = 17 ; int arrSize = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" % d \\\" , isPairSum ( arr , arrSize , val ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum operations required to convert all characters of a String to a given Character | Function to find the minimum number of operations required ; Maximum number of characters that can be changed in one operation ; If length of the less than maximum number of characters that can be changed in an operation ; Set the last index as the index for the operation ; Otherwise ; If size of the is equal to the maximum number of characters in an operation ; Find the number of operations required ; Find the starting position ; Print i - th index ; Shift to next index ; Otherwise ; Find the number of operations required ; If n % div exceeds k ; Print i - th index ; Shift to next index ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def countOperations ( n , k ) :\\n\\tdiv = 2 * k + 1\\n\\tif ( n \\/\\/ 2 <= k ) :\\n\\t\\tprint ( 1 )\\n\\t\\tif ( n > k ) :\\n\\t\\t\\tprint ( k + 1 )\\n\\t\\telse :\\n\\t\\t\\tprint ( n )\\n\\telse :\\n\\t\\tif ( n % div == 0 ) :\\n\\t\\t\\toprn = n \\/\\/ div\\n\\t\\t\\tprint ( oprn )\\n\\t\\t\\tpos = k + 1\\n\\t\\t\\tprint ( pos , end = \\\" \u2581 \\\" )\\n\\t\\t\\tfor i in range ( 1 , oprn + 1 ) :\\n\\t\\t\\t\\tprint ( pos , end = \\\" \u2581 \\\" )\\n\\t\\t\\t\\tpos += div\\n\\t\\telse :\\n\\t\\t\\toprn = n \\/\\/ div + 1\\n\\t\\t\\tprint ( oprn )\\n\\t\\t\\tpos = n % div\\n\\t\\t\\tif ( n % div > k ) :\\n\\t\\t\\t\\tpos -= k\\n\\t\\t\\tfor i in range ( 1 , oprn + 1 ) :\\n\\t\\t\\t\\tprint ( pos , end = \\\" \u2581 \\\" )\\n\\t\\t\\t\\tpos += div\\nif __name__ == ' _ _ main _ _ ' :\\n\\tstr = \\\" edfreqwsazxet \\\"\\n\\tch = ' $ '\\n\\tn = len ( str )\\n\\tk = 4\\n\\tcountOperations ( n , k )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Nearest smaller character to a character K from a Sorted Array | Function to return the nearest smaller letacter ; Stores the nearest smaller letacter ; Iterate till starts cross end ; Find the mid element ; Check if K is found ; Check if current letacter is less than K ; Increment the start ; Otherwise ; Increment end ; Return the letacter ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function bs ( ar , n , ele ) { let start = 0 ; let end = n - 1 ; let ch = ' ' ; while ( start <= end ) { let mid = start + Math . floor ( ( end - start ) \\/ 2 ) ; if ( ar [ mid ] == ele ) end = mid - 1 ; else if ( ar [ mid ] < ele ) { ch = ar [ mid ] ; start = mid + 1 ; } else end = mid - 1 ; } return ch ; } let ar = [ ' ' , ' ' , ' ' , ' ' ] ; let n = ar . length ; let K = ' ' ; let ch = bs ( ar , n , K ) ; if ( ch == ' ' ) document . write ( \\\" \\\" ) ; else document . write ( ch ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Pairs of complete strings in two sets of strings | Returns count of complete pairs from set [ 0. . n - 1 ] and set2 [ 0. . m - 1 ] ; Consider all pairs of both strings ; Create a concatenation of current pair ; Compute frequencies of all characters in the concatenated String . ; If frequency of any character is not greater than 0 , then this pair is not complete . ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function countCompletePairs ( set1 , set2 , n , m ) { let result = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { let concat = set1 [ i ] + set2 [ j ] ; let frequency = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { frequency [ i ] = 0 ; } for ( let k = 0 ; k < concat . length ; k ++ ) { frequency [ concat [ k ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } let k ; for ( k = 0 ; k < 26 ; k ++ ) { if ( frequency [ k ] < 1 ) { break ; } } if ( k == 26 ) { result ++ ; } } } return result ; } let set1 = [ \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" ] ; let set2 = [ \\\" \\\" , \\\" \\\" , \\\" \\\" ] let n = set1 . length ; let m = set2 . length ; document . write ( countCompletePairs ( set1 , set2 , n , m ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find all factors of a natural number | Set 1 | C implementation of Naive method to print all divisors ; function to print the divisors ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\nvoid printDivisors ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) if ( n % i == 0 ) printf ( \\\" % d \u2581 \\\" , i ) ; } int main ( ) { printf ( \\\" The \u2581 divisors \u2581 of \u2581 100 \u2581 are : \u2581 \\n \\\" ) ; printDivisors ( 100 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find count of Almost Prime numbers from 1 to N | PHP program to count almost prime numbers from 1 to n ; Create a boolean array \\\" prime [ 0 . . n ] \\\" and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Function to count almost prime numbers from 1 to n ; to store required answer ; 6 is first almost prime number ; to count prime factors ; if it is perfect square ; if I is almost prime number ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ N = 100005 ; $ prime = array_fill ( 0 , $ N , true ) ; function SieveOfEratosthenes ( ) { global $ N , $ prime ; $ prime [ 1 ] = false ; for ( $ p = 2 ; $ p < ( int ) ( sqrt ( $ N ) ) ; $ p ++ ) { if ( $ prime [ $ p ] == true ) for ( $ i = 2 * $ p ; $ i < $ N ; $ i += $ p ) $ prime [ $ i ] = false ; } } function almostPrimes ( $ n ) { global $ prime ; $ ans = 0 ; for ( $ i = 6 ; $ i < $ n + 1 ; $ i ++ ) { $ c = 0 ; for ( $ j = 2 ; $ i >= $ j * $ j ; $ j ++ ) { if ( $ i % $ j == 0 ) { if ( $ j * $ j == $ i ) { if ( $ prime [ $ j ] ) $ c += 1 ; } else { if ( $ prime [ $ j ] ) $ c += 1 ; if ( $ prime [ ( $ i \\/ $ j ) ] ) $ c += 1 ; } } } if ( $ c == 2 ) $ ans += 1 ; } return $ ans ; } SieveOfEratosthenes ( ) ; $ n = 21 ; print ( almostPrimes ( $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Hectagon Number | C program for above approach ; Finding the nth hectagon Number ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nint hectagonNum ( int n ) { return ( 98 * n * n - 96 * n ) \\/ 2 ; } int main ( ) { int n = 3 ; printf ( \\\"3rd \u2581 hectagon \u2581 Number \u2581 is \u2581 = \u2581 % d \\\" , hectagonNum ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Count all possible groups of size 2 or 3 that have sum as multiple of 3 | C Program to count all possible groups of size 2 or 3 that have sum as multiple of 3 ; Returns count of all possible groups that can be formed from elements of a [ ] . ; Create an array C [ 3 ] to store counts of elements with remainder 0 , 1 and 2. c [ i ] would store count of elements with remainder i ; To store the result ; Count elements with remainder 0 , 1 and 2 ; Case 3. a : Count groups of size 2 from 0 remainder elements ; Case 3. b : Count groups of size 2 with one element with 1 remainder and other with 2 remainder ; Case 4. a : Count groups of size 3 with all 0 remainder elements ; Case 4. b : Count groups of size 3 with all 1 remainder elements ; Case 4. c : Count groups of size 3 with all 2 remainder elements ; Case 4. c : Count groups of size 3 with different remainders ; Return total count stored in res ; Driver program to test above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint findgroups ( int arr [ ] , int n ) { int c [ 3 ] = { 0 } , i ; int res = 0 ; for ( i = 0 ; i < n ; i ++ ) c [ arr [ i ] % 3 ] ++ ; res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ; res += c [ 1 ] * c [ 2 ] ; res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) \\/ 6 ; res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) \\/ 6 ; res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) \\/ 6 ) ; res += c [ 0 ] * c [ 1 ] * c [ 2 ] ; return res ; } int main ( ) { int arr [ ] = { 3 , 6 , 7 , 2 , 9 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Required \u2581 number \u2581 of \u2581 groups \u2581 are \u2581 % d \\n \\\" , findgroups ( arr , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Print triplets with sum less than k | A Simple JavaScript program to count triplets with sum smaller than a given value ; Fix the first element as A [ i ] ; Fix the second element as A [ j ] ; Now look for the third number ; Driver program\\\"\\nSolution in Javascript:\",\"targets\":\"function printTriplets ( arr , n , sum ) { for ( let i = 0 ; i < n - 2 ; i ++ ) { for ( let j = i + 1 ; j < n - 1 ; j ++ ) { for ( let k = j + 1 ; k < n ; k ++ ) if ( arr [ i ] + arr [ j ] + arr [ k ] < sum ) document . write ( arr [ i ] + \\\" \\\" + arr [ j ] + \\\" \\\" + arr [ k ] + \\\" \\\" ) ; } } } let arr = [ 5 , 1 , 3 , 4 , 7 ] ; let n = arr . length ; let sum = 12 ; printTriplets ( arr , n , sum ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sorted insert in a doubly linked list with head and tail pointers | C program to insetail nodes in doubly linked list such that list remains in ascending order on printing from left to right ; A linked list node ; Function to insetail new node ; If first node to be insetailed in doubly linked list ; If node to be insetailed has value less than first node ; If node to be insetailed has value more than last node ; Find the node before which we need to insert p . ; Insert new node before temp ; Function to print nodes in from left to right ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nstruct Node { struct Node * prev ; int info ; struct Node * next ; } ; void nodeInsetail ( struct Node * * head , struct Node * * tail , int key ) { struct Node * p = new Node ; p -> info = key ; p -> next = NULL ; if ( ( * head ) == NULL ) { ( * head ) = p ; ( * tail ) = p ; ( * head ) -> prev = NULL ; return ; } if ( ( p -> info ) < ( ( * head ) -> info ) ) { p -> prev = NULL ; ( * head ) -> prev = p ; p -> next = ( * head ) ; ( * head ) = p ; return ; } if ( ( p -> info ) > ( ( * tail ) -> info ) ) { p -> prev = ( * tail ) ; ( * tail ) -> next = p ; ( * tail ) = p ; return ; } temp = ( * head ) -> next ; while ( ( temp -> info ) < ( p -> info ) ) temp = temp -> next ; ( temp -> prev ) -> next = p ; p -> prev = temp -> prev ; temp -> prev = p ; p -> next = temp ; } void printList ( struct Node * temp ) { while ( temp != NULL ) { printf ( \\\" % d \u2581 \\\" , temp -> info ) ; temp = temp -> next ; } } int main ( ) { struct Node * left = NULL , * right = NULL ; nodeInsetail ( & left , & right , 30 ) ; nodeInsetail ( & left , & right , 50 ) ; nodeInsetail ( & left , & right , 90 ) ; nodeInsetail ( & left , & right , 10 ) ; nodeInsetail ( & left , & right , 40 ) ; nodeInsetail ( & left , & right , 110 ) ; nodeInsetail ( & left , & right , 60 ) ; nodeInsetail ( & left , & right , 95 ) ; nodeInsetail ( & left , & right , 23 ) ; printf ( \\\" Doubly linked list on printing \\\" \u2581 \\\" from left to right \\\" printList ( left ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to find whether a given number is power of 2 | Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function isPowerOfTwo ( $ x ) { return $ x && ( ! ( $ x & ( $ x - 1 ) ) ) ; } if ( isPowerOfTwo ( 31 ) ) echo \\\" Yes \\n \\\" ; else echo \\\" No \\n \\\" ; if ( isPowerOfTwo ( 64 ) ) echo \\\" Yes \\n \\\" ; else echo \\\" No \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximize the minimum array element by M subarray increments of size S | Function to return index of minimum element in the array ; Initialize a [ 0 ] as minValue ; Traverse the array ; If a [ i ] < existing minValue ; Return the minimum index ; Function that maximize the minimum element of array after incrementing subarray of size S by 1 , M times ; Iterating through the array or M times ; Find minimum element index ; Increment the minimum value ; Storing the left index and right index ; Incrementing S - 1 minimum elements to the left and right of minValue ; Reached extreme left ; Reached extreme right ; Left value is minimum ; Right value is minimum ; Find the minValue in A [ ] after M operations ; Return the minimum value ; Driver Code ; Function Call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function min1 ( a , n ) { let minIndex = 0 , minValue = a [ 0 ] , i ; for ( i = 1 ; i < n ; i ++ ) { if ( a [ i ] < minValue ) { minValue = a [ i ] ; minIndex = i ; } } return minIndex ; } function maximizeMin ( A , N , S , M ) { let minIndex , left , right , i , j ; for ( i = 0 ; i < M ; i ++ ) { minIndex = min1 ( A , N ) ; A [ minIndex ] ++ ; left = minIndex - 1 ; right = minIndex + 1 ; for ( j = 0 ; j < S - 1 ; j ++ ) { if ( left == - 1 ) A [ right ++ ] ++ ; else if ( right == N ) A [ left -- ] ++ ; else { if ( A [ left ] < A [ right ] ) A [ left -- ] ++ ; else A [ right ++ ] ++ ; } } } minIndex = min1 ( A , N ) ; return A [ minIndex ] ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let N = arr . length ; let S = 2 , M = 3 ; document . write ( maximizeMin ( arr , N , S , M ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Insert node into the middle of the linked list | head of list ; Node Class ; Constructor to create a new node ; function to insert node at the middle of the linked list ; if list is empty ; get a new node ; calculate length of the linked list , i . e , the number of nodes ; ' count ' the number of nodes after which the new node is to be inserted ; ' ptr ' points to the node after which the new node is to be inserted ; insert the ' newNode ' and adjust the required links ; function to display the linked list ; Creating the list 1.2 . 4.5\\\"\\nSolution in Javascript:\",\"targets\":\"var head ; class Node { constructor ( d ) { this . data = d ; this . next = null ; } } function insertAtMid ( x ) { if ( head == null ) head = new Node ( x ) ; else { var newNode = new Node ( x ) ; var ptr = head ; var len = 0 ; while ( ptr != null ) { len ++ ; ptr = ptr . next ; } var count = ( ( len % 2 ) == 0 ) ? ( len \\/ 2 ) : ( len + 1 ) \\/ 2 ; ptr = head ; while ( count -- > 1 ) ptr = ptr . next ; newNode . next = ptr . next ; ptr . next = newNode ; } } function display ( ) { var temp = head ; while ( temp != null ) { document . write ( temp . data + \\\" \\\" ) ; temp = temp . next ; } } head = new Node ( 1 ) ; head . next = new Node ( 2 ) ; head . next . next = new Node ( 4 ) ; head . next . next . next = new Node ( 5 ) ; document . write ( \\\" \\\" + \\\" \\\" ) ; display ( ) ; var x = 3 ; insertAtMid ( x ) ; document . write ( \\\" \\\" + \\\" \\\" ) ; display ( ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Linear Search | C code to linearly search x in arr [ ] . If x is present then return its location , otherwise return - 1 ; Driver code ; Function call\\\"\\nSolution in C:\",\"targets\":\"#include \\nint search ( int arr [ ] , int n , int x ) { int i ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] == x ) return i ; return -1 ; } int main ( void ) { int arr [ ] = { 2 , 3 , 4 , 10 , 40 } ; int x = 10 ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int result = search ( arr , n , x ) ; ( result == -1 ) ? printf ( \\\" Element \u2581 is \u2581 not \u2581 present \u2581 in \u2581 array \\\" ) : printf ( \\\" Element \u2581 is \u2581 present \u2581 at \u2581 index \u2581 % d \\\" , result ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find all pairs ( a , b ) in an array such that a % b = k | method to find pair such that ( a % b = k ) ; Consider each and every pair ; Print if their modulo equals to k ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function printPairs ( arr , n , k ) { let isPairFound = true ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( i != j && arr [ i ] % arr [ j ] == k ) { document . write ( \\\" \\\" + arr [ i ] + \\\" \\\" + arr [ j ] + \\\" \\\" + \\\" \\\" ) ; isPairFound = true ; } } } return isPairFound ; } let arr = [ 2 , 3 , 5 , 4 , 7 ] ; let k = 3 ; if ( printPairs ( arr , arr . length , k ) == false ) document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximum possible difference of sum of two subsets of an array | Set 2 | C # Program for the above approach ; Stores the positive elements ; Stores the negative elements ; Stores the count of 0 s ; Sum of all positive numbers ; Sum of all negative numbers ; Iterate over the array ; Stores the difference ; Sort the positive numbers in ascending order ; Sort the negative numbers in decreasing order ; Case 1 : Include both positive and negative numbers ; Put all numbers in subset A and one 0 in subset B ; Put all numbers in subset A except the smallest positive number which is put in B ; Put all numbers in subset B and one 0 in subset A ; Place the largest negative number in subset A and remaining in B ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int maxSumAfterPartition ( int [ ] arr , int n ) { List < int > pos = new List < int > ( ) ; List < int > neg = new List < int > ( ) ; int zero = 0 ; int pos_sum = 0 ; int neg_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) { pos . Add ( arr [ i ] ) ; pos_sum += arr [ i ] ; } else if ( arr [ i ] < 0 ) { neg . Add ( arr [ i ] ) ; neg_sum += arr [ i ] ; } else { zero ++ ; } } int ans = 0 ; pos . Sort ( ) ; neg . Sort ( ) ; neg . Reverse ( ) ; if ( pos . Count > 0 && neg . Count > 0 ) { ans = ( pos_sum - neg_sum ) ; } else if ( pos . Count > 0 ) { if ( zero > 0 ) { ans = ( pos_sum ) ; } else { ans = ( pos_sum - 2 * pos [ 0 ] ) ; } } else { if ( zero > 0 ) { ans = ( - 1 * neg_sum ) ; } else { ans = ( neg [ 0 ] - ( neg_sum - neg [ 0 ] ) ) ; } } return ans ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , - 5 , - 7 } ; int n = arr . Length ; Console . Write ( maxSumAfterPartition ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Bitwise AND of all the odd numbers from 1 to N | Function to return the bitwise AND of all the odd integers from the range [ 1 , n ] ; Initialize result to 1 ; Starting from 3 , bitwise AND all the odd integers less than or equal to n ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function bitwiseAndOdd ( n ) { var result = 1 ; for ( var i = 3 ; i <= n ; i = i + 2 ) { result = ( result & i ) ; } return result ; } var n = 10 ; document . write ( bitwiseAndOdd ( n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Counting Sort | C Program for counting sort ; The main function that sort the given string arr [ ] in alphabatical order ; The output character array that will have sorted arr ; Create a count array to store count of inidividul characters and initialize count array as 0 ; Store count of each character ; Change count [ i ] so that count [ i ] now contains actual position of this character in output array ; Build the output character array ; Copy the output array to arr , so that arr now contains sorted characters ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\n#define RANGE 255\\nvoid countSort ( char arr [ ] ) { char output [ strlen ( arr ) ] ; int count [ RANGE + 1 ] , i ; memset ( count , 0 , sizeof ( count ) ) ; for ( i = 0 ; arr [ i ] ; ++ i ) ++ count [ arr [ i ] ] ; for ( i = 1 ; i <= RANGE ; ++ i ) count [ i ] += count [ i - 1 ] ; for ( i = 0 ; arr [ i ] ; ++ i ) { output [ count [ arr [ i ] ] - 1 ] = arr [ i ] ; -- count [ arr [ i ] ] ; } for ( i = 0 ; arr [ i ] ; ++ i ) arr [ i ] = output [ i ] ; } int main ( ) { char arr [ ] = \\\" geeksforgeeks \\\" ; countSort ( arr ) ; printf ( \\\" Sorted \u2581 character \u2581 array \u2581 is \u2581 % sn \\\" , arr ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find the direction from given string | Function to find the final direction ; if count is positive that implies resultant is clockwise direction ; if count is negative that implies resultant is anti - clockwise direction ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findDirection ( s ) :\\n\\tcount = 0\\n\\td = \\\" \\\"\\n\\tfor i in range ( len ( s ) ) :\\n\\t\\tif ( s [ i ] == ' L ' ) :\\n\\t\\t\\tcount -= 1\\n\\t\\telse :\\n\\t\\t\\tif ( s [ i ] == ' R ' ) :\\n\\t\\t\\t\\tcount += 1\\n\\tif ( count > 0 ) :\\n\\t\\tif ( count % 4 == 0 ) :\\n\\t\\t\\td = \\\" N \\\"\\n\\t\\telif ( count % 4 == 10 ) :\\n\\t\\t\\td = \\\" E \\\"\\n\\t\\telif ( count % 4 == 2 ) :\\n\\t\\t\\td = \\\" S \\\"\\n\\t\\telif ( count % 4 == 3 ) :\\n\\t\\t\\td = \\\" W \\\"\\n\\tif ( count < 0 ) :\\n\\t\\tcount *= - 1\\n\\t\\tif ( count % 4 == 0 ) :\\n\\t\\t\\td = \\\" N \\\"\\n\\t\\telif ( count % 4 == 1 ) :\\n\\t\\t\\td = \\\" W \\\"\\n\\t\\telif ( count % 4 == 2 ) :\\n\\t\\t\\td = \\\" S \\\"\\n\\t\\telif ( count % 4 == 3 ) :\\n\\t\\t\\td = \\\" E \\\"\\n\\treturn d\\nif __name__ == ' _ _ main _ _ ' :\\n\\ts = \\\" LLRLRRL \\\"\\n\\tprint ( findDirection ( s ) )\\n\\ts = \\\" LL \\\"\\n\\tprint ( findDirection ( s ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n"