"{\"inputs\":\"\\\"Find a Fixed Point ( Value equal to index ) in a given array | Java program to check fixed point in an array using linear search ; If no fixed point present then return - 1 ; main function\\\"\\nSolution in Java:\",\"targets\":\"class Main { static int linearSearch ( int arr [ ] , int n ) { int i ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == i ) return i ; } return - 1 ; } public static void main ( String args [ ] ) { int arr [ ] = { - 10 , - 1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 } ; int n = arr . length ; System . out . println ( \\\" Fixed ▁ Point ▁ is ▁ \\\" + linearSearch ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count of Octal numbers upto N digits | C # 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 C#:\",\"targets\":\"using System ; class GFG { static int count ( int N ) { int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += ( int ) ( 7 * Math . Pow ( 8 , i - 1 ) ) ; } return sum ; } public static void Main ( ) { int N = 4 ; Console . WriteLine ( count ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Iterative function to check if two trees are identical | Iterative Java program to check if two ; A Binary Tree Node ; Iterative method to find height of Binary Tree ; Return true if both trees are empty ; Return false if one is empty and other is not ; Create an empty queues for simultaneous traversals ; Enqueue Roots of trees in respective queues ; Get front nodes and compare them ; Remove front nodes from queues ; Enqueue left children of both nodes ; If one left child is empty and other is not ; Right child code ( Similar to left child code ) ; Utility function to create a new tree node ; Driver program to test above functions\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GfG { static class Node { int data ; Node left , right ; } static boolean areIdentical ( Node root1 , Node root2 ) { if ( root1 == null && root2 == null ) return true ; if ( root1 == null root2 == null ) return false ; Queue < Node > q1 = new LinkedList < Node > ( ) ; Queue < Node > q2 = new LinkedList < Node > ( ) ; q1 . add ( root1 ) ; q2 . add ( root2 ) ; while ( ! q1 . isEmpty ( ) && ! q2 . isEmpty ( ) ) { Node n1 = q1 . peek ( ) ; Node n2 = q2 . peek ( ) ; if ( n1 . data != n2 . data ) return false ; q1 . remove ( ) ; q2 . remove ( ) ; if ( n1 . left != null && n2 . left != null ) { q1 . add ( n1 . left ) ; q2 . add ( n2 . left ) ; } else if ( n1 . left != null n2 . left != null ) return false ; if ( n1 . right != null && n2 . right != null ) { q1 . add ( n1 . right ) ; q2 . add ( n2 . right ) ; } else if ( n1 . right != null n2 . right != null ) return false ; } return true ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = null ; temp . right = null ; return temp ; } public static void main ( String [ ] args ) { Node root1 = newNode ( 1 ) ; root1 . left = newNode ( 2 ) ; root1 . right = newNode ( 3 ) ; root1 . left . left = newNode ( 4 ) ; root1 . left . right = newNode ( 5 ) ; Node root2 = newNode ( 1 ) ; root2 . left = newNode ( 2 ) ; root2 . right = newNode ( 3 ) ; root2 . left . left = newNode ( 4 ) ; root2 . left . right = newNode ( 5 ) ; if ( areIdentical ( root1 , root2 ) == true ) 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\":\"\\\"Sum of matrix in which each element is absolute difference of its row and column numbers | Retuen the sum of matrix in which each element is absolute difference of its corresponding row and column number row ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function findSum ( $ n ) { $ n -- ; $ sum = 0 ; $ sum += ( $ n * ( $ n + 1 ) ) \\/ 2 ; $ sum += ( $ n * ( $ n + 1 ) * ( 2 * $ n + 1 ) ) \\/ 6 ; return $ sum ; } $ n = 3 ; echo findSum ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to find Nth term divisible by a or b | Java program to find nth term divisible by a or b ; Function to return gcd of a and b ; Function to calculate how many numbers from 1 to num are divisible by a or b ; calculate number of terms divisible by a and by b then , remove the terms which is are divisible by both a and b ; Binary search to find the nth term divisible by a or b ; set low to 1 and high to max ( a , b ) * n , here we have taken high as 10 ^ 18 ; if the current term is less than n then we need to increase low to mid + 1 ; if current term is greater than equal to n then high = mid ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int divTermCount ( int a , int b , int lcm , int num ) { return num \\/ a + num \\/ b - num \\/ lcm ; } static int findNthTerm ( int a , int b , int n ) { int low = 1 , high = Integer . MAX_VALUE , mid ; int lcm = ( a * b ) \\/ gcd ( a , b ) ; while ( low < high ) { mid = low + ( high - low ) \\/ 2 ; if ( divTermCount ( a , b , lcm , mid ) < n ) low = mid + 1 ; else high = mid ; } return low ; } public static void main ( String [ ] args ) { int a = 2 , b = 5 , n = 10 ; System . out . println ( findNthTerm ( a , b , n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW | Java program for the above approach ; Function to find area of rectangle inscribed another rectangle of length L and width W ; Area of rectangle ; Return the area ; Driver Code ; Given dimensions ; Function call\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { static double AreaofRectangle ( int L , int W ) { double area = ( W + L ) * ( W + L ) \\/ 2 ; return area ; } public static void main ( String args [ ] ) { int L = 18 ; int W = 12 ; System . out . println ( AreaofRectangle ( L , W ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Print unique rows in a given boolean matrix | Given a binary matrix of M X N of integers , you need to return only unique rows of binary array ; A Trie node ; Only two children needed for 0 and 1 ; A utility function to allocate memory for a new Trie node ; Inserts a new matrix row to Trie . If row is already present , then returns 0 , otherwise insets the row and return 1 ; base case ; Recur if there are more entries in this row ; If all entries of this row are processed ; unique row found , return 1 ; duplicate row found , return 0 ; A utility function to print a row ; The main function that prints all unique rows in a given matrix . ; create an empty Trie ; Iterate through all rows ; insert row to TRIE ; unique row found , print it ; Driver program to test above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\n#include \\n#define ROW 4\\n#define COL 5\\ntypedef struct Node { bool isEndOfCol ; struct Node * child [ 2 ] ; } Node ; Node * newNode ( ) { Node * temp = ( Node * ) malloc ( sizeof ( Node ) ) ; temp -> isEndOfCol = 0 ; temp -> child [ 0 ] = temp -> child [ 1 ] = NULL ; return temp ; } bool insert ( Node * * root , int ( * M ) [ COL ] , int row , int col ) { if ( * root == NULL ) * root = newNode ( ) ; if ( col < COL ) return insert ( & ( ( * root ) -> child [ M [ row ] [ col ] ] ) , M , row , col + 1 ) ; else { if ( ! ( ( * root ) -> isEndOfCol ) ) return ( * root ) -> isEndOfCol = 1 ; return 0 ; } } void printRow ( int ( * M ) [ COL ] , int row ) { int i ; for ( i = 0 ; i < COL ; ++ i ) printf ( \\\" % d ▁ \\\" , M [ row ] [ i ] ) ; printf ( \\\" \\n \\\" ) ; } void findUniqueRows ( int ( * M ) [ COL ] ) { Node * root = NULL ; int i ; for ( i = 0 ; i < ROW ; ++ i ) if ( insert ( & root , M , i , 0 ) ) printRow ( M , i ) ; } int main ( ) { int M [ ROW ] [ COL ] = { { 0 , 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 1 , 0 } , { 0 , 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 0 , 0 } } ; findUniqueRows ( M ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if given string is a substring of string formed by repeated concatenation of z to a | C # program for the above approach ; Function checks if a given string is valid or not and prints the output ; Boolean flag variable to mark if given string is valid ; Traverse the given string ; If adjacent character differ by 1 ; If character ' a ' is followed by 4 ; Else flip the flag and break from the loop ; Output according to flag variable ; Driver code ; Given string ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { public static void checkInfinite ( String s ) { bool flag = true ; int N = s . Length ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( s [ i ] == ( char ) ( ( int ) ( s [ i + 1 ] ) + 1 ) ) { continue ; } else if ( s [ i ] == ' a ' && s [ i + 1 ] == ' z ' ) { continue ; } else { flag = false ; break ; } } if ( ! flag ) Console . Write ( \\\" NO \\\" ) ; else Console . Write ( \\\" YES \\\" ) ; } public static void Main ( String [ ] args ) { String s = \\\" ecbaz \\\" ; checkInfinite ( s ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Largest gap in an array | function to solve the given problem ; Driver Code\\\"\\nSolution 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 ▁ gap ▁ is ▁ : ▁ \\\" , solve ( $ arr , $ size ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Add two numbers without using arithmetic operators |\\\"\\nSolution 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\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of unique triplets whose XOR is zero | C # program to count the number of unique triplets whose XOR is 0 ; function to count the number of unique triplets whose xor is 0 ; To store values that are present ; stores the count of unique triplets ; traverse for all i , j pairs such that j > i ; xor of a [ i ] and a [ j ] ; if xr of two numbers is present , then increase the count ; returns answer ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int countTriplets ( int [ ] a , int n ) { List < int > s = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) s . Add ( a [ i ] ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int xr = a [ i ] ^ a [ j ] ; if ( s . Exists ( item => item == xr ) && xr != a [ i ] && xr != a [ j ] ) count ++ ; } } return count \\/ 3 ; } static void Main ( ) { int [ ] a = new int [ ] { 1 , 3 , 5 , 10 , 14 , 15 } ; int n = a . Length ; Console . Write ( countTriplets ( a , n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximum absolute difference of value and index sums | C # program to calculate the maximum absolute difference of an array . ; Utility function to calculate the value of absolute difference for the pair ( i , j ) . ; Function to return maximum absolute difference in brute force . ; Variable for storing the maximum absolute distance throughout the traversal of loops . ; Iterate through all pairs . ; If the absolute difference of current pair ( i , j ) is greater than the maximum difference calculated till now , update the value of result . ; Driver program\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; public class MaximumAbsoluteDifference { private static int calculateDiff ( int i , int j , int [ ] array ) { return Math . Abs ( array [ i ] - array [ j ] ) + Math . Abs ( i - j ) ; } private static int maxDistance ( int [ ] array ) { int result = 0 ; for ( int i = 0 ; i < array . Length ; i ++ ) { for ( int j = i ; j < array . Length ; j ++ ) { result = Math . Max ( result , calculateDiff ( i , j , array ) ) ; } } return result ; } public static void Main ( ) { int [ ] array = { - 70 , - 64 , - 6 , - 56 , 64 , 61 , - 57 , 16 , 48 , - 98 } ; Console . WriteLine ( maxDistance ( array ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Generate all numbers up to N in Lexicographical Order | Python program for the above approach ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def lexNumbers ( n ) :\\n\\tsol = [ ]\\n\\tdfs ( 1 , n , sol )\\n\\tprint ( \\\" [ \\\" , sol [ 0 ] , end = \\\" \\\" , sep = \\\" \\\" )\\n\\tfor i in range ( 1 , n ) :\\n\\t\\tprint ( \\\" , ▁ \\\" , sol [ i ] , end = \\\" \\\" , sep = \\\" \\\" ) print ( \\\" ] \\\" )\\ndef dfs ( temp , n , sol ) :\\n\\tif ( temp > n ) :\\n\\t\\treturn\\n\\tsol . append ( temp )\\n\\tdfs ( temp * 10 , n , sol )\\n\\tif ( temp % 10 != 9 ) :\\n\\t\\tdfs ( temp + 1 , n , sol )\\nn = 15\\nlexNumbers ( n )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimum value to be assigned to the elements so that sum becomes greater than initial sum | Function to return the minimum required value ; Find the sum of the array elements ; Return the required value ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def findMinValue ( arr , n ) :\\n\\tsum = 0\\n\\tfor i in range ( n ) :\\n\\t\\tsum += arr [ i ]\\n\\treturn ( sum \\/\\/ n ) + 1\\narr = [ 4 , 2 , 1 , 10 , 6 ]\\nn = len ( arr )\\nprint ( findMinValue ( arr , n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count of integers from the range [ 0 , N ] whose digit sum is a multiple of K | C ++ implementation of the approach ; To store the states of the dp ; Function to return the count of numbers from the range [ 0 , n ] whose digit sum is a multiple of k using bottom - up dp ; The digit in this index can only be from [ 0 , num [ idx ] ] ; The digit in this index can be anything from [ 0 , 9 ] ; new_tight is the flag value for the next position ; res can 't be negative ; Function to process the string to a vector of digits from MSD to LSD ; Driver code ; For large input number n ; Total number of digits in n ; Clean dp table ; Process the string to a vector of digits from MSD to LSD\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; #define MAX 100005\\n#define MOD 1000000007\\nint dp [ MAX ] [ 101 ] [ 2 ] ; int countNum ( int idx , int sum , int tight , vector < int > num , int len , int k ) { if ( len == idx ) { if ( sum == 0 ) return 1 ; else return 0 ; } if ( dp [ idx ] [ sum ] [ tight ] != -1 ) return dp [ idx ] [ sum ] [ tight ] ; int res = 0 , limit ; if ( tight == 0 ) { limit = num [ idx ] ; } else { limit = 9 ; } for ( int i = 0 ; i <= limit ; i ++ ) { int new_tight = tight ; if ( tight == 0 && i < limit ) new_tight = 1 ; res += countNum ( idx + 1 , ( sum + i ) % k , new_tight , num , len , k ) ; res %= MOD ; } if ( res < 0 ) res += MOD ; return dp [ idx ] [ sum ] [ tight ] = res ; } vector < int > process ( string s ) { vector < int > num ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { num . push_back ( s [ i ] - '0' ) ; } return num ; } int main ( ) { string n = \\\"98765432109876543210\\\" ; int len = n . length ( ) ; int k = 58 ; memset ( dp , -1 , sizeof ( dp ) ) ; vector < int > num = process ( n ) ; cout << countNum ( 0 , 0 , 0 , num , len , k ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"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 C++?\",\"targets\":\"#include \\nusing namespace std ; class gfg { public : float squareRoot ( float n ) { float x = n ; float y = 1 ; float e = 0.000001 ; while ( x - y > e ) { x = ( x + y ) \\/ 2 ; y = n \\/ x ; } return x ; } } ; int main ( ) { gfg g ; int n = 50 ; cout << \\\" Square ▁ root ▁ of ▁ \\\" << n << \\\" ▁ is ▁ \\\" << g . squareRoot ( n ) ; getchar ( ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Bitwise OR of Bitwise AND of all subarrays of an array | Function to find the Bitwise OR of Bitwise AND of all consecutive subsets of the array ; Stores the required result ; Traverse the given array ; Print the result ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function findbitwiseOR ( a , n ) { var res = 0 ; var i ; for ( i = 0 ; i < n ; i ++ ) res = res | a [ i ] ; document . write ( res ) ; } var A = [ 1 , 2 , 3 ] ; var N = A . length ; findbitwiseOR ( A , N ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Encrypt string with product of number of vowels and consonants in substring of size k | C # Program to Encrypt String with product of number of vowels and consonants in subString of size k ; isVowel ( ) is a function that returns true for a vowel and false otherwise . ; function to Encrypt the String ; cv to count vowel cc to count consonants ; Counting prefix count of vowel and prefix count of consonants ; generating the encrypted String . ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static bool isVowel ( char c ) { return ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } static String encryptString ( char [ ] s , int n , int k ) { int [ ] cv = new int [ n ] ; int [ ] cc = new int [ n ] ; if ( isVowel ( s [ 0 ] ) ) cv [ 0 ] = 1 ; else cc [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { cv [ i ] = cv [ i - 1 ] + ( isVowel ( s [ i ] ) == true ? 1 : 0 ) ; cc [ i ] = cc [ i - 1 ] + ( isVowel ( s [ i ] ) == true ? 0 : 1 ) ; } String ans = \\\" \\\" ; int prod = 0 ; prod = cc [ k - 1 ] * cv [ k - 1 ] ; ans += String . Join ( \\\" \\\" , prod ) ; for ( int i = k ; i < s . Length ; i ++ ) { prod = ( cc [ i ] - cc [ i - k ] ) * ( cv [ i ] - cv [ i - k ] ) ; ans += String . Join ( \\\" \\\" , prod ) ; } return ans ; } public static void Main ( String [ ] args ) { String s = \\\" hello \\\" ; int n = s . Length ; int k = 2 ; Console . Write ( encryptString ( s . ToCharArray ( ) , n , k ) + \\\" \\n \\\" ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sum of squares of binomial coefficients | C # Program to find the sum of square of binomial coefficient . ; Return the sum of square of binomial coefficient ; Calculate value of Binomial Coefficient in bottom up manner ; Base Cases ; Calculate value using previously stored values ; Finding the sum of square of binomial coefficient . ; Driver function\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int sumofsquare ( int n ) { int [ , ] C = new int [ n + 1 , n + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . Min ( i , n ) ; j ++ ) { if ( j == 0 j == i ) C [ i , j ] = 1 ; else C [ i , j ] = C [ i - 1 , j - 1 ] + C [ i - 1 , j ] ; } } int sum = 0 ; for ( i = 0 ; i <= n ; i ++ ) sum += ( C [ n , i ] * C [ n , i ] ) ; return sum ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( sumofsquare ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Dynamic Programming | High | 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 Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function maxTasks ( $ high , $ low , $ n ) { if ( $ n <= 0 ) return 0 ; return max ( $ high [ $ n - 1 ] + maxTasks ( $ high , $ low , ( $ n - 2 ) ) , $ low [ $ n - 1 ] + maxTasks ( $ high , $ low , ( $ n - 1 ) ) ) ; } $ n = 5 ; $ high = array ( 3 , 6 , 8 , 7 , 6 ) ; $ low = array ( 1 , 5 , 4 , 5 , 3 ) ; print ( maxTasks ( $ high , $ low , $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Reverse vowels in a given string | utility function to check for vowel ; Function to reverse order of vowels ; Storing the vowels separately ; Placing the vowels in the reverse order in the string ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function isVowel ( c ) { return ( c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' ) ; } function reverseVowel ( str1 ) { let j = 0 ; let str = str1 . split ( ' ' ) ; let vowel = \\\" \\\" ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( isVowel ( str [ i ] ) ) { j ++ ; vowel += str [ i ] ; } } for ( let i = 0 ; i < str . length ; i ++ ) { if ( isVowel ( str [ i ] ) ) { str [ i ] = vowel [ -- j ] ; } } return str . join ( \\\" \\\" ) ; } let str = \\\" \\\" ; document . write ( reverseVowel ( str ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum changes required to make a Catalan Sequence | PHP implementation of the approach ; To store first N Catalan numbers ; Function to find first n Catalan numbers ; Initialize first two values in table ; Filong entries in catalan [ ] using recursive formula ; Function to return the minimum changes required ; Find first n Catalan Numbers ; a and b are first two Catalan Sequence numbers ; Insert first n catalan elements to set ; If catalan element is present in the array then remove it from set ; Return the remaining number of elements in the set ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php $ MAX = 1000 ; $ catalan = array_fill ( 0 , $ MAX , 0 ) ; function catalanDP ( $ n ) { global $ catalan ; $ catalan [ 0 ] = $ catalan [ 1 ] = 1 ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) { $ catalan [ $ i ] = 0 ; for ( $ j = 0 ; $ j < $ i ; $ j ++ ) { $ catalan [ $ i ] += $ catalan [ $ j ] * $ catalan [ $ i - $ j - 1 ] ; } } } function CatalanSequence ( $ arr , $ n ) { global $ catalan ; catalanDP ( $ n ) ; $ s = array ( ) ; $ a = $ b = 1 ; array_push ( $ s , $ a ) ; if ( $ n >= 2 ) { array_push ( $ s , $ b ) ; } for ( $ i = 2 ; $ i < $ n ; $ i ++ ) { array_push ( $ s , $ catalan [ $ i ] ) ; } $ s = array_unique ( $ s ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( in_array ( $ arr [ $ i ] , $ s ) ) { unset ( $ s [ array_search ( $ arr [ $ i ] , $ s ) ] ) ; } } return count ( $ s ) ; } $ arr = array ( 1 , 1 , 2 , 5 , 41 ) ; $ n = count ( $ arr ) ; print ( CatalanSequence ( $ arr , $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count of right shifts for each array element to be in its sorted position | Function to find the right shifts required for each element to reach its sorted array position in A [ ] ; Stores required number of shifts for each element ; If the element is at sorted position ; Otherwise ; Calculate right shift ; Print the respective shifts ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def findShifts ( A , N ) :\\n\\tshift = [ 0 for i in range ( N ) ]\\n\\tfor i in range ( N ) :\\n\\t\\tif ( i == A [ i ] - 1 ) :\\n\\t\\t\\tshift [ i ] = 0\\n\\t\\telse :\\n\\t\\t\\tshift [ i ] = ( A [ i ] - 1 - i + N ) % N\\n\\tfor i in range ( N ) :\\n\\t\\tprint ( shift [ i ] , end = \\\" ▁ \\\" )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 1 , 4 , 3 , 2 , 5 ]\\n\\tN = len ( arr )\\n\\tfindShifts ( arr , N )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Turn off the rightmost set bit | Set 2 | Unsets the rightmost set bit of n and returns the result ; Checking whether bit position is set or not ; If bit position is found set , we flip this bit by xoring given number and number with bit position set ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def FlipBits ( n ) :\\n\\tfor bit in range ( 32 ) :\\n\\t\\tif ( ( n >> bit ) & 1 ) :\\n\\t\\t\\tn = n ^ ( 1 << bit )\\n\\t\\t\\tbreak\\n\\tprint ( \\\" The ▁ number ▁ after ▁ unsetting ▁ the \\\" , end = \\\" ▁ \\\" )\\n\\tprint ( \\\" rightmost ▁ set ▁ bit \\\" , n )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 12 ;\\n\\tFlipBits ( N )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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 Java:\",\"targets\":\"public class GFG { static int countSetBits ( int N ) { int count = 0 ; for ( int i = 0 ; i < 4 * 8 ; i ++ ) { if ( ( N & ( 1 << i ) ) != 0 ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int N = 15 ; System . out . println ( countSetBits ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Pascal 's Triangle | binomialCoeff ; Function to print first n lines of Pascal 's Triangle ; Iterate through every line and print entries in it ; Every line has number of integers equal to line number ; Driver Code\\\"\\nSolution 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 ; } function printPascal ( $ n ) { for ( $ line = 0 ; $ line < $ n ; $ line ++ ) { for ( $ i = 0 ; $ i <= $ line ; $ i ++ ) echo \\\" \\\" . binomialCoeff ( $ line , $ i ) . \\\" ▁ \\\" ; echo \\\" \\n \\\" ; } } $ n = 7 ; printPascal ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"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\":\"\\\"Case | C # implementation of the approach ; Function to return the sorted string ; Vectors to store the lowercase and uppercase characters ; Sort both the vectors ; If current character is lowercase then pick the lowercase character from the sorted list ; Else pick the uppercase character ; Return the sorted string ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { public static String getSortedString ( char [ ] s , int n ) { List < char > v1 = new List < char > ( ) ; List < char > v2 = new List < char > ( ) ; int i = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( s [ i ] > ' a ' && s [ i ] <= ' z ' ) v1 . Add ( s [ i ] ) ; if ( s [ i ] > ' A ' && s [ i ] <= ' z ' ) v2 . Add ( s [ i ] ) ; } v1 . Sort ( ) ; v2 . Sort ( ) ; int j = 0 ; i = 0 ; for ( int k = 0 ; k < n ; k ++ ) { if ( s [ k ] > ' a ' && s [ k ] <= ' z ' ) { s [ k ] = v1 [ i ] ; ++ i ; } else if ( s [ k ] > ' A ' && s [ k ] <= ' Z ' ) { s [ k ] = v2 [ j ] ; ++ j ; } } return String . Join ( \\\" \\\" , s ) ; } public static void Main ( String [ ] args ) { String s = \\\" gEeksfOrgEEkS \\\" ; int n = s . Length ; Console . WriteLine ( getSortedString ( s . ToCharArray ( ) , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Curzon Numbers | Function to check if a number is a Curzon number or not ; Find 2 ^ N + 1 ; Find 2 * N + 1 ; Check for divisibility ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function checkIfCurzonNumber ( N ) { var powerTerm , productTerm ; powerTerm = Math . pow ( 2 , N ) + 1 ; productTerm = 2 * N + 1 ; if ( powerTerm % productTerm == 0 ) { document . write ( \\\" \\\" + \\\" \\\" ) ; } else { document . write ( \\\" \\\" ) ; } } var N = 5 ; checkIfCurzonNumber ( N ) ; N = 10 ; checkIfCurzonNumber ( N ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximize difference between sum of even and odd | Function to find the maximum possible difference between sum of even and odd indices ; Convert arr [ ] o 1 - based indexing ; Reverse the array ; Convert arr [ ] o 1 based index ; Reverse the array ; Stores maximum difference between sum of even and odd indexed elements ; Traverse the array ; If arr [ i ] is local maxima ; Update maxDiff ; If arr [ i ] is local minima ; Update maxDiff ; Driver Code ; Size of array ; Function Call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def maxPossibleDiff ( arr , N ) :\\n\\tarr . append ( - 1 )\\n\\tarr = arr [ : : - 1 ]\\n\\tarr . append ( - 1 )\\n\\tarr = arr [ : : - 1 ]\\n\\tmaxDiff = 0\\n\\tfor i in range ( 1 , N + 1 ) :\\n\\t\\tif ( arr [ i ] > arr [ i - 1 ] and arr [ i ] > arr [ i + 1 ] ) :\\n\\t\\t\\tmaxDiff += arr [ i ]\\n\\t\\tif ( arr [ i ] < arr [ i - 1 ] and arr [ i ] < arr [ i + 1 ] ) :\\n\\t\\t\\tmaxDiff -= arr [ i ]\\n\\tprint ( maxDiff )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 3 , 2 , 1 , 4 , 5 , 2 , 1 , 7 , 8 , 9 ]\\n\\tN = len ( arr )\\n\\tmaxPossibleDiff ( arr , N )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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 ( \\\" ▁ % d ▁ \\\" , cand ) ; else printf ( \\\" No ▁ Majority ▁ 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\":\"\\\"Product of all the pairs from the given array | Java implementation to Find the product of all the pairs from the given array ; Function to calculate ( x ^ y ) % 1000000007 ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; Return the final result ; Function to return the product of the elements of all possible pairs from the array ; To store the required product ; Iterate for every element of the array ; Each element appears ( 2 * n ) times ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static final int mod = 1000000007 ; static int power ( int x , int y ) { int p = 1000000007 ; int res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static int productPairs ( int arr [ ] , int n ) { int product = 1 ; for ( int i = 0 ; i < n ; i ++ ) { product = ( product % mod * ( int ) power ( arr [ i ] , ( 2 * n ) ) % mod ) % mod ; } return product % mod ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 } ; int n = arr . length ; System . out . print ( productPairs ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check whether a number can be represented by sum of two squares | C # program to Check whether a number can be represented by sum of two squares using Fermat Theorem . ; Count all the prime factors . ; If any prime factor of the form ( 4 k + 3 ) ( 4 k + 3 ) occurs an odd number of times . ; If n itself is a prime number and can be expressed in the form of 4 k + 3 we return false . ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { public static bool judgeSquareSum ( int n ) { for ( int i = 2 ; i * i <= n ; i ++ ) { int count = 0 ; if ( n % i == 0 ) { while ( n % i == 0 ) { count ++ ; n \\/= i ; } if ( i % 4 == 3 && count % 2 != 0 ) return false ; } } return n % 4 != 3 ; } static public void Main ( ) { int n = 17 ; if ( judgeSquareSum ( n ) ) Console . WriteLine ( \\\" Yes \\\" ) ; else Console . WriteLine ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Split squares of first N natural numbers into two sets with minimum absolute difference of their sums | Function to partition squares of N natural number in two subset ; Store the count of blocks of size 8 ; Partition of block of 8 element ; Store the minimum subset difference ; Partition of N elements to minimize their subset sum difference ; Store elements of subset A and B ; If element is of type A ; If the element is of type B ; Print the minimum subset difference ; Print the first subset ; Print the second subset ; Driver Code ; Function call\\\"\\nSolution in Python:\",\"targets\":\"def minimumSubsetDifference ( N ) :\\n\\tblockOfSize8 = N \\/\\/ 8\\n\\tstr = \\\" ABBABAAB \\\"\\n\\tsubsetDifference = 0\\n\\tpartition = \\\" \\\"\\n\\twhile blockOfSize8 != 0 :\\n\\t\\tpartition = partition + str\\n\\t\\tblockOfSize8 = blockOfSize8 - 1\\n\\tA = [ ]\\n\\tB = [ ]\\n\\tfor i in range ( N ) :\\n\\t\\tif partition [ i ] == ' A ' :\\n\\t\\t\\tA . append ( ( i + 1 ) * ( i + 1 ) )\\n\\t\\telse :\\n\\t\\t\\tB . append ( ( i + 1 ) * ( i + 1 ) )\\n\\tprint ( subsetDifference )\\n\\tfor i in A :\\n\\t\\tprint ( i , end = \\\" ▁ \\\" )\\n\\tprint ( )\\n\\tfor i in B :\\n\\t\\tprint ( i , end = \\\" ▁ \\\" )\\nN = 8\\nminimumSubsetDifference ( N )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find Prime number just less than and just greater each element of given Array | C ++ program for the above approach ; Utility function to check for primality of a number X by checking whether X haACCs any factors other than 1 and itself . ; if ( X % i == 0 ) Factor found ; Function to print primes just less than and just greater than of each element in an array ; Traverse the array ; Traverse for finding prime just less than A [ i ] ; Prime just less than A [ i ] found ; Traverse for finding prime just greater than A [ i ] ; Prime just greater than A [ i ] found ; Driver code ; Input ; Function call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool isPrime ( int X ) { for ( int i = 2 ; i * i <= X ; i ++ ) return false ; return true ; } void printPrimes ( int A [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = A [ i ] - 1 ; ; j -- ) { if ( isPrime ( j ) ) { cout << j << \\\" ▁ \\\" ; break ; } } for ( int j = A [ i ] + 1 ; ; j ++ ) { if ( isPrime ( j ) ) { cout << j << \\\" ▁ \\\" ; break ; } } cout << endl ; } } int main ( ) { int A [ ] = { 17 , 28 } ; int N = sizeof ( A ) \\/ sizeof ( A [ 0 ] ) ; printPrimes ( A , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Modify string by removing vowels in between two consonants | Java program to remove all Vowels in between two consonants from the string ; Function to check if the character x is a vowel or not ; Returns the updated string formed after removing all the Sandwiched Vowels from the given string ; string to store the Updated String after removing the Sandwiched Vowels ; traverse the string from left to right ; if the current character is the first or the last character of the string then , this needs to be appended to the updatedString , since the corner alphabet irrespective of it being a vowel or a consonant , is never ' Sandwiched ' ; Check if the current character of the string is a vowel and both the previous and the next characters are consonants , if so then this is a sandwiched vowel , thus is ignored and not appended to the updated string ; if this character is not a sandwiched Vowel append it to the updated String ; Driver Code ; Remove all the Sandwitched Vowels\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; import java . util . * ; import java . lang . * ; class GFG { static boolean isVowel ( char x ) { if ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) return true ; else return false ; } static String updateSandwichedVowels ( String a ) { int n = a . length ( ) ; String updatedString = \\\" \\\" ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == 0 i == n - 1 ) { updatedString += a . charAt ( i ) ; continue ; } if ( isVowel ( a . charAt ( i ) ) == true && isVowel ( a . charAt ( i - 1 ) ) == false && isVowel ( a . charAt ( i + 1 ) ) == false ) { continue ; } updatedString += a . charAt ( i ) ; } return updatedString ; } public static void main ( String [ ] args ) { String str = \\\" geeksforgeeks \\\" ; String updatedString = updateSandwichedVowels ( str ) ; System . out . print ( updatedString ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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\\\"\\nSolution in Python:\",\"targets\":\"def majorityElement ( arr , n ) :\\n\\tarr . sort ( )\\n\\tcount , max_ele , temp , f = 1 , - 1 , arr [ 0 ] , 0\\n\\tfor i in range ( 1 , n ) :\\n\\t\\tif ( temp == arr [ i ] ) :\\n\\t\\t\\tcount += 1\\n\\t\\telse :\\n\\t\\t\\tcount = 1\\n\\t\\t\\ttemp = arr [ i ]\\n\\t\\tif ( max_ele < count ) :\\n\\t\\t\\tmax_ele = count\\n\\t\\t\\tele = arr [ i ]\\n\\t\\t\\tif ( max_ele > ( n \\/\\/ 2 ) ) :\\n\\t\\t\\t\\tf = 1\\n\\t\\t\\t\\tbreak\\n\\tif f == 1 :\\n\\t\\treturn ele\\n\\telse :\\n\\t\\treturn - 1\\narr = [ 1 , 1 , 2 , 1 , 3 , 5 , 1 ]\\nn = len ( arr )\\nprint ( majorityElement ( arr , n ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all differences between Maximum and Minimum of increasing Subarrays | Function to calculate and return the sum of differences of maximum and minimum of strictly increasing subarrays ; Stores the sum ; Traverse the array ; If last element of the increasing sub - array is found ; Update sum ; If the last element of the array is reached ; Update sum ; Return the sum ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def sum_of_differences ( arr , N ) :\\n\\tsum = 0\\n\\ti = 0\\n\\twhile ( i < N - 1 ) :\\n\\t\\tif arr [ i ] < arr [ i + 1 ] :\\n\\t\\t\\tflag = 0\\n\\t\\t\\tfor j in range ( i + 1 , N - 1 ) :\\n\\t\\t\\t\\tif arr [ j ] >= arr [ j + 1 ] :\\n\\t\\t\\t\\t\\tsum += ( arr [ j ] - arr [ i ] )\\n\\t\\t\\t\\t\\ti = j\\n\\t\\t\\t\\t\\tflag = 1\\n\\t\\t\\t\\t\\tbreak\\n\\t\\t\\tif flag == 0 and arr [ i ] < arr [ N - 1 ] :\\n\\t\\t\\t\\tsum += ( arr [ N - 1 ] - arr [ i ] )\\n\\t\\t\\t\\tbreak\\n\\t\\ti += 1\\n\\treturn sum\\narr = [ 6 , 1 , 2 , 5 , 3 , 4 ]\\nN = len ( arr )\\nprint ( sum_of_differences ( arr , N ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"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\\\"\\nSolution 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 << \\\" ▁ \\\" ; if ( index != 0 && index != N - 1 ) cout << Diagonal ++ ; else cout << \\\" ▁ \\\" ; for ( side_index = 0 ; side_index < 2 * ( N - index - 1 ) ; side_index ++ ) cout << \\\" ▁ \\\" ; cout << Right ++ ; cout << endl ; } } int main ( int argc , char * * argv ) { int Size = 6 ; Alphabet_N_Pattern ( Size ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimize coins required to obtain all possible values up to N | Function to find minimum count of { 1 , 2 , 5 } valued coins required to make a change of all values in the range [ 1 , N ] ; Number of 5 valueds coins required ; Number of 1 valued coins required ; Number of 2 valued coins required ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def find ( N ) :\\n\\tF = int ( ( N - 4 ) \\/ 5 )\\n\\tif ( ( N - 5 * F ) % 2 ) == 0 :\\n\\t\\tO = 2\\n\\telse :\\n\\t\\tO = 1\\n\\tT = ( N - 5 * F - O ) \\/\\/ 2\\n\\tprint ( \\\" Count ▁ of ▁ 5 ▁ valueds ▁ coins : ▁ \\\" , F )\\n\\tprint ( \\\" Count ▁ of ▁ 2 ▁ valueds ▁ coins : ▁ \\\" , T )\\n\\tprint ( \\\" Count ▁ of ▁ 1 ▁ valueds ▁ coins : ▁ \\\" , O )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 8\\n\\tfind ( N )\",\"language\":\"python\",\"split\":\"validation\",\"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 | Java 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 program\\\"\\nSolution in Java:\",\"targets\":\"import java . util . Arrays ; import java . util . Collections ; import java . util . Comparator ; import java . util . Vector ; class GFG { static int minSum ( int arr [ ] , int n ) { Vector < Integer > evenArr = new Vector < > ( ) ; Vector < Integer > oddArr = new Vector < > ( ) ; Arrays . sort ( arr ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i < n \\/ 2 ) { oddArr . add ( arr [ i ] ) ; } else { evenArr . add ( arr [ i ] ) ; } } Comparator comparator = Collections . reverseOrder ( ) ; Collections . sort ( evenArr , comparator ) ; int i = 0 , sum = 0 ; for ( int j = 0 ; j < evenArr . size ( ) ; j ++ ) { arr [ i ++ ] = evenArr . get ( j ) ; arr [ i ++ ] = oddArr . get ( j ) ; sum += evenArr . get ( j ) * oddArr . get ( j ) ; } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 } ; int n = arr . length ; System . out . println ( \\\" Minimum ▁ required ▁ sum ▁ = ▁ \\\" + minSum ( arr , n ) ) ; System . out . println ( \\\" Sorted ▁ array ▁ in ▁ required ▁ format ▁ : ▁ \\\" ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + \\\" ▁ \\\" ) ; } } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 ; Print the answer\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; long double find ( int N , int sum ) { if ( sum > 6 * N sum < N ) return 0 ; if ( N == 1 ) { if ( sum >= 1 && sum <= 6 ) return 1.0 \\/ 6 ; else return 0 ; } long double s = 0 ; for ( int i = 1 ; i <= 6 ; i ++ ) s = s + find ( N - 1 , sum - i ) \\/ 6 ; return s ; } int main ( ) { int N = 4 , a = 13 , b = 17 ; long double probability = 0.0 ; for ( int sum = a ; sum <= b ; sum ++ ) probability = probability + find ( N , sum ) ; cout << fixed << setprecision ( 6 ) << probability ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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 the 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 ; Print the answer\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static double find ( int N , int sum ) { if ( sum > 6 * N sum < N ) return 0 ; if ( N == 1 ) { if ( sum >= 1 && sum <= 6 ) return 1.0 \\/ 6 ; else return 0 ; } double s = 0 ; for ( int i = 1 ; i <= 6 ; i ++ ) s = s + find ( N - 1 , sum - i ) \\/ 6 ; return s ; } static void Main ( ) { int N = 4 , a = 13 , b = 17 ; double probability = 0.0 ; for ( int sum = a ; sum <= b ; sum ++ ) probability = probability + find ( N , sum ) ; Console . WriteLine ( Math . Round ( probability , 6 ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximum number of operations required such that no pairs from a Matrix overlap | C # program to implement the above approach ; Function to find maximum count of operations ; Initialize count by 0 ; Iterate over remaining pairs ; Check if first operation is applicable ; Check if 2 nd operation is applicable ; Otherwise ; Return the count of operations ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int find_max ( List < pair > v , int n ) { int count = 0 ; if ( n >= 2 ) count = 2 ; else count = 1 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( v [ i - 1 ] . first < ( v [ i ] . first - v [ i ] . second ) ) count ++ ; else if ( v [ i + 1 ] . first > ( v [ i ] . first + v [ i ] . second ) ) { count ++ ; v [ i ] . first = v [ i ] . first + v [ i ] . second ; } else continue ; } return count ; } public static void Main ( String [ ] args ) { int n = 3 ; List < pair > v = new List < pair > ( ) ; v . Add ( new pair ( 10 , 20 ) ) ; v . Add ( new pair ( 15 , 10 ) ) ; v . Add ( new pair ( 20 , 16 ) ) ; Console . Write ( find_max ( v , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Smallest element greater than X not present in the array | C # implementation of the approach ; 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 C-Sharp?\",\"targets\":\"using System ; class GFG { static int Next_greater ( int [ ] a , int n , int x ) { Array . Sort ( a ) ; int low = 0 , high = n - 1 , ans = x + 1 ; while ( low <= high ) { int 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 ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 5 , 10 , 4 , 7 } ; int x = 4 ; int n = a . Length ; Console . WriteLine ( Next_greater ( a , n , x ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Perimeter of the Union of Two Rectangles | C # program for the above approach ; Function to check if two rectangles are intersecting or not ; If one rectangle is to the right of other 's right edge ; If one rectangle is on the top of other 's top edge ; Function to return the perimeter of the Union of Two Rectangles ; Stores the resultant perimeter ; If rectangles do not interesect ; Perimeter of Rectangle 1 ; Perimeter of Rectangle 2 ; If the rectangles intersect ; Get width of combined figure ; Get length of combined figure ; Return the perimeter ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Linq ; public class GFG { static bool doIntersect ( int [ ] X , int [ ] Y ) { if ( X [ 0 ] > X [ 3 ] X [ 2 ] > X [ 1 ] ) return false ; if ( Y [ 0 ] > Y [ 3 ] Y [ 2 ] > Y [ 1 ] ) return false ; return true ; } static int getUnionPerimeter ( int [ ] X , int [ ] Y ) { int perimeter = 0 ; if ( ! doIntersect ( X , Y ) ) { perimeter += 2 * ( Math . Abs ( X [ 1 ] - X [ 0 ] ) + Math . Abs ( Y [ 1 ] - Y [ 0 ] ) ) ; perimeter += 2 * ( Math . Abs ( X [ 3 ] - X [ 2 ] ) + Math . Abs ( Y [ 3 ] - Y [ 2 ] ) ) ; } else { int w = X . Max ( ) - X . Min ( ) ; int l = X . Max ( ) - Y . Min ( ) ; perimeter = 2 * ( l + w ) ; } return perimeter ; } public static void Main ( String [ ] args ) { int [ ] X = { - 1 , 2 , 4 , 6 } ; int [ ] Y = { 2 , 5 , 3 , 7 } ; Console . Write ( getUnionPerimeter ( X , Y ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Print all distinct even and odd prefix Bitwise XORs of first N natural numbers | Java approach for the above approach ; 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 Java?\",\"targets\":\"class GFG { static void evenOddBitwiseXOR ( int N ) { System . out . print ( \\\" Even : ▁ \\\" + 0 + \\\" ▁ \\\" ) ; for ( int i = 4 ; i <= N ; i = i + 4 ) { System . out . print ( i + \\\" ▁ \\\" ) ; } System . out . print ( \\\"\\n\\\"); System . out . print ( \\\" Odd : ▁ \\\" + 1 + \\\" ▁ \\\" ) ; for ( int i = 4 ; i <= N ; i = i + 4 ) { System . out . print ( i - 1 + \\\" ▁ \\\" ) ; } if ( N % 4 == 2 ) System . out . print ( N + 1 ) ; else if ( N % 4 == 3 ) System . out . print ( N ) ; } public static void main ( String [ ] args ) { int N = 6 ; evenOddBitwiseXOR ( N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"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\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def has0 ( x ) :\\n\\twhile ( x != 0 ) :\\n\\t\\tif ( x % 10 == 0 ) :\\n\\t\\t\\treturn 1\\n\\t\\tx = x \\/\\/ 10\\n\\treturn 0\\ndef getCount ( n ) :\\n\\tcount = 0\\n\\tfor i in range ( 1 , n + 1 ) :\\n\\t\\tcount = count + has0 ( i )\\n\\treturn count\\nn = 107\\nprint ( \\\" Count ▁ of ▁ numbers ▁ from ▁ 1\\\" , \\\" ▁ to ▁ \\\" , n , \\\" ▁ is ▁ \\\" , getCount ( n ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if given array is almost sorted ( elements are at | function for checking almost sort ; One by one compare adjacents . ; Check whether resultant is sorted or not ; is resultant is sorted return true ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function almostSort ( A , n ) { for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( A [ i ] > A [ i + 1 ] ) { let temp = A [ i ] ; A [ i ] = A [ i + 1 ] ; A [ i + 1 ] = temp ; i ++ ; } } for ( let i = 0 ; i < n - 1 ; i ++ ) if ( A [ i ] > A [ i + 1 ] ) return false ; return true ; } let A = [ 1 , 3 , 2 , 4 , 6 , 5 ] ; let n = A . length ; if ( almostSort ( A , n ) ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Rearrange array by interchanging positions of even and odd elements in the given array | Function to replace each even element by odd and vice - versa in a given array ; Stores length of array ; Traverse array ; If current element is even then swap it with odd ; Perform Swap ; Change the sign ; If current element is odd then swap it with even ; Perform Swap ; Change the sign ; Marked element positive ; Prlet final array ; Given array arr [ ] ; Function Call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function replace ( arr ) { let n = arr . length ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] >= 0 && arr [ j ] >= 0 && arr [ i ] % 2 == 0 && arr [ j ] % 2 != 0 ) { let tmp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = tmp ; arr [ j ] = - arr [ j ] ; break ; } else if ( arr [ i ] >= 0 && arr [ j ] >= 0 && arr [ i ] % 2 != 0 && arr [ j ] % 2 == 0 ) { let tmp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = tmp ; arr [ j ] = - arr [ j ] ; break ; } } } for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = Math . abs ( arr [ i ] ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + \\\" \\\" ) ; } let arr = [ 1 , 3 , 2 , 4 ] ; replace ( arr ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Merge K sorted Doubly Linked List in Sorted Order | Java program to merge K sorted doubly linked list in sorted order ; A linked list node ; Given a reference ( pointer to pointer ) to the head Of a DLL and an int , appends a new node at the end ; Allocate node ; Put in the data ; This new node is going to be the last node , so make next of it as null ; If the Linked List is empty , then make the new node as head ; Else traverse till the last node ; Change the next of last node ; Make last node as previous of new node ; Function to print the list ; Run while loop unless node becomes null ; Function to merge two sorted doubly linked lists ; If any of the list is empty ; Comparison the data of two linked list ; Store head pointer before merge the list ; Changing of pointer between Two list for merging ; Changing of pointer between Two list for merging ; Condition to check if any anyone list not end ; Return head pointer of merged list ; Function to merge all sorted linked list in sorted order ; Function call to merge two sorted doubly linked list at a time ; Return final sorted doubly linked list ; Driver code ; Loop to initialize all the lists to empty ; Create first doubly linked List List1 . 1 <= > 5 <= > 9 ; Create second doubly linked List List2 . 2 <= > 3 <= > 7 <= > 12 ; Create third doubly linked List List3 . 8 <= > 11 <= > 13 <= > 18 ; Function call to merge all sorted doubly linked lists in sorted order ; Print final sorted list\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static class Node { int data ; Node next ; Node prev ; } ; static Node append ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; Node last = head_ref ; new_node . data = new_data ; new_node . next = null ; if ( head_ref == null ) { new_node . prev = null ; head_ref = new_node ; return head_ref ; } while ( last . next != null ) last = last . next ; last . next = new_node ; new_node . prev = last ; return head_ref ; } static void printList ( Node node ) { Node last ; while ( node != null ) { System . out . print ( node . data + \\\" ▁ \\\" ) ; last = node ; node = node . next ; } } static Node mergeList ( Node p , Node q ) { Node s = null ; if ( p == null q == null ) { return ( p == null ? q : p ) ; } if ( p . data < q . data ) { p . prev = s ; s = p ; p = p . next ; } else { q . prev = s ; s = q ; q = q . next ; } Node head = s ; while ( p != null && q != null ) { if ( p . data < q . data ) { s . next = p ; p . prev = s ; s = s . next ; p = p . next ; } else { s . next = q ; q . prev = s ; s = s . next ; q = q . next ; } } if ( p == null ) { s . next = q ; q . prev = s ; } if ( q == null ) { s . next = p ; p . prev = s ; } return head ; } static Node mergeAllList ( Node head [ ] , int k ) { Node finalList = null ; for ( int i = 0 ; i < k ; i ++ ) { finalList = mergeList ( finalList , head [ i ] ) ; } return finalList ; } public static void main ( String args [ ] ) { int k = 3 ; Node head [ ] = new Node [ k ] ; for ( int i = 0 ; i < k ; i ++ ) { head [ i ] = null ; } head [ 0 ] = append ( head [ 0 ] , 1 ) ; head [ 0 ] = append ( head [ 0 ] , 5 ) ; head [ 0 ] = append ( head [ 0 ] , 9 ) ; head [ 1 ] = append ( head [ 1 ] , 2 ) ; head [ 1 ] = append ( head [ 1 ] , 3 ) ; head [ 1 ] = append ( head [ 1 ] , 7 ) ; head [ 1 ] = append ( head [ 1 ] , 12 ) ; head [ 2 ] = append ( head [ 2 ] , 8 ) ; head [ 2 ] = append ( head [ 2 ] , 11 ) ; head [ 2 ] = append ( head [ 2 ] , 13 ) ; head [ 2 ] = append ( head [ 2 ] , 18 ) ; Node finalList = mergeAllList ( head , k ) ; printList ( finalList ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"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 ; Program to test function power\\\"\\nSolution in C:\",\"targets\":\"#include \\nint power ( int x , unsigned int y ) { if ( y == 0 ) return 1 ; else if ( y % 2 == 0 ) return power ( x , y \\/ 2 ) * power ( x , y \\/ 2 ) ; else return x * power ( x , y \\/ 2 ) * power ( x , y \\/ 2 ) ; } int main ( ) { int x = 2 ; unsigned int y = 3 ; printf ( \\\" % d \\\" , power ( x , y ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Calculate 7 n \\/ 8 without using division and multiplication operators | C program to evaluate ceil ( 7 n \\/ 8 ) without using * and \\/ ; Note the inner bracket here . This is needed because precedence of ' - ' operator is higher than ' < < ' ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint multiplyBySevenByEight ( unsigned int n ) { return ( n - ( n >> 3 ) ) ; } int main ( ) { unsigned int n = 9 ; printf ( \\\" % d \\\" , multiplyBySevenByEight ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find k ordered pairs in array with minimum difference d | Java implementation of the approach ; Function to find the required pairs ; There has to be atleast 2 * k elements ; To store the pairs ; Sort the given array ; For every possible pair ; If the current pair is valid ; Insert it into the pair vector ; If k pairs are not possible ; Print the pairs ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void findPairs ( int arr [ ] , int n , int k , int d ) { if ( n < 2 * k ) { System . out . print ( - 1 ) ; return ; } Vector < pair > pairs = new Vector < pair > ( ) ; Arrays . sort ( arr ) ; for ( int i = 0 ; i < k ; i ++ ) { if ( arr [ n - k + i ] - arr [ i ] >= d ) { pair p = new pair ( arr [ i ] , arr [ n - k + i ] ) ; pairs . add ( p ) ; } } if ( pairs . size ( ) < k ) { System . out . print ( - 1 ) ; return ; } for ( pair v : pairs ) { System . out . println ( \\\" ( \\\" + v . first + \\\" , ▁ \\\" + v . second + \\\" ) \\\" ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 6 , 10 , 23 , 14 , 7 , 2 , 20 , 9 } ; int n = arr . length ; int k = 4 , d = 3 ; findPairs ( arr , n , k , d ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Probability that a random pair chosen from an array ( a [ i ] , a [ j ] ) has the maximum sum | Java implementation of the approach ; Function to return the probability of getting the maximum pair sum when a random pair is chosen from the given array ; Initialize the maximum sum , its count and the count of total pairs ; For every single pair ; Get the sum of the current pair ; If the sum is equal to the current maximum sum so far ; Increment its count ; If the sum is greater than the current maximum ; Update the current maximum and re - initialize the count to 1 ; Find the required probability ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static float findProb ( int arr [ ] , int n ) { long maxSum = Integer . MIN_VALUE , maxCount = 0 , totalPairs = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int sum = arr [ i ] + arr [ j ] ; if ( sum == maxSum ) { maxCount ++ ; } else if ( sum > maxSum ) { maxSum = sum ; maxCount = 1 ; } totalPairs ++ ; } } float prob = ( float ) maxCount \\/ ( float ) totalPairs ; return prob ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 1 , 1 , 2 , 2 , 2 } ; int n = arr . length ; System . out . println ( findProb ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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\\\"\\nHow can the above be solved in JS?\",\"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\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximum number of pair reductions possible on a given triplet | C # 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\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void maxOps ( int a , int b , int c ) { int [ ] arr = { a , b , c } ; int count = 0 ; while ( 1 != 0 ) { Array . Sort ( arr ) ; if ( arr [ 0 ] == 0 && arr [ 1 ] == 0 ) break ; arr [ 1 ] -= 1 ; arr [ 2 ] -= 1 ; count += 1 ; } Console . WriteLine ( count ) ; } public static void Main ( String [ ] args ) { int a = 4 , b = 3 , c = 2 ; maxOps ( a , b , c ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find the day number in the current year for the given date | Java implementation of the approach ; Function to return the day number of the year for the given date ; Extract the year , month and the day from the date string ; If current year is a leap year and the date given is after the 28 th of February then it must include the 29 th February ; Add the days in the previous months ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int days [ ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ; static int dayOfYear ( String date ) { int year = Integer . parseInt ( date . substring ( 0 , 4 ) ) ; int month = Integer . parseInt ( date . substring ( 5 , 7 ) ) ; int day = Integer . parseInt ( date . substring ( 8 ) ) ; if ( month > 2 && year % 4 == 0 && ( year % 100 != 0 year % 400 == 0 ) ) { ++ day ; } while ( -- month > 0 ) { day = day + days [ month - 1 ] ; } return day ; } public static void main ( String [ ] args ) { String date = \\\"2019-01-09\\\" ; System . out . println ( dayOfYear ( date ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Lexicographically largest permutation possible by a swap that is smaller than a given array | C # program for the above approach ; Function to lexicographic largest permutation possible by a swap that is smaller than given array ; Find the index of first element such that arr [ i ] > arr [ i + 1 ] ; If the array is sorted in increasing order ; Find the index of first element which is smaller than arr [ i ] ; If arr [ j ] = = arr [ j - 1 ] ; Decrement j ; Swap the element ; Print the array arr [ ] ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void findPermutation ( int [ ] arr ) { int N = arr . Length ; int i = N - 2 ; while ( i >= 0 && arr [ i ] <= arr [ i + 1 ] ) i -- ; if ( i == - 1 ) { Console . Write ( \\\" - 1\\\" ) ; return ; } int j = N - 1 ; while ( j > i && arr [ j ] >= arr [ i ] ) j -- ; while ( j > i && arr [ j ] == arr [ j - 1 ] ) { j -- ; } int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; foreach ( int it in arr ) { Console . Write ( it + \\\" ▁ \\\" ) ; } } public static void Main ( ) { int [ ] arr = { 1 , 2 , 5 , 3 , 4 , 6 } ; findPermutation ( arr ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"k | C # 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 C-Sharp?\",\"targets\":\"using System ; using System . Collections ; class GFG { static int findK ( int n , int k ) { ArrayList a = new ArrayList ( n ) ; for ( int i = 1 ; i < n ; i ++ ) if ( i % 2 == 1 ) a . Add ( i ) ; for ( int i = 1 ; i < n ; i ++ ) if ( i % 2 == 0 ) a . Add ( i ) ; return ( int ) ( a [ k - 1 ] ) ; } static void Main ( ) { int n = 10 , k = 3 ; Console . WriteLine ( findK ( n , k ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Split a binary string into K subsets minimizing sum of products of occurrences of 0 and 1 | Java Program to split a given String into K segments such that the sum of product of occurence of characters in them is minimized ; Function to return the minimum sum of products of occurences of 0 and 1 in each segments ; Store the length of the String ; Not possible to generate subsets greater than the length of String ; If the number of subsets equals the length ; Precompute the sum of products for all index ; Calculate the minimum sum of products for K subsets ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static int minSumProd ( String S , int K ) { int len = S . length ( ) ; if ( K > len ) return - 1 ; if ( K == len ) return 0 ; int [ ] dp = new int [ len ] ; int count_zero = 0 , count_one = 0 ; for ( int j = 0 ; j < len ; j ++ ) { if ( S . charAt ( j ) == '0' ) count_zero ++ ; else count_one ++ ; dp [ j ] = count_zero * count_one ; } for ( int i = 1 ; i < K ; i ++ ) { for ( int j = len - 1 ; j >= i ; j -- ) { count_zero = 0 ; count_one = 0 ; dp [ j ] = Integer . MAX_VALUE ; for ( int k = j ; k >= i ; k -- ) { if ( S . charAt ( k ) == '0' ) count_zero ++ ; else count_one ++ ; dp [ j ] = Math . min ( dp [ j ] , count_zero * count_one + dp [ k - 1 ] ) ; } } } return dp [ len - 1 ] ; } public static void main ( String [ ] args ) { String S = \\\"1011000110110100\\\" ; int K = 5 ; System . out . print ( minSumProd ( S , K ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function printPascal ( $ n ) { $ arr = array ( array ( ) ) ; for ( $ line = 0 ; $ line < $ n ; $ line ++ ) { for ( $ 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 ] ; echo $ arr [ $ line ] [ $ i ] . \\\" \\\" ; } echo \\\" \\n \\\" ; } } $ n = 5 ; printPascal ( $ n ) ; ? >\",\"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\":\"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\\nHow can the above be solved 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 ▁ of ▁ % d ▁ and ▁ % d ▁ is ▁ \\\" , 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\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if a number has an odd count of odd divisors and even count of even divisors | Java implementation of the above approach ; Function to find the count of even and odd factors of N ; Loop runs till square root ; Condition to check if the even factors of the number N is is even and count of odd factors is odd ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static void checkFactors ( long N ) { long ev_count = 0 , od_count = 0 ; for ( long i = 1 ; i <= Math . sqrt ( N ) + 1 ; i ++ ) { if ( N % i == 0 ) { if ( i == N \\/ i ) { if ( i % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; } else { if ( i % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; if ( ( N \\/ i ) % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; } } } if ( ev_count % 2 == 0 && od_count % 2 == 1 ) System . out . print ( \\\" Yes \\\" + \\\"\\n\\\"); else System . out . print ( \\\" No \\\" + \\\"\\n\\\"); } public static void main ( String [ ] args ) { long N = 36 ; checkFactors ( N ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find minimum steps required to reach the end of a matrix | Set 2 | C ++ implementation of the approach ; 2d array to store states of dp ; Array to determine whether a state has been solved before ; Function to return the minimum steps required ; Base cases ; If a state has been solved before it won 't be evaluated again ; Recurrence relation ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\n#define n 3\\nusing namespace std ; int dp [ n ] [ n ] ; int v [ n ] [ n ] ; int minSteps ( int i , int j , int arr [ ] [ n ] ) { if ( i == n - 1 and j == n - 1 ) return 0 ; if ( i > n - 1 j > n - 1 ) return 9999999 ; if ( v [ i ] [ j ] ) return dp [ i ] [ j ] ; v [ i ] [ j ] = 1 ; dp [ i ] [ j ] = 9999999 ; for ( int k = max ( 0 , arr [ i ] [ j ] + j - n + 1 ) ; k <= min ( n - i - 1 , arr [ i ] [ j ] ) ; k ++ ) { dp [ i ] [ j ] = min ( dp [ i ] [ j ] , minSteps ( i + k , j + arr [ i ] [ j ] - k , arr ) ) ; } dp [ i ] [ j ] ++ ; return dp [ i ] [ j ] ; } int main ( ) { int arr [ n ] [ n ] = { { 4 , 1 , 2 } , { 1 , 1 , 1 } , { 2 , 1 , 1 } } ; int ans = minSteps ( 0 , 0 , arr ) ; if ( ans >= 9999999 ) cout << -1 ; else cout << ans ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Compositorial of a number | Function to check if a number is composite . ; Corner cases ; This is checked so that we can skip the middle five numbers in the below loop ; This function stores all Composite numbers less than N ; Function to calculate the Compositorial of n ; Multiply first n composite number ; Driver code ; Vector to store all the composite less than N\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def isComposite ( n ) :\\n\\tif ( n <= 3 ) :\\n\\t\\treturn False\\n\\tif ( n % 2 == 0 or n % 3 == 0 ) :\\n\\t\\treturn True\\n\\ti = 5\\n\\twhile ( i * i <= n ) :\\n\\t\\tif ( n % i == 0 or n % ( i + 2 ) == 0 ) :\\n\\t\\t\\treturn True\\n\\t\\ti = i + 6\\n\\treturn False\\ndef Compositorial_list ( n ) :\\n\\tl = 0\\n\\tfor i in range ( 4 , 10 ** 6 ) :\\n\\t\\tif l < n :\\n\\t\\t\\tif isComposite ( i ) :\\n\\t\\t\\t\\tcompo . append ( i )\\n\\t\\t\\t\\tl += 1\\ndef calculateCompositorial ( n ) :\\n\\tresult = 1\\n\\tfor i in range ( n ) :\\n\\t\\tresult = result * compo [ i ]\\n\\treturn result\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tn = 5\\n\\tcompo = [ ]\\n\\tCompositorial_list ( n )\\n\\tprint ( calculateCompositorial ( n ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all odd length subarrays | C # program for the above approach ; Function to calculate the sum of all odd length subarrays ; Stores the sum ; Size of array ; Traverse the array ; Generate all subarray of odd length ; Add the element to sum ; Return the final sum ; Driver Code ; Given array arr [ ] ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int OddLengthSum ( int [ ] arr ) { int sum = 0 ; int l = arr . Length ; for ( int i = 0 ; i < l ; i ++ ) { for ( int j = i ; j < l ; j += 2 ) { for ( int k = i ; k <= j ; k ++ ) { sum += arr [ k ] ; } } } return sum ; } public static void Main ( ) { int [ ] arr = { 1 , 5 , 3 , 1 , 2 } ; Console . Write ( OddLengthSum ( arr ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Rearrange array to maximize sum of GCD of array elements with their respective indices | C # program to implement the above approach ; Function to find the maximum sum of GCD ( arr [ i ] , i ) by rearranging the array ; Sort the array in ascending order ; Stores maximum sum of GCD ( arr [ i ] , i ) by rearranging the array elements ; Generate all possible permutations of the array ; Stores sum of GCD ( arr [ i ] , i ) ; Traverse the array ; Update sum ; Update res ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int findMaxValByRearrArr ( int [ ] arr , int N ) { Array . Sort ( arr ) ; int res = 0 ; do { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += __gcd ( i + 1 , arr [ i ] ) ; } res = Math . Max ( res , sum ) ; } while ( next_permutation ( arr ) ) ; return res ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } static bool next_permutation ( int [ ] p ) { for ( int a = p . Length - 2 ; a >= 0 ; -- a ) if ( p [ a ] < p [ a + 1 ] ) for ( int b = p . Length - 1 ; ; -- b ) if ( p [ b ] > p [ a ] ) { int t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; for ( ++ a , b = p . Length - 1 ; a < b ; ++ a , -- b ) { t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; } return true ; } return false ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 1 } ; int N = arr . Length ; Console . Write ( findMaxValByRearrArr ( arr , N ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count all prefixes of the given binary array which are divisible by x | Function to return the count of total binary prefix which are divisible by x ; Initialize with zero ; Convert all prefixes to decimal ; If number is divisible by x then increase count ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function CntDivbyX ( $ arr , $ n , $ x ) { $ number = 0 ; $ count = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ number = $ number * 2 + $ arr [ $ i ] ; if ( ( $ number % $ x == 0 ) ) $ count += 1 ; } return $ count ; } $ arr = array ( 1 , 0 , 1 , 0 , 1 , 1 , 0 ) ; $ n = sizeof ( $ arr ) ; $ x = 2 ; echo CntDivbyX ( $ arr , $ n , $ x ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Longest Increasing Subsequence | DP | lis ( ) returns the length of the longest increasing subsequence in arr [ ] of size n ; Initialize LIS values for all indexes ; Compute optimized LIS values in bottom up manner ; Pick maximum of all LIS values ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function lis ( arr , n ) { let lis = Array ( n ) . fill ( 0 ) ; let i , j , max = 0 ; for ( i = 0 ; i < n ; i ++ ) lis [ i ] = 1 ; for ( i = 1 ; i < n ; i ++ ) for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; for ( i = 0 ; i < n ; i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ; return max ; } let arr = [ 10 , 22 , 9 , 33 , 21 , 50 , 41 , 60 ] ; let n = arr . length ; document . write ( \\\" \\\" + lis ( arr , n ) + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\\\"\\nSolution 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 ( \\\" ▁ % d ▁ \\\" , cand ) ; else printf ( \\\" No ▁ Majority ▁ 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\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Binomial Random Variables | function to calculate nCr i . e . , number of ways to choose r out of n objects ; Since nCr is same as nC ( n - r ) To decrease number of iterations ; function to calculate binomial r . v . probability ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function nCr ( $ n , $ r ) { if ( $ r > $ n \\/ 2 ) $ r = $ n - $ r ; $ answer = 1 ; for ( $ i = 1 ; $ i <= $ r ; $ i ++ ) { $ answer *= ( $ n - $ r + $ i ) ; $ answer \\/= $ i ; } return $ answer ; } function binomialProbability ( $ n , $ k , $ p ) { return nCr ( $ n , $ k ) * pow ( $ p , $ k ) * pow ( 1 - $ p , $ n - $ k ) ; } $ n = 10 ; $ k = 5 ; $ p = 1.0 \\/ 3 ; $ probability = binomialProbability ( $ n , $ k , $ p ) ; echo \\\" Probability ▁ of ▁ \\\" . $ k ; echo \\\" ▁ heads ▁ when ▁ a ▁ coin ▁ is ▁ tossed ▁ \\\" . $ n ; echo \\\" ▁ times ▁ where ▁ probability ▁ of ▁ \\\" . \\\" each ▁ head ▁ is ▁ \\\" . $ p ; echo \\\" is = \\\" ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Number of permutation with K inversions | Set 2 | C # program for the above approach ; Function to count permutations with K inversions ; Store number of permutations with K inversions ; If N = 1 only 1 permutation with no inversion ; For K = 0 only 1 permutation with no inversion ; Otherwise Update each dp state as per the reccurrance relation formed ; Print final count ; Driver Code ; Given N and K ; Function Call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void numberOfPermWithKInversion ( int N , int K ) { int [ , ] dp = new int [ 2 , K + 1 ] ; int mod = 1000000007 ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 0 ; j <= K ; j ++ ) { if ( i == 1 ) { dp [ i % 2 , j ] = ( j == 0 ) ? 1 : 0 ; } else if ( j == 0 ) dp [ i % 2 , j ] = 1 ; else dp [ i % 2 , j ] = ( dp [ i % 2 , j - 1 ] % mod + ( dp [ 1 - i % 2 , j ] - ( ( Math . Max ( j - ( i - 1 ) , 0 ) == 0 ) ? 0 : dp [ 1 - i % 2 , Math . Max ( j - ( i - 1 ) , 0 ) - 1 ] ) + mod ) % mod ) % mod ; } } Console . WriteLine ( dp [ N % 2 , K ] ) ; } public static void Main ( ) { int N = 3 , K = 2 ; numberOfPermWithKInversion ( N , K ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Largest lexicographic triplet from a given Array that forms a triangle | C # program to implement the the above approach ; 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\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void findTriplet ( int [ ] arr , int N ) { Array . Sort ( arr ) ; int 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 != 0 ) { Console . Write ( arr [ i - 2 ] + \\\" ▁ \\\" + arr [ i - 1 ] + \\\" ▁ \\\" + arr [ i ] ) ; } else { Console . Write ( - 1 ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 4 , 2 , 10 , 3 , 5 } ; int N = arr . Length ; findTriplet ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Smallest character in a string having minimum sum of distances between consecutive repetitions | Python3 program for the above approach ; Function to find the character repeats with minimum distance ; Stores the first and last index ; Intialize with - 1 ; Get the values of last and first occurence ; Update the first index ; Update the last index ; Intialize the min ; Get the minimum ; Values must not be same ; Update the minimum distance ; return ans ; Driver Code ; Function call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import sys\\ndef minDistChar ( s ) :\\n\\tn = len ( s )\\n\\tfirst = [ ]\\n\\tlast = [ ]\\n\\tfor i in range ( 26 ) :\\n\\t\\tfirst . append ( - 1 )\\n\\t\\tlast . append ( - 1 )\\n\\tfor i in range ( n ) :\\n\\t\\tif ( first [ ord ( s [ i ] ) - ord ( ' a ' ) ] == - 1 ) :\\n\\t\\t\\tfirst [ ord ( s [ i ] ) - ord ( ' a ' ) ] = i\\n\\t\\tlast [ ord ( s [ i ] ) - ord ( ' a ' ) ] = i\\n\\tmin = sys . maxsize\\n\\tans = '1'\\n\\tfor i in range ( 26 ) :\\n\\t\\tif ( last [ i ] == first [ i ] ) :\\n\\t\\t\\tcontinue\\n\\t\\tif ( min > last [ i ] - first [ i ] ) :\\n\\t\\t\\tmin = last [ i ] - first [ i ]\\n\\t\\t\\tans = i + ord ( ' a ' )\\n\\treturn chr ( ans )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tstr = \\\" geeksforgeeks \\\"\\n\\tprint ( minDistChar ( str ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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 ▁ Obtainable ▁ Value ▁ is ▁ \\\" + cutRod ( arr , size ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find minimum steps required to reach the end of a matrix | Set | Java program to implement above approach ; 2d array to store states of dp ; array to determine whether a state has been solved before ; Function to find the minimum number of steps to reach the end of matrix ; base cases ; if a state has been solved before it won 't be evaluated again. ; recurrence relation ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int n = 3 ; static int dp [ ] [ ] = new int [ n ] [ n ] ; static int [ ] [ ] v = new int [ n ] [ n ] ; static int minSteps ( int i , int j , int arr [ ] [ ] ) { if ( i == n - 1 && j == n - 1 ) { return 0 ; } if ( i > n - 1 j > n - 1 ) { return 9999999 ; } if ( v [ i ] [ j ] == 1 ) { return dp [ i ] [ j ] ; } v [ i ] [ j ] = 1 ; dp [ i ] [ j ] = 1 + Math . min ( minSteps ( i + arr [ i ] [ j ] , j , arr ) , minSteps ( i , j + arr [ i ] [ j ] , arr ) ) ; return dp [ i ] [ j ] ; } public static void main ( String [ ] args ) { int arr [ ] [ ] = { { 2 , 1 , 2 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ; int ans = minSteps ( 0 , 0 , arr ) ; if ( ans >= 9999999 ) { System . out . println ( - 1 ) ; } else { System . out . println ( ans ) ; } } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find most significant set bit of a number | CPP program to find MSB number for given n . ; To find the position of the most significant set bit ; To return the the value of the number with set bit at k - th position ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int setBitNumber ( int n ) { int k = ( int ) ( log2 ( n ) ) ; return 1 << k ; } int main ( ) { int n = 273 ; cout << setBitNumber ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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\\\"\\nSolution 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 ▁ n \\\" , FindMaxSum ( arr , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Secretary Problem ( A Optimal Stopping Problem ) | PHP Program to test 1 \\/ e law for Secretary Problem : ; To find closest integer of num . ; Finds best candidate using n \\/ e rule . candidate [ ] represents talents of n candidates . ; Calculating sample size for benchmarking . ; Finding best candidate in sample size ; Finding the first best candidate that is better than benchmark set . ; Driver code ; n = 8 candidates and candidate array contains talents of n candidate where the largest number means highest talented candidate . ; generating random numbers between 1 to 8 for talent of candidate\\\"\\nSolution in php:\",\"targets\":\"< ? php $ e = 2.71828 ; function roundNo ( $ num ) { return $ num < 0 ? $ num - 0.5 : $ num + 0.5 ; } function printBestCandidate ( $ candidate , $ n ) { global $ e ; $ sample_size = roundNo ( $ n \\/ $ e ) ; echo \\\" Sample size is \\\" floor ( $ sample_size ) . \\\" \\n \\\" ; $ best = 0 ; for ( $ i = 1 ; $ i < $ sample_size ; $ i ++ ) if ( $ candidate [ $ i ] > $ candidate [ $ best ] ) $ best = $ i ; for ( $ i = $ sample_size ; $ i < $ n ; $ i ++ ) if ( $ candidate [ $ i ] >= $ candidate [ $ best ] ) { $ best = $ i ; break ; } if ( $ best >= $ sample_size ) echo \\\" Best candidate found is \\\" . floor ( $ best + 1 ) . \\\" ▁ with ▁ talent ▁ \\\" . floor ( $ candidate [ $ best ] ) . \\\" \\n \\\" ; else echo \\\" Couldn ' t ▁ find ▁ a ▁ best ▁ candidate \\n \\\" ; } $ n = 8 ; $ candidate = array_fill ( 0 , $ n , 0 ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ candidate [ $ i ] = 1 + rand ( 1 , 8 ) ; echo \\\" Candidate ▁ : ▁ \\\" ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo ( $ i + 1 ) . \\\" ▁ \\\" ; echo \\\" Talents : \\\" ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo $ candidate [ $ i ] . \\\" ▁ \\\" ; printBestCandidate ( $ candidate , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"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\":\"\\\"Maximize length of longest subarray consisting of same elements by at most K decrements | Java program to implement the above approach ; Function to construct Segment Tree to return the minimum element in a range ; If leaf nodes of the tree are found ; Update the value in segment tree from given array ; Divide left and right subtree ; Stores smallest element in subarray { arr [ start ] , arr [ mid ] } ; Stores smallest element in subarray { arr [ mid + 1 ] , arr [ end ] } ; Stores smallest element in subarray { arr [ start ] , arr [ end ] } ; Function to find the smallest element present in a subarray ; If elements of the subarray are not in the range [ l , r ] ; If all the elements of the subarray are in the range [ l , r ] ; Divide tree into left and right subtree ; Stores smallest element in left subtree ; Stores smallest element in right subtree ; Function that find length of longest subarray with all equal elements in atmost K decrements ; Stores length of longest subarray with all equal elements in atmost K decrements . ; Store the prefix sum array ; Calculate the prefix sum array ; Build the segment tree for range min query ; Traverse the array ; Stores start index of the subarray ; Stores end index of the subarray ; Stores end index of the longest subarray ; Performing the binary search to find the endpoint for the selected range ; Find the mid for binary search ; Find the smallest element in range [ i , mid ] using Segment Tree ; Stores total sum of subarray after K decrements ; Stores sum of elements of subarray before K decrements ; If subarray found with all equal elements ; Update start ; Update max_index ; If false , it means that the selected range is invalid ; Update end ; Store the length of longest subarray ; Return result ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static int build ( int tree [ ] , int [ ] A , int start , int end , int node ) { if ( start == end ) { tree [ node ] = A [ start ] ; return tree [ node ] ; } int mid = ( start + end ) \\/ 2 ; int X = build ( tree , A , start , mid , 2 * node + 1 ) ; int Y = build ( tree , A , mid + 1 , end , 2 * node + 2 ) ; return ( tree [ node ] = Math . min ( X , Y ) ) ; } static int query ( int tree [ ] , int start , int end , int l , int r , int node ) { if ( start > r end < l ) return Integer . MAX_VALUE ; if ( start >= l && end <= r ) return tree [ node ] ; int mid = ( start + end ) \\/ 2 ; int X = query ( tree , start , mid , l , r , 2 * node + 1 ) ; int Y = query ( tree , mid + 1 , end , l , r , 2 * node + 2 ) ; return Math . min ( X , Y ) ; } static int longestSubArray ( int [ ] A , int N , int K ) { int res = 1 ; int preSum [ ] = new int [ N + 1 ] ; preSum [ 0 ] = A [ 0 ] ; for ( int i = 0 ; i < N ; i ++ ) preSum [ i + 1 ] = preSum [ i ] + A [ i ] ; int tree [ ] = new int [ 4 * N + 5 ] ; build ( tree , A , 0 , N - 1 , 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { int start = i ; int end = N - 1 ; int mid ; int max_index = i ; while ( start <= end ) { mid = ( start + end ) \\/ 2 ; int min_element = query ( tree , 0 , N - 1 , i , mid , 0 ) ; int expected_sum = ( mid - i + 1 ) * min_element ; int actual_sum = preSum [ mid + 1 ] - preSum [ i ] ; if ( actual_sum - expected_sum <= K ) { start = mid + 1 ; max_index = Math . max ( max_index , mid ) ; } else { end = mid - 1 ; } } res = Math . max ( res , max_index - i + 1 ) ; } return res ; } static public void main ( String args [ ] ) { int arr [ ] = { 1 , 7 , 3 , 4 , 5 , 6 } ; int k = 6 ; int n = 6 ; System . out . print ( longestSubArray ( arr , n , k ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 ▁ \\\" , 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\":\"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 \\nvoid 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 ) ) ; printf ( \\\" Perpendicular ▁ distance ▁ is ▁ % f \\n \\\" , d ) ; } else printf ( \\\" Planes ▁ are ▁ not ▁ 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\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Modify array of strings by replacing characters repeating in the same or remaining strings | Function to remove duplicate characters across the strings ; Stores distinct characters ; Size of the array ; Stores the list of modified strings ; Traverse the array ; Stores the modified string ; Iterate over the characters of the modified string ; If character is already present ; Insert character into the Set ; Print the list of modified strings ; Print each string ; Given array of strings ; Function Call to modify the given array of strings\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function removeDuplicateCharacters ( arr ) { var cset = new Set ( ) ; var n = arr . length ; var out = [ ] ; arr . forEach ( str => { var out_curr = \\\" \\\" ; str . split ( ' ' ) . forEach ( ch => { if ( ! cset . has ( ch ) ) { out_curr += ch ; cset . add ( ch ) ; } } ) ; if ( out_curr . size != 0 ) out . push ( out_curr ) ; } ) ; for ( var i = 0 ; i < out . length ; i ++ ) { document . write ( out [ i ] + \\\" \\\" ) ; } } var arr = [ \\\" \\\" , \\\" \\\" , \\\" \\\" , \\\" \\\" ] ; removeDuplicateCharacters ( arr ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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 Java:\",\"targets\":\"class GFG { static long boost_hyperfactorial ( long num ) { long val = 1 ; for ( int i = 1 ; i <= num ; i ++ ) { val = val * ( long ) Math . pow ( i , i ) ; } return val ; } public static void main ( String args [ ] ) { int num = 5 ; System . out . println ( boost_hyperfactorial ( num ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count of minimum reductions required to get the required sum K | Python3 program to find the count of minimum reductions required to get the required sum K ; Function to return the count of minimum reductions ; If the sum is already less than K ; Sort in non - increasing order of difference ; Driver Code ; Function Call\\\"\\nSolution in Python:\",\"targets\":\"from typing import Any , List\\ndef countReductions ( v : List [ Any ] , K : int ) -> int :\\n\\tsum = 0\\n\\tfor i in v :\\n\\t\\tsum += i [ 0 ]\\n\\tif ( sum <= K ) :\\n\\t\\treturn 0\\n\\tv . sort ( key = lambda a : a [ 0 ] - a [ 1 ] )\\n\\ti = 0\\n\\twhile ( sum > K and i < len ( v ) ) :\\n\\t\\tsum -= ( v [ i ] [ 0 ] - v [ i ] [ 1 ] )\\n\\t\\ti += 1\\n\\tif ( sum <= K ) :\\n\\t\\treturn i\\n\\treturn - 1\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tN = 4\\n\\tK = 25\\n\\tv = [ [ 0 , 0 ] for _ in range ( N ) ]\\n\\tv [ 0 ] = [ 10 , 5 ]\\n\\tv [ 1 ] = [ 20 , 9 ]\\n\\tv [ 2 ] = [ 12 , 10 ]\\n\\tv [ 3 ] = [ 4 , 2 ]\\n\\tprint ( countReductions ( v , K ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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 Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int 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 ] ) ; cout << \\\" Required ▁ number ▁ of ▁ groups ▁ are ▁ \\\" << findgroups ( arr , n ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Subarrays whose sum is a perfect square | Function to print the start and end indices of all subarrays whose sum is a perfect square ; Stores the current subarray sum ; Update current subarray sum ; Stores the square root of currSubSum ; Check if currSubSum is a perfect square or not ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function PrintIndexes ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { let currSubSum = 0 ; for ( let j = i ; j < N ; j ++ ) { currSubSum += arr [ j ] ; let sq = Math . floor ( Math . sqrt ( currSubSum ) ) ; if ( sq * sq == currSubSum ) { document . write ( \\\" \\\" + i + \\\" \\\" + j + \\\" \\\" + \\\" \\\" ) ; } } } } let arr = [ 65 , 79 , 81 ] ; PrintIndexes ( arr , arr . length ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum removals required to make frequency of each array element equal to its value | Java 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 Java:\",\"targets\":\"import java . util . * ; class GFG { public static int min_elements ( int arr [ ] , int N ) { Map < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { mp . put ( arr [ i ] , mp . getOrDefault ( arr [ i ] , 0 ) + 1 ) ; } int cntMinRem = 0 ; for ( int key : mp . keySet ( ) ) { int i = key ; int val = mp . get ( i ) ; if ( val < i ) { cntMinRem += val ; } else if ( val > i ) { cntMinRem += ( val - i ) ; } } return cntMinRem ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 1 , 4 , 2 } ; System . out . println ( min_elements ( arr , arr . length ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sort an Array which contain 1 to N values in O ( N ) using Cycle Sort | C ++ program for the above approach ; Function to swap two a & b value ; Function to print array element ; Traverse the array ; Function to sort the array in O ( N ) ; Traverse the array ; If the current element is at correct position ; Else swap the current element with it 's correct position ; Driver Code ; Function call to sort the array ; Function call to print the array\\\"\\nSolution in C++:\",\"targets\":\"#include \\\" bits \\/ stdc + + . h \\\"\\nusing namespace std ; void swap ( int * a , int * b ) { int temp = * a ; * a = * b ; * b = temp ; } void printArray ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { cout << arr [ i ] << ' ▁ ' ; } } void sortArray ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; ) { if ( arr [ i ] == i + 1 ) { i ++ ; } else { swap ( & arr [ i ] , & arr [ arr [ i ] - 1 ] ) ; } } } int main ( ) { int arr [ ] = { 2 , 1 , 5 , 3 , 4 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; sortArray ( arr , N ) ; printArray ( arr , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find most significant set bit of a number | Simple PhP program to find MSB number for given n . ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function setBitNumber ( $ n ) { if ( $ n == 0 ) return 0 ; $ msb = 0 ; $ n = $ n \\/ 2 ; while ( $ n != 0 ) { $ n = $ n \\/ 2 ; $ msb ++ ; } return ( 1 << $ msb ) ; } $ n = 0 ; echo setBitNumber ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Partition problem | DP | 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 ; Driver Code ; Function call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findPartition ( arr , n ) :\\n\\tsum = 0\\n\\ti , j = 0 , 0\\n\\tfor i in range ( n ) :\\n\\t\\tsum += arr [ i ]\\n\\tif sum % 2 != 0 :\\n\\t\\treturn false\\n\\tpart = [ [ True for i in range ( n + 1 ) ] for j in range ( sum \\/\\/ 2 + 1 ) ]\\n\\tfor i in range ( 0 , n + 1 ) :\\n\\t\\tpart [ 0 ] [ i ] = True\\n\\tfor i in range ( 1 , sum \\/\\/ 2 + 1 ) :\\n\\t\\tpart [ i ] [ 0 ] = False\\n\\tfor i in range ( 1 , sum \\/\\/ 2 + 1 ) :\\n\\t\\tfor j in range ( 1 , n + 1 ) :\\n\\t\\t\\tpart [ i ] [ j ] = part [ i ] [ j - 1 ]\\n\\t\\t\\tif i >= arr [ j - 1 ] :\\n\\t\\t\\t\\tpart [ i ] [ j ] = ( part [ i ] [ j ] or part [ i - arr [ j - 1 ] ] [ j - 1 ] )\\n\\treturn part [ sum \\/\\/ 2 ] [ n ]\\narr = [ 3 , 1 , 1 , 2 , 2 , 1 ]\\nn = len ( arr )\\nif findPartition ( arr , n ) == True :\\n\\tprint ( \\\" Can ▁ be ▁ divided ▁ into ▁ two \\\" , \\\" subsets ▁ of ▁ equal ▁ sum \\\" )\\nelse :\\n\\tprint ( \\\" Can ▁ not ▁ be ▁ divided ▁ into ▁ \\\" , \\\" two ▁ subsets ▁ of ▁ equal ▁ sum \\\" )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count number of substrings of a string consisting of same characters | Function to return the number of substrings of same characters ; Size of the string ; Initialize count to 1 ; Initialize left to 0 and right to 1 to traverse the string ; Checking if consecutive characters are same and increment the count ; When we encounter a different characters ; Increment the result ; To repeat the whole process set left equals right and count variable to 1 ; Store the final value of result ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function findNumbers ( s ) { var n = s . length ; var count = 1 ; var result = 0 ; var left = 0 ; var right = 1 ; while ( right < n ) { if ( s [ left ] == s [ right ] ) { count ++ ; } else { result += parseInt ( count * ( count + 1 ) \\/ 2 ) ; left = right ; count = 1 ; } right ++ ; } result += parseInt ( count * ( count + 1 ) \\/ 2 ) ; document . write ( result ) ; } var s = \\\" \\\" ; findNumbers ( s ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count numbers from range whose prime factors are only 2 and 3 | Function to count the number within a range whose prime factors are only 2 and 3 ; Start with 2 so that 1 doesn 't get counted ; While num is divisible by 2 , divide it by 2 ; While num is divisible by 3 , divide it by 3 ; If num got reduced to 1 then it has only 2 and 3 as prime factors ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findTwoThreePrime ( $ l , $ r ) { if ( $ l == 1 ) $ l ++ ; $ count = 0 ; for ( $ i = $ l ; $ i <= $ r ; $ i ++ ) { $ num = $ i ; while ( $ num % 2 == 0 ) $ num \\/= 2 ; while ( $ num % 3 == 0 ) $ num \\/= 3 ; if ( $ num == 1 ) $ count ++ ; } return $ count ; } $ l = 1 ; $ r = 10 ; echo findTwoThreePrime ( $ l , $ r ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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 Code\\\"\\nSolution in Javascript:\",\"targets\":\"function findFirstMissing ( array , start , end ) { if ( start > end ) return end + 1 ; if ( start != array [ start ] ) return start ; let mid = parseInt ( ( start + end ) \\/ 2 , 10 ) ; if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ; return findFirstMissing ( array , start , mid ) ; } let arr = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 10 ] ; let n = arr . length ; document . write ( \\\" \\\" + findFirstMissing ( arr , 0 , n - 1 ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to reach the nth stair using step 1 , 2 or 3 | A recursive function used by countWays ; declaring three variables and holding the ways for first three stairs ; d = 0 fourth variable ; starting from 4 as already counted for 3 stairs ; Driver program to test above functions\\\"\\nSolution in Python:\",\"targets\":\"def countWays ( n ) :\\n\\ta = 1\\n\\tb = 2\\n\\tc = 4\\n\\tif ( n == 0 or n == 1 or n == 2 ) :\\n\\t\\treturn n\\n\\tif ( n == 3 ) :\\n\\t\\treturn c\\n\\tfor i in range ( 4 , n + 1 ) :\\n\\t\\td = c + b + a\\n\\t\\ta = b\\n\\t\\tb = c\\n\\t\\tc = d\\n\\treturn d\\nn = 4\\nprint ( countWays ( n ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Smallest number exceeding N whose Kth bit is set | Function to find the number greater than n whose Kth bit is set ; Iterate from N + 1 ; Check if Kth bit is set or not ; Increment M for next number ; Return the minimum value ; Driver Code ; Given N and K ; Function Call\\\"\\nSolution in Python:\",\"targets\":\"def find_next ( n , k ) :\\n\\tM = n + 1 ;\\n\\twhile ( True ) :\\n\\t\\tif ( ( M & ( 1 << k ) ) > 0 ) :\\n\\t\\t\\tbreak ;\\n\\t\\tM += 1 ;\\n\\treturn M ;\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 15 ; K = 2 ;\\n\\tprint ( find_next ( N , K ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"Find position of the only set bit | C program to find position of only set bit in a given number ; A utility function to check whether n is power of 2 or not ; Returns position of the only set bit in ' n ' ; One by one move the only set bit to right till it reaches end ; increment count of shifts ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint isPowerOfTwo ( unsigned n ) { return n && ( ! ( n & ( n - 1 ) ) ) ; } int findPosition ( unsigned n ) { if ( ! isPowerOfTwo ( n ) ) return -1 ; unsigned count = 0 ; while ( n ) { n = n >> 1 ; ++ count ; } return count ; } int main ( void ) { int n = 0 ; int pos = findPosition ( n ) ; ( pos == -1 ) ? printf ( \\\" n ▁ = ▁ % d , ▁ Invalid ▁ number \\n \\\" , n ) : printf ( \\\" n ▁ = ▁ % d , ▁ Position ▁ % d ▁ \\n \\\" , n , pos ) ; n = 12 ; pos = findPosition ( n ) ; ( pos == -1 ) ? printf ( \\\" n ▁ = ▁ % d , ▁ Invalid ▁ number \\n \\\" , n ) : printf ( \\\" n ▁ = ▁ % d , ▁ Position ▁ % d ▁ \\n \\\" , n , pos ) ; n = 128 ; pos = findPosition ( n ) ; ( pos == -1 ) ? printf ( \\\" n ▁ = ▁ % d , ▁ Invalid ▁ number \\n \\\" , n ) : printf ( \\\" n ▁ = ▁ % d , ▁ Position ▁ % d ▁ \\n \\\" , n , pos ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-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\":\"\\\"Maximum equlibrium sum in an array | 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 Python?\",\"targets\":\"def findMaxSum ( arr , n ) :\\n\\tpreSum = [ 0 for i in range ( n ) ]\\n\\tsuffSum = [ 0 for i in range ( n ) ]\\n\\tans = - 10000000\\n\\tpreSum [ 0 ] = arr [ 0 ]\\n\\tfor i in range ( 1 , n ) :\\n\\t\\tpreSum [ i ] = preSum [ i - 1 ] + arr [ i ]\\n\\tsuffSum [ n - 1 ] = arr [ n - 1 ]\\n\\tif ( preSum [ n - 1 ] == suffSum [ n - 1 ] ) :\\n\\t\\tans = max ( ans , preSum [ n - 1 ] )\\n\\tfor i in range ( n - 2 , - 1 , - 1 ) :\\n\\t\\tsuffSum [ i ] = suffSum [ i + 1 ] + arr [ i ]\\n\\t\\tif ( suffSum [ i ] == preSum [ i ] ) :\\n\\t\\t\\tans = max ( ans , preSum [ i ] )\\n\\treturn ans\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ - 2 , 5 , 3 , 1 , 2 , 6 , - 4 , 2 ]\\n\\tn = len ( arr )\\n\\tprint ( findMaxSum ( arr , n ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sieve of Atkin | C ++ program for implementation of Sieve of Atkin ; 2 and 3 are known to be prime ; Initialise the sieve array with false values ; Mark sieve [ n ] is true if one of the following is true : a ) n = ( 4 * x * x ) + ( y * y ) has odd number of solutions , i . e . , there exist odd number of distinct pairs ( x , y ) that satisfy the equation and n % 12 = 1 or n % 12 = 5. b ) n = ( 3 * x * x ) + ( y * y ) has odd number of solutions and n % 12 = 7 c ) n = ( 3 * x * x ) - ( y * y ) has odd number of solutions , x > y and n % 12 = 11 ; Main part of Sieve of Atkin ; Mark all multiples of squares as non - prime ; Print primes using sieve [ ] ; Driver program\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int SieveOfAtkin ( int limit ) { if ( limit > 2 ) cout << 2 << \\\" ▁ \\\" ; if ( limit > 3 ) cout << 3 << \\\" ▁ \\\" ; bool sieve [ limit ] ; for ( int i = 0 ; i < limit ; i ++ ) sieve [ i ] = false ; for ( int x = 1 ; x * x < limit ; x ++ ) { for ( int y = 1 ; y * y < limit ; y ++ ) { int n = ( 4 * x * x ) + ( y * y ) ; if ( n <= limit && ( n % 12 == 1 n % 12 == 5 ) ) sieve [ n ] ^= true ; n = ( 3 * x * x ) + ( y * y ) ; if ( n <= limit && n % 12 == 7 ) sieve [ n ] ^= true ; n = ( 3 * x * x ) - ( y * y ) ; if ( x > y && n <= limit && n % 12 == 11 ) sieve [ n ] ^= true ; } } for ( int r = 5 ; r * r < limit ; r ++ ) { if ( sieve [ r ] ) { for ( int i = r * r ; i < limit ; i += r * r ) sieve [ i ] = false ; } } for ( int a = 5 ; a < limit ; a ++ ) if ( sieve [ a ] ) cout << a << \\\" ▁ \\\" ; } int main ( void ) { int limit = 20 ; SieveOfAtkin ( limit ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Print all possible rotations of a given Array | Java program to print all possible rotations of the given array ; Global declaration of array ; Function to reverse array between indices s and e ; Function to generate all possible rotations of array ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int arr [ ] = new int [ 10000 ] ; public static void reverse ( int arr [ ] , int s , int e ) { while ( s < e ) { int tem = arr [ s ] ; arr [ s ] = arr [ e ] ; arr [ e ] = tem ; s = s + 1 ; e = e - 1 ; } } public static void fun ( int arr [ ] , int k ) { int n = 4 - 1 ; int v = n - k ; if ( v >= 0 ) { reverse ( arr , 0 , v ) ; reverse ( arr , v + 1 , n ) ; reverse ( arr , 0 , n ) ; } } public static void main ( String args [ ] ) { arr [ 0 ] = 1 ; arr [ 1 ] = 2 ; arr [ 2 ] = 3 ; arr [ 3 ] = 4 ; for ( int i = 0 ; i < 4 ; i ++ ) { fun ( arr , i ) ; System . out . print ( \\\" [ \\\" ) ; for ( int j = 0 ; j < 4 ; j ++ ) { System . out . print ( arr [ j ] + \\\" , ▁ \\\" ) ; } System . out . print ( \\\" ] \\\" ) ; } } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimize the difference between the maximum and minimum values of the modified array | C # program to find the minimum difference . ; Function to return required minimum difference ; finding minimum and maximum values ; returning minimum possible difference ; Driver program ; function to return the answer\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int minDiff ( int n , int x , int [ ] A ) { int mn = A [ 0 ] , mx = A [ 0 ] ; for ( int i = 0 ; i < n ; ++ i ) { mn = Math . Min ( mn , A [ i ] ) ; mx = Math . Max ( mx , A [ i ] ) ; } return Math . Max ( 0 , mx - mn - 2 * x ) ; } public static void Main ( ) { int n = 3 , x = 3 ; int [ ] A = { 1 , 3 , 6 } ; Console . WriteLine ( minDiff ( n , x , A ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Largest number divisible by 50 that can be formed from a given set of N digits consisting of 0 s and 7 s only | C ++ Program for the above approach ; Print the largest number divisible by 50 ; Counting number of 0 s and 7 s ; If count of 7 is divisible by 50 ; If count of 7 is less than 5 ; If count of 7 is not divisible by 50 ; Count of groups of 5 in which count of 7 s can be grouped ; Driver Code ; Given array ; Size of the array\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void printLargestDivisible ( int arr [ ] , int N ) { int i , count0 = 0 , count7 = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) count0 ++ ; else count7 ++ ; } if ( count7 % 50 == 0 ) { while ( count7 -- ) cout << 7 ; while ( count0 -- ) cout << 0 ; } else if ( count7 < 5 ) { if ( count0 == 0 ) cout << \\\" No \\\" ; else cout << \\\"0\\\" ; } else { count7 = count7 - count7 % 5 ; while ( count7 -- ) cout << 7 ; while ( count0 -- ) cout << 0 ; } } int main ( ) { int arr [ ] = { 0 , 7 , 0 , 7 , 7 , 7 , 7 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 7 , 7 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printLargestDivisible ( arr , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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 to find the Nth day present is given out ; Find the number of presents given on day is day * ( day + 1 ) \\/ 2 ; Iterate over the type ; Return the resultant type ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function itemType ( n ) { let count = 0 ; let day = 1 ; while ( count + day * ( day + 1 ) \\/ 2 < n ) { count += day * ( day + 1 ) \\/ 2 ; day ++ ; } for ( let type = day ; type > 0 ; type -- ) { count += type ; if ( count >= n ) { return type ; } } } let N = 10 ; document . write ( itemType ( N ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of given operations required to reduce the array to 0 element | C ++ implementation of the approach ; 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\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int minOperations ( int * arr , int n ) { int maxi , result = 0 ; vector < int > freq ( 1000001 , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) { int x = arr [ i ] ; freq [ x ] ++ ; } maxi = * ( max_element ( arr , arr + n ) ) ; for ( int i = 1 ; i <= maxi ; i ++ ) { if ( freq [ i ] != 0 ) { for ( int j = i * 2 ; j <= maxi ; j = j + i ) { freq [ j ] = 0 ; } result ++ ; } } return result ; } int main ( ) { int arr [ ] = { 2 , 4 , 2 , 4 , 4 , 4 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << minOperations ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find a Fixed Point ( Value equal to index ) in a given array | Python program to check fixed point in an array using binary search ; ; Return - 1 if there is no Fixed Point ; Driver program to check above functions\\\"\\nSolution in Python:\",\"targets\":\"def binarySearch ( arr , low , high ) :\\n\\tif high >= low :\\n\\t\\tmid = ( low + high ) \\/\\/ 2\\n\\tif mid is arr [ mid ] :\\n\\t\\treturn mid\\n\\tif mid > arr [ mid ] :\\n\\t\\treturn binarySearch ( arr , ( mid + 1 ) , high )\\n\\telse :\\n\\t\\treturn binarySearch ( arr , low , ( mid - 1 ) )\\n\\treturn - 1\\narr = [ - 10 , - 1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 ]\\nn = len ( arr )\\nprint ( \\\" Fixed ▁ Point ▁ is ▁ \\\" + str ( binarySearch ( arr , 0 , n - 1 ) ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find two numbers whose sum and GCD are given | Java program to find two numbers whose sum and GCD is given ; function to find gcd of two numbers ; Function to find two numbers whose sum and gcd is given ; sum != gcd checks that both the numbers are positive or not ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class Solution { static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } static void findTwoNumbers ( int sum , int gcd ) { if ( __gcd ( gcd , sum - gcd ) == gcd && sum != gcd ) System . out . println ( \\\" a ▁ = ▁ \\\" + Math . min ( gcd , sum - gcd ) + \\\" , ▁ b ▁ = ▁ \\\" + ( int ) ( sum - Math . min ( gcd , sum - gcd ) ) ) ; else System . out . println ( - 1 ) ; } public static void main ( String args [ ] ) { int sum = 8 ; int gcd = 2 ; findTwoNumbers ( sum , gcd ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Print N numbers such that their sum is a Perfect Cube | C ++ implementation to find the N numbers such that their sum is a perfect cube ; Function to find the N numbers such that their sum is a perfect cube ; Loop to find the Ith term of the Centered Hexagonal number ; Driver Code ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void findNumbers ( int n ) { int i = 1 ; while ( i <= n ) { cout << ( 3 * i * ( i - 1 ) + 1 ) << \\\" ▁ \\\" ; i ++ ; } } int main ( ) { int n = 4 ; findNumbers ( n ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximize a given unsigned number number by swapping bits at it 's extreme positions. | JavaScript 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\\\"\\nSolution in Javascript:\",\"targets\":\"function findMax ( num ) { let num_copy = num ; let j = 4 * 8 - 1 ; let i = 0 ; while ( i < j ) { let m = ( num_copy >> i ) & 1 ; let n = ( num_copy >> j ) & 1 ; if ( m > n ) { let x = ( 1 << i 1 << j ) ; num = num ^ x ; } i ++ ; j -- ; } return num ; } let num = 4 ; document . write ( findMax ( num ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sum of first N natural numbers which are divisible by X or Y | Function to calculate the sum of numbers divisible by X or Y ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function sum ( $ N , $ X , $ Y ) { $ S1 ; $ S2 ; $ S3 ; $ S1 = floor ( ( ( int ) $ N \\/ $ X ) ) * ( 2 * $ X + ( int ) ( ( int ) $ N \\/ $ X - 1 ) * $ X ) \\/ 2 ; $ S2 = floor ( ( ( int ) $ N \\/ $ Y ) ) * ( 2 * $ Y + ( int ) ( ( int ) $ N \\/ $ Y - 1 ) * $ Y ) \\/ 2 ; $ S3 = floor ( ( ( int ) $ N \\/ ( $ X * $ Y ) ) ) * ( 2 * ( $ X * $ Y ) + ( ( int ) $ N \\/ ( $ X * $ Y ) - 1 ) * ( int ) ( $ X * $ Y ) ) \\/ 2 ; return ceil ( $ S1 + ( $ S2 - $ S3 ) ) ; } $ N = 14 ; $ X = 3 ; $ Y = 5 ; echo sum ( $ N , $ X , $ Y ) ; #This code is contributed by ajit.\\n? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Count words in a given string | C 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 tes above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#define OUT \\t0\\n#define IN \\t1\\nunsigned countWords ( char * str ) { int state = OUT ; unsigned wc = 0 ; while ( * str ) { if ( * str == ' ▁ ' * str == ' ' * str == ' \\t ' ) state = OUT ; else if ( state == OUT ) { state = IN ; ++ wc ; } ++ str ; } return wc ; } int main ( void ) { char str [ ] = \\\" One ▁ two \\t \\t three \\n \\t four \\t five ▁ \\\" ; printf ( \\\" No ▁ of ▁ words ▁ : ▁ % u \\\" , countWords ( str ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum steps to minimize n as per given condition | A tabulation based solution in Java ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static int getMinSteps ( int n ) { int [ ] dp = new int [ n + 1 ] ; dp [ 1 ] = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { int min = dp [ i - 1 ] ; if ( i % 2 == 0 ) { min = Math . min ( min , dp [ i \\/ 2 ] ) ; } if ( i % 3 == 0 ) { min = Math . min ( min , dp [ i \\/ 3 ] ) ; } dp [ i ] = min + 1 ; } return dp [ n ] ; } public static void main ( String [ ] args ) { int n = 14 ; System . out . print ( getMinSteps ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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\\\"\\nHow can the above be solved 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\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Angle between a chord and a tangent when angle in the alternate segment is given | C ++ program to find the angle between a chord and a tangent when angle in the alternate segment is given ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void anglechordtang ( int z ) { cout << \\\" The ▁ angle ▁ between ▁ tangent \\\" << \\\" ▁ and ▁ the ▁ chord ▁ is ▁ \\\" << z << \\\" ▁ degrees \\\" << endl ; } int main ( ) { int z = 48 ; anglechordtang ( z ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Subset Sum Problem in O ( sum ) space | Returns true if there exists a subset with given sum in arr [ ] ; The value of subset [ i % 2 ] [ j ] will be true if there exists a subset of sum j in arr [ 0 , 1 , ... . , i - 1 ] ; A subset with sum 0 is always possible ; If there exists no element no sum is possible ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function isSubsetSum ( $ arr , $ n , $ sum ) { $ subset [ 2 ] [ $ sum + 1 ] = array ( ) ; for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) { for ( $ j = 0 ; $ j <= $ sum ; $ j ++ ) { if ( $ j == 0 ) $ subset [ $ i % 2 ] [ $ j ] = true ; else if ( $ i == 0 ) $ subset [ $ i % 2 ] [ $ j ] = false ; else if ( $ arr [ $ i - 1 ] <= $ j ) $ subset [ $ i % 2 ] [ $ j ] = $ subset [ ( $ i + 1 ) % 2 ] [ $ j - $ arr [ $ i - 1 ] ] || $ subset [ ( $ i + 1 ) % 2 ] [ $ j ] ; else $ subset [ $ i % 2 ] [ $ j ] = $ subset [ ( $ i + 1 ) % 2 ] [ $ j ] ; } } return $ subset [ $ n % 2 ] [ $ sum ] ; } $ arr = array ( 6 , 2 , 5 ) ; $ sum = 7 ; $ n = sizeof ( $ arr ) ; if ( isSubsetSum ( $ arr , $ n , $ sum ) == true ) echo ( \\\" There ▁ exists ▁ a ▁ subset ▁ with ▁ given ▁ sum \\\" ) ; else echo ( \\\" No ▁ subset ▁ exists ▁ with ▁ given ▁ sum \\\" ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if a given array is sorted in Spiral manner or not | Java program to implement the above approach ; Function to check if the array is spirally sorted or not ; Stores start index of the array ; Stores end index of an array ; If arr [ start ] greater than arr [ end ] ; Update start ; If arr [ end ] greater than arr [ start ] ; Update end ; Driver code ; Function Call\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static boolean isSpiralSorted ( int [ ] arr , int n ) { int start = 0 ; int end = n - 1 ; while ( start < end ) { if ( arr [ start ] > arr [ end ] ) { return false ; } start ++ ; if ( arr [ end ] > arr [ start ] ) { return false ; } end -- ; } return true ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 10 , 14 , 20 , 18 , 12 , 5 } ; int N = arr . length ; if ( isSpiralSorted ( arr , N ) != false ) System . out . print ( \\\" YES \\\" ) ; else System . out . print ( \\\" NO \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 ] ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int bitwiseAndOdd ( int n ) { return 1 ; } 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\":\"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 ▁ minimum ▁ element ▁ is ▁ % d \\n \\\" , findMin ( arr1 , 0 , n1 - 1 ) ) ; int arr2 [ ] = { 1 , 2 , 3 , 4 } ; int n2 = sizeof ( arr2 ) \\/ sizeof ( arr2 [ 0 ] ) ; printf ( \\\" The ▁ minimum ▁ element ▁ is ▁ % d \\n \\\" , findMin ( arr2 , 0 , n2 - 1 ) ) ; int arr3 [ ] = { 1 } ; int n3 = sizeof ( arr3 ) \\/ sizeof ( arr3 [ 0 ] ) ; printf ( \\\" The ▁ minimum ▁ element ▁ is ▁ % d \\n \\\" , findMin ( arr3 , 0 , n3 - 1 ) ) ; int arr4 [ ] = { 1 , 2 } ; int n4 = sizeof ( arr4 ) \\/ sizeof ( arr4 [ 0 ] ) ; printf ( \\\" The ▁ minimum ▁ element ▁ is ▁ % d \\n \\\" , findMin ( arr4 , 0 , n4 - 1 ) ) ; int arr5 [ ] = { 2 , 1 } ; int n5 = sizeof ( arr5 ) \\/ sizeof ( arr5 [ 0 ] ) ; printf ( \\\" The ▁ minimum ▁ element ▁ is ▁ % 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 ▁ minimum ▁ element ▁ is ▁ % 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 ▁ minimum ▁ element ▁ is ▁ % 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 ▁ minimum ▁ element ▁ is ▁ % d \\n \\\" , findMin ( arr8 , 0 , n8 - 1 ) ) ; int arr9 [ ] = { 3 , 4 , 5 , 1 , 2 } ; int n9 = sizeof ( arr9 ) \\/ sizeof ( arr9 [ 0 ] ) ; printf ( \\\" The ▁ minimum ▁ element ▁ is ▁ % 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\":\"\\\"Split a number as sum of K numbers which are not divisible by K | Function to split into K parts and print them ; Print 1 K - 1 times ; Print N - K + 1 ; Print 1 K - 2 times ; Print 2 and N - K ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def printKParts ( N , K ) :\\n\\tif ( N % K == 0 ) :\\n\\t\\tfor i in range ( 1 , K ) :\\n\\t\\t\\tprint ( \\\"1 , ▁ \\\" ) ;\\n\\t\\tprint ( N - ( K - 1 ) , end = \\\" \\\" ) ;\\n\\telse :\\n\\t\\tif ( K == 2 ) :\\n\\t\\t\\tprint ( \\\" Not ▁ Possible \\\" , end = \\\" \\\" ) ;\\n\\t\\t\\treturn ;\\n\\tfor i in range ( 1 , K - 1 ) :\\n\\t\\tprint ( 1 , end = \\\" , ▁ \\\" ) ;\\n\\tprint ( 2 , \\\" , ▁ \\\" , ( N - K ) , end = \\\" \\\" ) ;\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 18 ;\\n\\tK = 5 ;\\n\\tprintKParts ( N , K ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\\"\\nSolution in C#:\",\"targets\":\"using System ; 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 ; } } Console . Write ( count + \\\" ▁ \\\" ) ; 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\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Divide a number into two parts such that sum of digits is maximum | Java implementation of above approach Returns sum of digits of x ; Returns sum of digits of x ; Returns closest number to x in terms of 9 's. ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int sumOfDigitsSingle ( int x ) { int ans = 0 ; while ( x != 0 ) { ans += x % 10 ; x \\/= 10 ; } return ans ; } static int closest ( int x ) { int ans = 0 ; while ( ans * 10 + 9 <= x ) ans = ans * 10 + 9 ; return ans ; } static int sumOfDigitsTwoParts ( int N ) { int A = closest ( N ) ; return sumOfDigitsSingle ( A ) + sumOfDigitsSingle ( N - A ) ; } public static void main ( String args [ ] ) { int N = 35 ; System . out . print ( sumOfDigitsTwoParts ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sum of even values and update queries on an array | Function to return the sum of even elements after updating value at given index ; Add given value to A [ index ] ; To store the sum of even elements ; If current element is even ; Function to print the result for every query ; Resultant vector that stores the result for every query ; Get sum of even elements after updating value at given index ; Store sum for each query ; Print the result for every query ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function EvenSum ( A , index , value ) { A [ index ] = A [ index ] + value ; var sum = 0 ; for ( var i = 0 ; i < A . length ; i ++ ) if ( A [ i ] % 2 == 0 ) sum = sum + A [ i ] ; return sum ; } function BalanceArray ( A , Q ) { var ANS = [ ] ; var i , sum ; for ( i = 0 ; i < Q . length ; i ++ ) { var index = Q [ i ] [ 0 ] ; var value = Q [ i ] [ 1 ] ; sum = EvenSum ( A , index , value ) ; ANS . push ( sum ) ; } for ( i = 0 ; i < ANS . length ; i ++ ) document . write ( ANS [ i ] + \\\" \\\" ) ; } var A = [ 1 , 2 , 3 , 4 ] ; var Q = [ [ 0 , 1 ] , [ 1 , - 3 ] , [ 0 , - 4 ] , [ 3 , 2 ] ] ; BalanceArray ( A , Q ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Pandigital number in a given base | Return true if n is pandigit else return false . ; Checking length is less than base ; Traversing each digit of the number . ; If digit is integer ; If digit is alphabet ; Checking hash array , if any index is unmarked . ; Driver Program\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function checkPandigital ( $ b , $ n ) { if ( strlen ( $ n ) < $ b ) return 0 ; $ hash = array ( ) ; for ( $ i = 0 ; $ i < $ b ; $ i ++ ) $ hash [ $ i ] = 0 ; for ( $ i = 0 ; $ i < strlen ( $ n ) ; $ i ++ ) { if ( $ n [ $ i ] >= '0' && $ n [ $ i ] <= '9' ) $ hash [ $ n [ $ i ] - '0' ] = 1 ; else if ( ord ( $ n [ $ i ] ) - ord ( ' A ' ) <= $ b - 11 ) $ hash [ ord ( $ n [ $ i ] ) - ord ( ' A ' ) + 10 ] = 1 ; } for ( $ i = 0 ; $ i < $ b ; $ i ++ ) if ( $ hash [ $ i ] == 0 ) return 0 ; return 1 ; } $ b = 13 ; $ n = \\\"1298450376ABC \\\" ; if ( checkPandigital ( $ b , $ n ) ) echo \\\" Yes \\\" ; else echo \\\" No \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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 program\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint fact ( int n ) { if ( n == 0 ) return 1 ; return n * fact ( n - 1 ) ; } int div ( int x ) { int ans = 0 ; for ( int i = 1 ; i <= x ; i ++ ) if ( x % i == 0 ) ans += i ; return ans ; } int sumFactDiv ( int n ) { return div ( fact ( n ) ) ; } int main ( ) { int n = 4 ; printf ( \\\" % d \\\" , sumFactDiv ( n ) ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all odd length palindromic numbers within the range [ L , R ] | Function that returns true if the given number is a palindrome ; Here we are generating a new number ( reverse_num ) by reversing the digits of original input number ; If the original input number ( num ) is equal to its reverse ( reverse_num ) then its palindrome else it is not . ; Function that returns true if the given number is of odd length ; Function to return the sum of all odd length palindromic numbers within the given range ; if number is palindrome and of odd length ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function isPalindrome ( $ num ) { $ reverse_num = 0 ; $ remainder ; $ temp ; $ temp = $ num ; while ( $ temp != 0 ) { $ remainder = $ temp % 10 ; $ reverse_num = $ reverse_num * 10 + $ remainder ; $ temp = ( int ) ( $ temp \\/ 10 ) ; } if ( $ reverse_num == $ num ) { return true ; } return false ; } function isOddLength ( $ num ) { $ count = 0 ; while ( $ num > 0 ) { $ num = ( int ) ( $ num \\/ 10 ) ; $ count ++ ; } if ( $ count % 2 != 0 ) { return true ; } return false ; } function sumOfAllPalindrome ( $ L , $ R ) { $ sum = 0 ; if ( $ L <= $ R ) for ( $ i = $ L ; $ i <= $ R ; $ i ++ ) { if ( isPalindrome ( $ i ) && isOddLength ( $ i ) ) { $ sum += $ i ; } } return $ sum ; } $ L = 110 ; $ R = 1130 ; echo sumOfAllPalindrome ( $ L , $ R ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Print all possible rotations of a given Array | C ++ program to print all possible rotations of the given array ; Global declaration of array ; Function to reverse array between indices s and e ; Function to generate all possible rotations of array ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int arr [ 10000 ] ; void reverse ( int arr [ ] , int s , int e ) { while ( s < e ) { int tem = arr [ s ] ; arr [ s ] = arr [ e ] ; arr [ e ] = tem ; s = s + 1 ; e = e - 1 ; } } void fun ( int arr [ ] , int k ) { int n = 4 - 1 ; int v = n - k ; if ( v >= 0 ) { reverse ( arr , 0 , v ) ; reverse ( arr , v + 1 , n ) ; reverse ( arr , 0 , n ) ; } } int main ( ) { arr [ 0 ] = 1 ; arr [ 1 ] = 2 ; arr [ 2 ] = 3 ; arr [ 3 ] = 4 ; for ( int i = 0 ; i < 4 ; i ++ ) { fun ( arr , i ) ; cout << ( \\\" [ \\\" ) ; for ( int j = 0 ; j < 4 ; j ++ ) { cout << ( arr [ j ] ) << \\\" , ▁ \\\" ; } cout << ( \\\" ] \\\" ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Cutting a Rod | DP | 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 php:\",\"targets\":\"< ? php function cutRod ( $ price , $ n ) { $ val = array ( ) ; $ val [ 0 ] = 0 ; $ i ; $ j ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ max_val = PHP_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 ] ; } $ arr = array ( 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 ) ; $ size = count ( $ arr ) ; echo \\\" Maximum ▁ Obtainable ▁ Value ▁ is ▁ \\\" , cutRod ( $ arr , $ size ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Icosikaioctagon or Icosioctagon Number | C program for above approach ; Finding the nth icosikaioctagonal Number ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nint icosikaioctagonalNum ( int n ) { return ( 26 * n * n - 24 * n ) \\/ 2 ; } int main ( ) { int n = 3 ; printf ( \\\"3rd ▁ icosikaioctagonal ▁ Number ▁ is ▁ = ▁ % d \\\" , icosikaioctagonalNum ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find the number of pairs such that their gcd is equals to 1 | Java program to find the number of pairs such that gcd equals to 1 ; Function to calculate least prime factor of each number ; If it is a prime number ; For all multiples which are not visited yet . ; Function to find the value of Mobius function for all the numbers from 1 to n ; If number is one ; If number has a squared prime factor ; Multiply - 1 with the previous number ; Function to find the number of pairs such that gcd equals to 1 ; To store maximum number ; To store frequency of each number ; Find frequency and maximum number ; To store number of pairs with gcd equals to 1 ; Traverse through the all possible elements ; Return the number of pairs ; Driver code ; Function call\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int N = 100050 ; static int [ ] lpf = new int [ N ] ; static int [ ] mobius = new int [ N ] ; static void least_prime_factor ( ) { for ( int i = 2 ; i < N ; i ++ ) if ( lpf [ i ] == 0 ) for ( int j = i ; j < N ; j += i ) if ( lpf [ j ] == 0 ) lpf [ j ] = i ; } static void Mobius ( ) { for ( int i = 1 ; i < N ; i ++ ) { if ( i == 1 ) mobius [ i ] = 1 ; else { if ( lpf [ i \\/ lpf [ i ] ] == lpf [ i ] ) mobius [ i ] = 0 ; else mobius [ i ] = - 1 * mobius [ i \\/ lpf [ i ] ] ; } } } static int gcd_pairs ( int a [ ] , int n ) { int maxi = 0 ; int [ ] fre = new int [ N ] ; for ( int i = 0 ; i < n ; i ++ ) { fre [ a [ i ] ] ++ ; maxi = Math . max ( a [ i ] , maxi ) ; } least_prime_factor ( ) ; Mobius ( ) ; int ans = 0 ; for ( int i = 1 ; i <= maxi ; i ++ ) { if ( mobius [ i ] == 0 ) continue ; int temp = 0 ; for ( int j = i ; j <= maxi ; j += i ) temp += fre [ j ] ; ans += temp * ( temp - 1 ) \\/ 2 * mobius [ i ] ; } return ans ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int n = a . length ; System . out . print ( gcd_pairs ( a , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count pairs from two sorted arrays whose sum is equal to a given value x | C # implementation to count pairs from both sorted arrays whose sum is equal to a given value ; function to count all pairs from both the sorted arrays whose sum is equal to a given value ; generating pairs from both the arrays ; if sum of pair is equal to ' x ' increment count ; required count of pairs ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int countPairs ( int [ ] arr1 , int [ ] arr2 , int m , int n , int x ) { int count = 0 ; for ( int i = 0 ; i < m ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ; return count ; } public static void Main ( ) { int [ ] arr1 = { 1 , 3 , 5 , 7 } ; int [ ] arr2 = { 2 , 3 , 5 , 8 } ; int m = arr1 . Length ; int n = arr2 . Length ; int x = 10 ; Console . WriteLine ( \\\" Count ▁ = ▁ \\\" + countPairs ( arr1 , arr2 , m , n , x ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Program to find height of a Trapezoid | C ++ program for the above approach ; Function to calculate height of the trapezoid ; Apply Heron 's formula ; Calculate the area ; Calculate height of trapezoid ; Print the height ; Driver Code ; Given a , b , p1 and p2\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void findHeight ( float p1 , float p2 , float b , float c ) { float a = max ( p1 , p2 ) - min ( p1 , p2 ) ; float s = ( a + b + c ) \\/ 2 ; float area = sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ; float height = ( area * 2 ) \\/ a ; cout << \\\" Height ▁ is : ▁ \\\" << height ; } int main ( ) { float p1 = 25 , p2 = 10 ; float a = 14 , b = 13 ; findHeight ( p1 , p2 , a , b ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if the number is balanced | C ++ program to check if a number is Balanced or not ; Function to check whether N is Balanced Number or not ; Calculating the Leftsum and rightSum simultaneously ; Typecasting each character to integer and adding the digit to respective sums ; Driver Code ; Function call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void BalancedNumber ( string s ) { int Leftsum = 0 ; int Rightsum = 0 ; for ( int i = 0 ; i < s . size ( ) \\/ 2 ; i ++ ) { Leftsum += int ( s [ i ] - '0' ) ; Rightsum += int ( s [ s . size ( ) - 1 - i ] - '0' ) ; } if ( Leftsum == Rightsum ) cout << \\\" Balanced \\\" << endl ; else cout << \\\" Not ▁ Balanced \\\" << endl ; } int main ( ) { string s = \\\"12321\\\" ; BalancedNumber ( s ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Puzzle | Program to find number of squares in a chessboard | Function to return count of squares ; ; A better way to write n * ( n + 1 ) * ( 2 n + 1 ) \\/ 6 ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"function countSquares ( n ) { return ( n * ( n + 1 ) \\/ 2 ) * ( 2 * n + 1 ) \\/ 3 ; } let n = 4 ; document . write ( \\\" Count ▁ of ▁ squares ▁ is ▁ \\\" + countSquares ( n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check whether the given number is Euclid Number or not | C # program to check Euclid Number ; Function to get the prime numbers ; 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 ; store all prime numbers to vector ' arr ' ; Function to check the number for Euclid Number ; Multiply next prime number and check if product + 1 = n holds or not ; Driver code ; Get the prime numbers ; Get n ; Check if n is Euclid Number ; Get n ; Check if n is Euclid Number\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static readonly int MAX = 10000 ; static List < int > arr = new List < int > ( ) ; static void SieveOfEratosthenes ( ) { bool [ ] prime = new bool [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p < MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i < MAX ; i += p ) prime [ i ] = false ; } } for ( int p = 2 ; p < MAX ; p ++ ) if ( prime [ p ] ) arr . Add ( p ) ; } static bool isEuclid ( long n ) { long product = 1 ; int i = 0 ; while ( product < n ) { product = product * arr [ i ] ; if ( product + 1 == n ) return true ; i ++ ; } return false ; } public static void Main ( String [ ] args ) { SieveOfEratosthenes ( ) ; long n = 31 ; if ( isEuclid ( n ) ) Console . WriteLine ( \\\" YES \\\" ) ; else Console . WriteLine ( \\\" NO \\\" ) ; n = 42 ; if ( isEuclid ( n ) ) 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\":\"\\\"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\":\"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\":\"\\\"How to check if a given array represents a Binary Heap ? | Returns true if arr [ i . . n - 1 ] represents a max - heap ; If a leaf node ; If an internal node and is greater than its children , and same is recursively true for the children ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def isHeap ( arr , i , n ) :\\n\\tif i >= int ( ( n - 2 ) \\/ 2 ) :\\n\\t\\treturn True\\n\\tif ( arr [ i ] >= arr [ 2 * i + 1 ] and arr [ i ] >= arr [ 2 * i + 2 ] and isHeap ( arr , 2 * i + 1 , n ) and isHeap ( arr , 2 * i + 2 , n ) ) :\\n\\t\\treturn True\\n\\treturn False\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 90 , 15 , 10 , 7 , 12 , 2 , 7 , 3 ]\\n\\tn = len ( arr ) - 1\\n\\tif isHeap ( arr , 0 , n ) :\\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\":\"\\\"Count frequencies of all elements in array in O ( 1 ) extra space and O ( n ) time | ; Function to find counts of all elements present in arr [ 0. . n - 1 ] . The array elements must be range from 1 to n ; Subtract 1 from every element so that the elements become in range from 0 to n - 1 ; Use every element arr [ i ] as index and add ' n ' to element present at arr [ i ] % n to keep track of count of occurrences of arr [ i ] ; To print counts , simply print the number of times n was added at index corresponding to every element ; Driver program to test above functions\\\"\\nSolution in C#:\",\"targets\":\"using System ; internal class CountFrequency { internal virtual void printfrequency ( int [ ] arr , int n ) { for ( int j = 0 ; j < n ; j ++ ) { arr [ j ] = arr [ j ] - 1 ; } for ( int i = 0 ; i < n ; i ++ ) { arr [ arr [ i ] % n ] = arr [ arr [ i ] % n ] + n ; } for ( int i = 0 ; i < n ; i ++ ) { Console . WriteLine ( i + 1 + \\\" - > \\\" + arr [ i ] \\/ n ) ; } } public static void Main ( string [ ] args ) { CountFrequency count = new CountFrequency ( ) ; int [ ] arr = new int [ ] { 2 , 3 , 3 , 2 , 5 } ; int n = arr . Length ; count . printfrequency ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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 | C # 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 C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int MAX = 10 ; static List < int > numToVec ( int N ) { List < int > digit = new List < int > ( ) ; while ( N != 0 ) { digit . Add ( N % 10 ) ; N = N \\/ 10 ; } if ( digit . Count == 0 ) digit . Add ( 0 ) ; digit . Reverse ( ) ; return digit ; } static int solve ( List < int > A , int B , int C ) { List < int > digit = new List < int > ( ) ; int d , d2 ; digit = numToVec ( C ) ; d = A . Count ; if ( B > digit . Count d == 0 ) return 0 ; else if ( B < digit . Count ) { if ( A [ 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 [ 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 [ i - 1 ] ] ; dp [ i ] = dp [ i - 1 ] * d ; if ( i == 1 && A [ 0 ] == 0 && B != 1 ) d2 = d2 - 1 ; if ( flag ) dp [ i ] += d2 ; flag = ( flag & ( lower [ digit [ i - 1 ] + 1 ] == lower [ digit [ i - 1 ] ] + 1 ) ) ; } return dp [ B ] ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 0 , 1 , 2 , 5 } ; List < int > A = new List < int > ( arr ) ; int N = 2 ; int k = 21 ; Console . WriteLine ( solve ( A , N , k ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Split first N natural numbers into two sets with minimum absolute difference of their sums | Function to split the first N natural numbers into two sets having minimum absolute difference of their sums ; Stores the sum of elements of set1 ; Stores the sum of elements of set2 ; Traverse first N natural numbers ; Check if sum of elements of set1 is less than or equal to sum of elements of set2 ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function minAbsDiff ( N ) { var sumSet1 = 0 ; var sumSet2 = 0 ; for ( i = N ; i > 0 ; i -- ) { if ( sumSet1 <= sumSet2 ) { sumSet1 += i ; } else { sumSet2 += i ; } } return Math . abs ( sumSet1 - sumSet2 ) ; } var N = 6 ; document . write ( minAbsDiff ( N ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Bitwise AND of sub | C ++ implementation of the approach ; Function to return the minimum possible value of | K - X | where X is the bitwise AND of the elements of some sub - array ; Check all possible sub - arrays ; Find the overall minimum ; No need to perform more AND operations as | k - X | will increase ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int closetAND ( int arr [ ] , int n , int k ) { int ans = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { int X = arr [ i ] ; for ( int j = i ; j < n ; j ++ ) { X &= arr [ j ] ; ans = min ( ans , abs ( k - X ) ) ; if ( X <= k ) break ; } } return ans ; } int main ( ) { int arr [ ] = { 4 , 7 , 10 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int k = 2 ; cout << closetAND ( arr , n , k ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Distinct adjacent elements in a binary array | Python3 implementation of the above approach ; if array has only one element , return 1 ; For first element compare with only next element ; For remaining elements compare with both prev and next elements ; For last element compare with only prev element ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def distinct ( arr ) :\\n\\tcount = 0\\n\\tif len ( arr ) == 1 :\\n\\t\\treturn 1\\n\\tfor i in range ( 0 , len ( arr ) - 1 ) :\\n\\t\\tif ( i == 0 ) :\\n\\t\\t\\tif ( arr [ i ] != arr [ i + 1 ] ) :\\n\\t\\t\\t\\tcount += 1\\n\\t\\telif ( i > 0 & i < len ( arr ) - 1 ) :\\n\\t\\t\\tif ( arr [ i ] != arr [ i + 1 ] or arr [ i ] != arr [ i - 1 ] ) :\\n\\t\\t\\t\\tcount += 1\\n\\tif ( arr [ len ( arr ) - 1 ] != arr [ len ( arr ) - 2 ] ) :\\n\\t\\tcount += 1\\n\\treturn count\\narr = [ 0 , 0 , 0 , 0 , 0 , 1 , 0 ]\\nprint ( distinct ( arr ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\":\"\\\"Count of subarrays having sum equal to its length | Set 2 | Java program for the above approach ; 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 ; Driver Code ; Given array arr [ ] ; Size of array ; Function Call\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void countOfSubarray ( int arr [ ] , int N ) { Map < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; int answer = 0 ; int sum = 0 ; if ( mp . get ( 1 ) != null ) mp . put ( 1 , mp . get ( 1 ) + 1 ) ; else mp . put ( 1 , 1 ) ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; if ( mp . get ( sum - i ) != null ) answer += mp . get ( sum - i ) ; if ( mp . get ( sum - i ) != null ) mp . put ( sum - i , mp . get ( sum - i ) + 1 ) ; else mp . put ( sum - i , 1 ) ; } System . out . print ( answer ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 0 , 2 , 1 , 2 , - 2 , 2 , 4 } ; int N = arr . length ; countOfSubarray ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Seating arrangement of N boys sitting around a round table such that two particular boys sit together | C # implementation of the approach ; Function to return the total count of ways ; Find ( n - 1 ) factorial ; Return ( n - 1 ) ! * 2 ! ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int Total_Ways ( int n ) { int fac = 1 ; for ( int i = 2 ; i <= n - 1 ; i ++ ) { fac = fac * i ; } return ( fac * 2 ) ; } static public void Main ( ) { int n = 5 ; Console . Write ( Total_Ways ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Case | Function to return the sorted string ; Vectors to store the lowercase and uppercase characters ; Sort both the vectors ; If current character is lowercase then pick the lowercase character from the sorted list ; Else pick the uppercase character ; Return the sorted string ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function getSortedString ( s , n ) { var v1 = [ ] ; var v2 = [ ] ; var i = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( s [ i ] . charCodeAt ( 0 ) > \\\" \\\" . charCodeAt ( 0 ) && s [ i ] . charCodeAt ( 0 ) <= \\\" \\\" . charCodeAt ( 0 ) ) v1 . push ( s [ i ] ) ; if ( s [ i ] . charCodeAt ( 0 ) > \\\" \\\" . charCodeAt ( 0 ) && s [ i ] . charCodeAt ( 0 ) <= \\\" \\\" . charCodeAt ( 0 ) ) v2 . push ( s [ i ] ) ; } console . log ( v1 ) ; v1 . sort ( ) ; v2 . sort ( ) ; var j = 0 ; i = 0 ; for ( var k = 0 ; k < n ; k ++ ) { if ( s [ k ] . charCodeAt ( 0 ) > \\\" \\\" . charCodeAt ( 0 ) && s [ k ] . charCodeAt ( 0 ) <= \\\" \\\" . charCodeAt ( 0 ) ) { s [ k ] = v1 [ i ] ; ++ i ; } else if ( s [ k ] . charCodeAt ( 0 ) > \\\" \\\" . charCodeAt ( 0 ) && s [ k ] . charCodeAt ( 0 ) <= \\\" \\\" . charCodeAt ( 0 ) ) { s [ k ] = v2 [ j ] ; ++ j ; } } return s . join ( \\\" \\\" ) ; } var s = \\\" \\\" ; var n = s . length ; document . write ( getSortedString ( s . split ( \\\" \\\" ) , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Number of Triangles in an Undirected Graph | A C ++ program for finding number of triangles in an Undirected Graph . The program is for adjacency matrix representation of the graph ; Number of vertices in the graph ; Utility function for matrix multiplication ; Utility function to calculate trace of a matrix ( sum ofdiagnonal elements ) ; Utility function for calculating number of triangles in graph ; To Store graph ^ 2 ; To Store graph ^ 3 ; Initialising aux matrices with 0 ; aux2 is graph ^ 2 now printMatrix ( aux2 ) ; ; after this multiplication aux3 is graph ^ 3 printMatrix ( aux3 ) ; ; driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; #define V 4\\nvoid multiply ( int A [ ] [ V ] , int B [ ] [ V ] , int C [ ] [ V ] ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { C [ i ] [ j ] = 0 ; for ( int k = 0 ; k < V ; k ++ ) C [ i ] [ j ] += A [ i ] [ k ] * B [ k ] [ j ] ; } } } int getTrace ( int graph [ ] [ V ] ) { int trace = 0 ; for ( int i = 0 ; i < V ; i ++ ) trace += graph [ i ] [ i ] ; return trace ; } int triangleInGraph ( int graph [ ] [ V ] ) { int aux2 [ V ] [ V ] ; int aux3 [ V ] [ V ] ; for ( int i = 0 ; i < V ; ++ i ) for ( int j = 0 ; j < V ; ++ j ) aux2 [ i ] [ j ] = aux3 [ i ] [ j ] = 0 ; multiply ( graph , graph , aux2 ) ; multiply ( graph , aux2 , aux3 ) ; int trace = getTrace ( aux3 ) ; return trace \\/ 6 ; } int main ( ) { int graph [ V ] [ V ] = { { 0 , 1 , 1 , 0 } , { 1 , 0 , 1 , 1 } , { 1 , 1 , 0 , 1 } , { 0 , 1 , 1 , 0 } } ; printf ( \\\" Total ▁ number ▁ of ▁ Triangle ▁ in ▁ Graph ▁ : ▁ % d \\n \\\" , triangleInGraph ( graph ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Megagon number | C ++ implementation for the above approach ; Function to find the nth Megagon Number ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int MegagonNum ( int n ) { return ( 999998 * n * n - 999996 * n ) \\/ 2 ; } int main ( ) { int n = 3 ; cout << MegagonNum ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Queries to count characters having odd frequency in a range [ L , R ] | C ++ Program to implement the above problem ; Function to print the number of characters having odd frequencies for each query ; A function to construct the arr [ ] and prefix [ ] ; Stores array length ; Stores the unique powers of 2 associated to each character ; Prefix array to store the XOR values from array elements ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void queryResult ( int prefix [ ] , pair < int , int > Q ) { int l = Q . first ; int r = Q . second ; if ( l == 0 ) { int xorval = prefix [ r ] ; cout << __builtin_popcount ( xorval ) << endl ; } else { int xorval = prefix [ r ] ^ prefix [ l - 1 ] ; cout << __builtin_popcount ( xorval ) << endl ; } } void calculateCount ( string S , pair < int , int > Q [ ] , int m ) { int n = S . length ( ) ; int arr [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = ( 1 << ( S [ i ] - ' a ' ) ) ; } int prefix [ n ] ; int x = 0 ; for ( int i = 0 ; i < n ; i ++ ) { x ^= arr [ i ] ; prefix [ i ] = x ; } for ( int i = 0 ; i < m ; i ++ ) { queryResult ( prefix , Q [ i ] ) ; } } int main ( ) { string S = \\\" geeksforgeeks \\\" ; pair < int , int > Q [ ] = { { 2 , 4 } , { 0 , 3 } , { 0 , 12 } } ; calculateCount ( S , Q , 3 ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count pairs from an array with absolute difference not less than the minimum element in the pair | Function to find the number of pairs ( i , j ) such that abs ( a [ i ] - a [ j ] ) is at least the minimum of ( a [ i ] , a [ j ] ) ; Stores the resultant count of pairs ; Iterate over the range [ 0 , n ] ; Iterate from arr [ i ] - ( i % arr [ i ] ) till n with an increment of arr [ i ] ; Count the possible pairs ; Return the total count ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def getPairsCount ( arr , n ) :\\n\\tcount = 0\\n\\tfor i in range ( n ) :\\n\\t\\tfor j in range ( arr [ i ] - ( i % arr [ i ] ) , n , arr [ i ] ) :\\n\\t\\t\\tif ( i < j and abs ( arr [ i ] - arr [ j ] ) >= min ( arr [ i ] , arr [ j ] ) ) :\\n\\t\\t\\t\\tcount += 1\\n\\treturn count\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 1 , 2 , 2 , 3 ]\\n\\tN = len ( arr )\\n\\tprint ( getPairsCount ( arr , N ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\":\"\\\"Count integers up to N which can be represented as sum of two or more consecutive numbers | C ++ Program to implement the above approach ; Function to check if the number N can be expressed as sum of 2 or more consecutive numbers or not ; Function to count integers in the range [ 1 , N ] that can be expressed as sum of 2 or more consecutive numbers ; Stores the required count ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool isPossible ( int N ) { return ( ( N & ( N - 1 ) ) && N ) ; } void countElements ( int N ) { int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( isPossible ( i ) ) count ++ ; } cout << count ; } int main ( ) { int N = 15 ; countElements ( N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Area of Incircle of a Right Angled Triangle | C program to find the area of incircle of right angled triangle ; Function to find area of incircle ; Driver code\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#define PI 3.14159265\\nfloat area_inscribed ( float P , float B , float H ) { return ( ( P + B - H ) * ( P + B - H ) * ( PI \\/ 4 ) ) ; } int main ( ) { float P = 3 , B = 4 , H = 5 ; printf ( \\\" % f \\\" , area_inscribed ( P , B , H ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-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 ▁ found ▁ between ▁ indexes ▁ % d ▁ and ▁ % d \\\" , start , i - 1 ) ; return 1 ; } if ( i < n ) curr_sum = curr_sum + arr [ i ] ; } printf ( \\\" No ▁ subarray ▁ 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\":\"\\\"Find minimum area of rectangle with given set of coordinates | C ++ Implementation of above approach ; function to find minimum area of Rectangle ; creating empty columns ; fill columns with coordinates ; check if rectangle can be formed ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int minAreaRect ( vector < vector < int > > A ) { map < int , vector < int > > columns ; for ( auto i : A ) columns [ i [ 0 ] ] . push_back ( i [ 1 ] ) ; map < pair < int , int > , int > lastx ; int ans = INT_MAX ; for ( auto x : columns ) { vector < int > column = x . second ; sort ( column . begin ( ) , column . end ( ) ) ; for ( int j = 0 ; j < column . size ( ) ; j ++ ) { for ( int i = 0 ; i < j ; i ++ ) { int y1 = column [ i ] ; if ( lastx . find ( { y1 , column [ j ] } ) != lastx . end ( ) ) { ans = min ( ans , ( x . first - lastx [ { y1 , column [ j ] } ] ) * ( column [ j ] - column [ i ] ) ) ; } lastx [ { y1 , column [ j ] } ] = x . first ; } } } if ( ans < INT_MAX ) return ans ; else return 0 ; } int main ( ) { vector < vector < int > > A = { { 1 , 1 } , { 1 , 3 } , { 3 , 1 } , { 3 , 3 } , { 2 , 2 } } ; cout << ( minAreaRect ( A ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximize the rightmost element of an array in k operations in Linear Time | Function to calculate maximum value of Rightmost element ; Calculating maximum value of Rightmost element ; Checking if arr [ i ] is operationable ; Performing operation of i - th element ; Decreasing the value of k by 1 ; Printing rightmost element ; Given Input ; Function Call\\\"\\nSolution in Python:\",\"targets\":\"def maxRightmostElement ( N , k , p , arr ) :\\n\\twhile ( k ) :\\n\\t\\tfor i in range ( N - 2 , - 1 , - 1 ) :\\n\\t\\t\\tif ( arr [ i ] >= p ) :\\n\\t\\t\\t\\tarr [ i ] = arr [ i ] - p\\n\\t\\t\\t\\tarr [ i + 1 ] = arr [ i + 1 ] + p\\n\\t\\t\\t\\tbreak\\n\\t\\tk = k - 1\\n\\tprint ( arr [ N - 1 ] )\\nN = 4\\np = 2\\nk = 5\\narr = [ 3 , 8 , 1 , 4 ]\\nmaxRightmostElement ( N , k , p , arr )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"First and Last Three Bits | Function to print the first and last 3 bits equivalent decimal number ; Number formed from last three bits ; Let us get first three bits in n ; Number formed from first three bits ; Printing result ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function binToDecimal3 ( $ n ) { $ last_3 = ( ( $ n & 4 ) + ( $ n & 2 ) + ( $ n & 1 ) ) ; $ n = $ n >> 3 ; while ( $ n > 7 ) $ n = $ n >> 1 ; $ first_3 = ( ( $ n & 4 ) + ( $ n & 2 ) + ( $ n & 1 ) ) ; echo ( $ first_3 ) ; echo ( \\\" ▁ \\\" ) ; echo ( $ last_3 ) ; } $ n = 86 ; binToDecimal3 ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if a large number is divisible by 8 or not | Function to find that number divisible by 8 or not ; Empty string ; If there is single digit ; If there is double digit ; If number formed by last three digits is divisible by 8. ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function check ( $ str ) { $ n = strlen ( $ str ) ; if ( $ n == 0 ) return false ; if ( $ n == 1 ) return ( ( $ str [ 0 ] - '0' ) % 8 == 0 ) ; if ( $ n == 2 ) return ( ( ( $ str [ $ n - 2 ] - '0' ) * 10 + ( $ str [ $ n - 1 ] - '0' ) ) % 8 == 0 ) ; $ last = $ str [ $ n - 1 ] - '0' ; $ second_last = $ str [ $ n - 2 ] - '0' ; $ third_last = $ str [ $ n - 3 ] - '0' ; return ( ( $ third_last * 100 + $ second_last * 10 + $ last ) % 8 == 0 ) ; } $ str = \\\"76952\\\" ; $ x = check ( $ str ) ? \\\" Yes \\\" : \\\" No ▁ \\\" ; echo ( $ x ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"Word Wrap Problem | DP | A Dynamic programming solution for Word Wrap Problem ; A utility function to print the solution ; l [ ] represents lengths of different words in input sequence . For example , l [ ] = { 3 , 2 , 2 , 5 } is for a sentence like \\\" aaa ▁ bb ▁ cc ▁ ddddd \\\" . n is size of l [ ] and M is line width ( maximum no . of characters that can fit in a line ) ; For simplicity , 1 extra space is used in all below arrays extras [ i ] [ j ] will have number of extra spaces if words from i to j are put in a single line ; lc [ i ] [ j ] will have cost of a line which has words from i to j ; c [ i ] will have total cost of optimal arrangement of words from 1 to i ; p [ ] is used to print the solution . ; calculate extra spaces in a single line . The value extra [ i ] [ j ] indicates extra spaces if words from word number i to j are placed in a single line ; Calculate line cost corresponding to the above calculated extra spaces . The value lc [ i ] [ j ] indicates cost of putting words from word number i to j in a single line ; Calculate minimum cost and find minimum cost arrangement . The value c [ j ] indicates optimized cost to arrange words from word number 1 to j . ; Driver program to test above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\n#define INF INT_MAX\\nint printSolution ( int p [ ] , int n ) ; int printSolution ( int p [ ] , int n ) { int k ; if ( p [ n ] == 1 ) k = 1 ; else k = printSolution ( p , p [ n ] - 1 ) + 1 ; printf ( \\\" Line ▁ number ▁ % d : ▁ From ▁ word ▁ no . ▁ % d ▁ to ▁ % d ▁ \\n \\\" , k , p [ n ] , n ) ; return k ; } void solveWordWrap ( int l [ ] , int n , int M ) { int extras [ n + 1 ] [ n + 1 ] ; int lc [ n + 1 ] [ n + 1 ] ; int c [ n + 1 ] ; int p [ n + 1 ] ; int i , j ; for ( i = 1 ; i <= n ; i ++ ) { extras [ i ] [ i ] = M - l [ i - 1 ] ; for ( j = i + 1 ; j <= n ; j ++ ) extras [ i ] [ j ] = extras [ i ] [ j - 1 ] - l [ j - 1 ] - 1 ; } for ( i = 1 ; i <= n ; i ++ ) { for ( j = i ; j <= n ; j ++ ) { if ( extras [ i ] [ j ] < 0 ) lc [ i ] [ j ] = INF ; else if ( j == n && extras [ i ] [ j ] >= 0 ) lc [ i ] [ j ] = 0 ; else lc [ i ] [ j ] = extras [ i ] [ j ] * extras [ i ] [ j ] ; } } c [ 0 ] = 0 ; for ( j = 1 ; j <= n ; j ++ ) { c [ j ] = INF ; for ( i = 1 ; i <= j ; i ++ ) { if ( c [ i - 1 ] != INF && lc [ i ] [ j ] != INF && ( c [ i - 1 ] + lc [ i ] [ j ] < c [ j ] ) ) { c [ j ] = c [ i - 1 ] + lc [ i ] [ j ] ; p [ j ] = i ; } } } printSolution ( p , n ) ; } int main ( ) { int l [ ] = { 3 , 2 , 2 , 5 } ; int n = sizeof ( l ) \\/ sizeof ( l [ 0 ] ) ; int M = 6 ; solveWordWrap ( l , n , M ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find average of two numbers using bit operation | C # implementation of the approach ; Function to return the average of x and y using bit operations ; Calculate the average Floor value of ( x + y ) \\/ 2 ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int getAverage ( int x , int y ) { int avg = ( x & y ) + ( ( x ^ y ) >> 1 ) ; return avg ; } public static void Main ( ) { int x = 10 , y = 9 ; Console . WriteLine ( getAverage ( x , y ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Nth non | Java program to find n - th non - square number . ; function to find the nth Non - Square Number ; conversion from int to long double is necessary in order to preserve decimal places after square root . ; calculating the result ; Driver code ; initializing the term number ; Print the result\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; import java . util . * ; import java . lang . * ; class GFG { static int findNthNonSquare ( int n ) { double x = ( double ) n ; double ans = x + Math . floor ( 0.5 + Math . sqrt ( x ) ) ; return ( int ) ans ; } public static void main ( String [ ] args ) { int n = 16 ; System . out . print ( \\\" The ▁ \\\" + n + \\\" th ▁ Non - Square ▁ number ▁ is ▁ \\\" ) ; System . out . print ( findNthNonSquare ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Lexicographically largest prime path from top | C ++ implementation of above approach ; Depth First Search ; Return if cell contain non prime number or obstacle , or going out of matrix or already visited the cell or already found the lexicographical largest path ; marking cell is already visited ; storing the lexicographical largest path index ; if reached the end of the matrix ; updating the final number of steps in lexicographical largest path ; moving diagonal ( trying lexicographical largest path ) ; moving cell right to current cell ; moving cell down to current cell . ; Print lexicographical largest prime path ; to count the number of step in lexicographical largest prime path ; to store the lexicographical largest prime path index ; to mark if the cell is already traversed or not ; traversing by DFS ; printing the lexicographical largest prime path ; Return the number of prime path in ther matrix . ; for each cell ; If on the top row or leftmost column , there is no path there . ; If non prime number ; Finding the matrix mapping by considering non prime number as obstacle and prime number be valid path . ; Sieve ; If prime ; if non prime ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; #define MAX 105\\nvoid sieve ( int prime [ ] ) { for ( int i = 2 ; i * i <= MAX ; i ++ ) { if ( prime [ i ] == 0 ) { for ( int j = i * i ; j <= MAX ; j += i ) prime [ j ] = 1 ; } } } void dfs ( int i , int j , int k , int * q , int n , int m , int mappedMatrix [ ] [ MAX ] , int mark [ ] [ MAX ] , pair < int , int > ans [ ] ) { if ( mappedMatrix [ i ] [ j ] == 0 || i > n || j > m || mark [ i ] [ j ] || ( * q ) ) return ; mark [ i ] [ j ] = 1 ; ans [ k ] = make_pair ( i , j ) ; if ( i == n && j == m ) { ( * q ) = k ; return ; } dfs ( i + 1 , j + 1 , k + 1 , q , n , m , mappedMatrix , mark , ans ) ; dfs ( i + 1 , j , k + 1 , q , n , m , mappedMatrix , mark , ans ) ; dfs ( i , j + 1 , k + 1 , q , n , m , mappedMatrix , mark , ans ) ; } void lexicographicalPath ( int n , int m , int mappedMatrix [ ] [ MAX ] ) { int q = 0 ; pair < int , int > ans [ MAX ] ; int mark [ MAX ] [ MAX ] ; dfs ( 1 , 1 , 1 , & q , n , m , mappedMatrix , mark , ans ) ; for ( int i = 1 ; i <= q ; i ++ ) cout << ans [ i ] . first << \\\" ▁ \\\" << ans [ i ] . second << \\\" \\n \\\" ; } void countPrimePath ( int mappedMatrix [ ] [ MAX ] , int n , int m ) { int dp [ MAX ] [ MAX ] = { 0 } ; dp [ 1 ] [ 1 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { if ( i == 1 && j == 1 ) continue ; dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ) ; if ( mappedMatrix [ i ] [ j ] == 0 ) dp [ i ] [ j ] = 0 ; } } cout << dp [ n ] [ m ] << \\\" \\n \\\" ; } void preprocessMatrix ( int mappedMatrix [ ] [ MAX ] , int a [ ] [ MAX ] , int n , int m ) { int prime [ MAX ] ; sieve ( prime ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( prime [ a [ i ] [ j ] ] == 0 ) mappedMatrix [ i + 1 ] [ j + 1 ] = 1 ; else mappedMatrix [ i + 1 ] [ j + 1 ] = 0 ; } } } int main ( ) { int n = 3 ; int m = 3 ; int a [ MAX ] [ MAX ] = { { 2 , 3 , 7 } , { 5 , 4 , 2 } , { 3 , 7 , 11 } } ; int mappedMatrix [ MAX ] [ MAX ] = { 0 } ; preprocessMatrix ( mappedMatrix , a , n...\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Longest alternating sub | C ++ program to calculate longest alternating sub - array for each index elements ; Function to calculate alternating sub - array for each index of array elements ; Initialize the base state of len [ ] ; Calculating value for each element ; If both elements are different then add 1 to next len [ i + 1 ] ; else initialize to 1 ; Print lengths of binary subarrays . ; Driver program\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void alternateSubarray ( bool arr [ ] , int n ) { int len [ n ] ; len [ n - 1 ] = 1 ; for ( int i = n - 2 ; i >= 0 ; -- i ) { if ( arr [ i ] ^ arr [ i + 1 ] == 1 ) len [ i ] = len [ i + 1 ] + 1 ; else len [ i ] = 1 ; } for ( int i = 0 ; i < n ; ++ i ) cout << len [ i ] << \\\" ▁ \\\" ; } int main ( ) { bool arr [ ] = { 1 , 0 , 1 , 0 , 0 , 1 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; alternateSubarray ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all odd length palindromic numbers within the range [ L , R ] | Java program to find the sum of all odd length palindromic numbers within the given range ; Function that returns true if the given number is a palindrome ; Here we are generating a new number ( reverse_num ) * by reversing the digits of original input number ; If the original input number ( num ) is equal to * to its reverse ( reverse_num ) then its palindrome * else it is not . ; Function that returns true if the given number is of odd length ; Function to return the sum of all odd length palindromic numbers within the given range ; if number is palindrome and of odd length ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static boolean isPalindrome ( int num ) { int reverse_num = 0 , remainder , temp ; temp = num ; while ( temp != 0 ) { remainder = temp % 10 ; reverse_num = reverse_num * 10 + remainder ; temp \\/= 10 ; } if ( reverse_num == num ) { return true ; } return false ; } static boolean isOddLength ( int num ) { int count = 0 ; while ( num > 0 ) { num \\/= 10 ; count ++ ; } if ( count % 2 != 0 ) { return true ; } return false ; } static long sumOfAllPalindrome ( int L , int R ) { long sum = 0 ; if ( L <= R ) for ( int i = L ; i <= R ; i ++ ) { if ( isPalindrome ( i ) && isOddLength ( i ) ) { sum += i ; } } return sum ; } public static void main ( String [ ] args ) { int L = 110 , R = 1130 ; System . out . println ( sumOfAllPalindrome ( L , R ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find the number of Chicks in a Zoo at Nth day | C # implementation of the approach ; Function to return the number of chicks on the nth day ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int getChicks ( int n ) { int chicks = ( int ) Math . Pow ( 3 , n - 1 ) ; return chicks ; } public static void Main ( ) { int n = 3 ; Console . WriteLine ( getChicks ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check horizontal and vertical symmetry in binary matrix | Java 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 ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; public class GFG { static void checkHV ( int [ ] [ ] arr , int N , int M ) { boolean horizontal = true ; boolean 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 ] ) { horizontal = false ; break ; } } } if ( ! horizontal && ! vertical ) System . out . println ( \\\" NO \\\" ) ; else if ( horizontal && ! vertical ) System . out . println ( \\\" HORIZONTAL \\\" ) ; else if ( vertical && ! horizontal ) System . out . println ( \\\" VERTICAL \\\" ) ; else System . out . println ( \\\" BOTH \\\" ) ; } static public void main ( String [ ] args ) { int [ ] [ ] mat = { { 1 , 0 , 1 } , { 0 , 0 , 0 } , { 1 , 0 , 1 } } ; checkHV ( mat , 3 , 3 ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Form minimum number from given sequence | Prints the minimum number that can be formed from input sequence of I ' s ▁ and ▁ D ' s ; Initialize current_max ( to make sure that we don 't use repeated character ; Initialize last_entry ( Keeps track for last printed digit ) ; Iterate over input array ; Initialize ' noOfNextD ' to get count of next D 's available ; If letter is ' I ' Calculate number of next consecutive D 's available ; If ' I ' is first letter , print incremented sequence from 1 ; Set max digit reached ; If not first letter Get next digit to print ; Print digit for I ; For all next consecutive ' D ' print decremented sequence ; If letter is 'D ; If ' D ' is first letter in sequence Find number of Next D 's available ; Calculate first digit to print based on number of consecutive D 's ; Print twice for the first time ; Store last entry ; If current ' D ' is not first letter Decrement last_entry ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def PrintMinNumberForPattern ( arr ) :\\n\\tcurr_max = 0\\n\\tlast_entry = 0\\n\\ti = 0\\n\\twhile i < len ( arr ) :\\n\\t\\tnoOfNextD = 0\\n\\t\\tif arr [ i ] == \\\" I \\\" :\\n\\t\\t\\tj = i + 1\\n\\t\\t\\twhile j < len ( arr ) and arr [ j ] == \\\" D \\\" :\\n\\t\\t\\t\\tnoOfNextD += 1\\n\\t\\t\\t\\tj += 1\\n\\t\\t\\tif i == 0 :\\n\\t\\t\\t\\tcurr_max = noOfNextD + 2\\n\\t\\t\\t\\tlast_entry += 1\\n\\t\\t\\t\\tprint ( \\\" \\\" , last_entry , end = \\\" \\\" )\\n\\t\\t\\t\\tprint ( \\\" \\\" , curr_max , end = \\\" \\\" )\\n\\t\\t\\t\\tlast_entry = curr_max\\n\\t\\t\\telse :\\n\\t\\t\\t\\tcurr_max += noOfNextD + 1\\n\\t\\t\\t\\tlast_entry = curr_max\\n\\t\\t\\t\\tprint ( \\\" \\\" , last_entry , end = \\\" \\\" )\\n\\t\\t\\tfor k in range ( noOfNextD ) :\\n\\t\\t\\t\\tlast_entry -= 1\\n\\t\\t\\t\\tprint ( \\\" \\\" , last_entry , end = \\\" \\\" )\\n\\t\\t\\t\\ti += 1\\n\\t\\telif arr [ i ] == \\\" D \\\" :\\n\\t\\t\\tif i == 0 :\\n\\t\\t\\t\\tj = i + 1\\n\\t\\t\\t\\twhile j < len ( arr ) and arr [ j ] == \\\" D \\\" :\\n\\t\\t\\t\\t\\tnoOfNextD += 1\\n\\t\\t\\t\\t\\tj += 1\\n\\t\\t\\t\\tcurr_max = noOfNextD + 2\\n\\t\\t\\t\\tprint ( \\\" \\\" , curr_max , curr_max - 1 , end = \\\" \\\" )\\n\\t\\t\\t\\tlast_entry = curr_max - 1\\n\\t\\t\\telse :\\n\\t\\t\\t\\tprint ( \\\" \\\" , last_entry - 1 , end = \\\" \\\" )\\n\\t\\t\\t\\tlast_entry -= 1\\n\\t\\ti += 1\\n\\tprint ( )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tPrintMinNumberForPattern ( \\\" IDID \\\" )\\n\\tPrintMinNumberForPattern ( \\\" I \\\" )\\n\\tPrintMinNumberForPattern ( \\\" DD \\\" )\\n\\tPrintMinNumberForPattern ( \\\" II \\\" )\\n\\tPrintMinNumberForPattern ( \\\" DIDI \\\" )\\n\\tPrintMinNumberForPattern ( \\\" IIDDD \\\" )\\n\\tPrintMinNumberForPattern ( \\\" DDIDDIID \\\" )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\":\"\\\"Dynamic Programming | Returns true if there is a subset of set [ ] with sun 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 botton up manner ; print table ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function isSubsetSum ( $ set , $ n , $ sum ) { $ subset = array ( array ( ) ) ; for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) $ subset [ $ i ] [ 0 ] = true ; for ( $ i = 1 ; $ i <= $ sum ; $ i ++ ) $ subset [ 0 ] [ $ i ] = false ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { for ( $ j = 1 ; $ j <= $ sum ; $ j ++ ) { if ( $ j < $ set [ $ i - 1 ] ) $ subset [ $ i ] [ $ j ] = $ subset [ $ i - 1 ] [ $ j ] ; if ( $ j >= $ set [ $ i - 1 ] ) $ subset [ $ i ] [ $ j ] = $ subset [ $ i - 1 ] [ $ j ] || $ subset [ $ i - 1 ] [ $ j - $ set [ $ i - 1 ] ] ; } } for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= sum ; j ++ ) printf ( \\\" % 4d \\\" , subset [ i ] [ j ] ) ; printf ( \\\" n \\\" ) ; } return $ subset [ $ n ] [ $ sum ] ; } $ set = array ( 3 , 34 , 4 , 12 , 5 , 2 ) ; $ sum = 9 ; $ n = count ( $ set ) ; if ( isSubsetSum ( $ set , $ n , $ sum ) == true ) echo \\\" Found ▁ a ▁ subset ▁ with ▁ given ▁ sum \\\" ; else echo \\\" No ▁ subset ▁ with ▁ given ▁ sum \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum steps required to reach the end of a matrix | Set 2 | Javascript 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\\\"\\nHow can the above be solved in JS?\",\"targets\":\"var n = 3 ; function minSteps ( arr ) { var v = Array . from ( Array ( n ) , ( ) => Array ( n ) . fill ( 0 ) ) ; var q = [ ] ; q . push ( [ 0 , 0 ] ) ; var depth = 0 ; while ( q . length != 0 ) { var x = q . length ; while ( x -- ) { var y = q [ 0 ] ; var i = y [ 0 ] , j = y [ 1 ] ; q . shift ( ) ; if ( v [ i ] [ j ] ) continue ; if ( i == n - 1 && j == n - 1 ) return depth ; v [ i ] [ j ] = 1 ; if ( i + arr [ i ] [ j ] < n ) q . push ( [ i + arr [ i ] [ j ] , j ] ) ; if ( j + arr [ i ] [ j ] < n ) q . push ( [ i , j + arr [ i ] [ j ] ] ) ; } depth ++ ; } return - 1 ; } var arr = [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ; document . write ( minSteps ( arr ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sort the array in a given index range | Function to sort the elements of the array from index a to index b ; Variables to store start and end of the index range ; Temporary array ; Sort the temporary array ; Modifying original array with temporary array elements ; Print the modified array ; Driver code ; length of the array\\\"\\nSolution in Javascript:\",\"targets\":\"function partSort ( arr , N , a , b ) { let l = Math . min ( a , b ) ; let r = Math . max ( a , b ) ; let temp = new Array ( r - l + 1 ) ; temp . fill ( 0 ) ; let j = 0 ; for ( let i = l ; i <= r ; i ++ ) { temp [ j ] = arr [ i ] ; j ++ ; } temp . sort ( function ( a , b ) { return a - b } ) ; j = 0 ; for ( let i = l ; i <= r ; i ++ ) { arr [ i ] = temp [ j ] ; j ++ ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( arr [ i ] + \\\" \\\" ) ; } } let arr = [ 7 , 8 , 4 , 5 , 2 ] ; let a = 1 , b = 4 ; let N = arr . length ; partSort ( arr , N , a , b ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Number of values of b such that a = b + ( a ^ b ) | Java program to find the number of values of b such that a = b + ( a ^ b ) ; function to return the number of solutions ; check for every possible value ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static int countSolutions ( int a ) { int count = 0 ; for ( int i = 0 ; i <= a ; i ++ ) { if ( a == ( i + ( a ^ i ) ) ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int a = 3 ; System . out . println ( countSolutions ( a ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"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 ▁ \\\" , 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\":\"\\\"Construct a frequency array of digits of the values obtained from x ^ 1 , x ^ 2 , ... ... . . , x ^ n | Function that traverses digits in a number and modifies frequency count array ; Array to keep count of digits ; Traversing through x ^ 1 to x ^ n ; For power function , both its parameters are to be in double ; calling countDigits function on x ^ i ; Printing count of digits 0 - 9 ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function countDigits ( $ val , & $ arr ) { while ( $ val > 0 ) { $ digit = $ val % 10 ; $ arr [ ( int ) ( $ digit ) ] += 1 ; $ val = ( int ) ( $ val \\/ 10 ) ; } return ; } function countFrequency ( $ x , $ n ) { $ freq_count = array_fill ( 0 , 10 , 0 ) ; for ( $ i = 1 ; $ i < $ n + 1 ; $ i ++ ) { $ val = pow ( $ x , $ i ) ; countDigits ( $ val , $ freq_count ) ; } for ( $ i = 0 ; $ i < 10 ; $ i ++ ) { echo $ freq_count [ $ i ] . \\\" \\\" ; } } $ x = 15 ; $ n = 3 ; countFrequency ( $ x , $ n ) ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum steps to convert all top left to bottom right paths in Matrix as palindrome | Set 2 | C ++ program for the above approach ; Function for counting minimum number of changes ; Distance of elements from ( 0 , 0 ) will is i range [ 0 , n + m - 2 ] ; Store frequencies of [ 0 , 9 ] at distance i ; Initialize frequencies as 0 ; Count frequencies of [ 0 , 9 ] ; Increment frequency of value matrix [ i ] [ j ] at distance i + j ; Find value with max frequency and count total cells at distance i from front end and rear end ; Change all values to the value with max frequency ; Return the answer ; Driver Code ; Given Matrix ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; #define N 7\\nint countChanges ( int matrix [ ] [ N ] , int n , int m ) { int dist = n + m - 1 ; int freq [ dist ] [ 10 ] ; for ( int i = 0 ; i < dist ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) freq [ i ] [ j ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { freq [ i + j ] [ matrix [ i ] [ j ] ] ++ ; } } int min_changes_sum = 0 ; for ( int i = 0 ; i < dist \\/ 2 ; i ++ ) { int maximum = 0 ; int total_values = 0 ; for ( int j = 0 ; j < 10 ; j ++ ) { maximum = max ( maximum , freq [ i ] [ j ] + freq [ n + m - 2 - i ] [ j ] ) ; total_values += ( freq [ i ] [ j ] + freq [ n + m - 2 - i ] [ j ] ) ; } min_changes_sum += ( total_values - maximum ) ; } return min_changes_sum ; } int main ( ) { int mat [ ] [ N ] = { { 1 , 2 } , { 3 , 5 } } ; cout << countChanges ( mat , 2 , 2 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Minimum distance between two occurrences of maximum | C program to find Min distance of maximum element ; function to return min distance ; case a ; case b ; case c ; driver program\\nHow can the above be solved in C?\",\"targets\":\"#include \\nusing namespace std ; int minDistance ( int arr [ ] , int n ) { int maximum_element = arr [ 0 ] ; int min_dis = n ; int index = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( maximum_element == arr [ i ] ) { min_dis = min ( min_dis , ( i - index ) ) ; index = i ; } else if ( maximum_element < arr [ i ] ) { maximum_element = arr [ i ] ; min_dis = n ; index = i ; } else continue ; } return min_dis ; } int main ( ) { int arr [ ] = { 6 , 3 , 1 , 3 , 6 , 4 , 6 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << \\\" Minimum ▁ distance ▁ = ▁ \\\" << minDistance ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"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 | 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 Javascript:\",\"targets\":\"function precompute ( nextpos , arr , N ) { nextpos [ N - 1 ] = N ; for ( var i = N - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] == arr [ i + 1 ] ) nextpos [ i ] = nextpos [ i + 1 ] ; else nextpos [ i ] = i + 1 ; } } function findIndex ( query , arr , N , Q ) { var nextpos = Array ( N ) ; precompute ( nextpos , arr , N ) ; for ( var i = 0 ; i < Q ; i ++ ) { var l , r , x ; l = query [ i ] [ 0 ] ; r = query [ i ] [ 1 ] ; x = query [ i ] [ 2 ] ; var ans = - 1 ; if ( arr [ l ] != x ) ans = l ; else { var d = nextpos [ l ] ; if ( d <= r ) ans = d ; } document . write ( ans + \\\" \\\" ) ; } } var N , Q ; N = 6 ; Q = 3 ; var arr = [ 1 , 2 , 1 , 1 , 3 , 5 ] ; var query = [ [ 0 , 3 , 1 ] , [ 1 , 5 , 2 ] , [ 2 , 3 , 1 ] ] ; findIndex ( query , arr , N , Q ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\\nHow can the above be solved 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 ▁ found \\\" ) ; else printf ( \\\" % c \\\" , str [ pos ] ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"k | Java program to check for even or odd ; Function to find k - th missing element ; interating over the array ; check if i - th and ( i + 1 ) - th element are not consecutive ; save their difference ; check for difference and given k ; if found ; Driver code ; Input array ; k - th missing element to be found in the array ; calling function to find missing element\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; import java . util . * ; public class GFG { static int missingK ( int [ ] a , int k , int n ) { int difference = 0 , ans = 0 , count = k ; boolean flag = false ; for ( int i = 0 ; i < n - 1 ; i ++ ) { difference = 0 ; if ( ( a [ i ] + 1 ) != a [ i + 1 ] ) { difference += ( a [ i + 1 ] - a [ i ] ) - 1 ; if ( difference >= count ) { ans = a [ i ] + count ; flag = true ; break ; } else count -= difference ; } } if ( flag ) return ans ; else return - 1 ; } public static void main ( String args [ ] ) { int [ ] a = { 1 , 5 , 11 , 19 } ; int k = 11 ; int n = a . length ; int missing = missingK ( a , k , n ) ; System . out . print ( missing ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 ▁ know ▁ which ▁ value ▁ is ▁ ▁ full - fill ▁ our ▁ criteria ▁ ▁ that ' s why we doing two calls ; Driver Code\\\"\\nSolution in C#:\",\"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\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all nodes with smaller values at a distance K from a given node in a BST | Structure of Tree ; Constructor ; Function to add the node to the sum below the target node ; Base Case ; If Kth distant node is reached ; Recur for the left and the right subtrees ; Function to find the K distant nodes from target node , it returns - 1 if target node is not present in tree ; Base Case 1 ; If target is same as root . ; Recurr for the left subtree ; Tree is BST so reduce the search space ; Check if target node was found in left subtree ; If root is at distance k from the target ; Node less than target will be present in left ; When node is not present in the left subtree ; If Kth distant node is reached ; Node less than target at k distance maybe present in the left tree ; If target was not present in the left nor in right subtree ; Function to insert a node in BST ; If root is null ; Insert the data in right half ; Insert the data in left half ; Return the root node ; Function to find the sum of K distant nodes from the target node having value less than target node ; Stores the sum of nodes having values < target at K distance ; Print the resultant sum ; Driver Code ; Create the Tree\\\"\\nHow can the above be solved in JS?\",\"targets\":\"let sum = 0 ; class TreeNode { constructor ( data = \\\" \\\" , left = null , right = null ) { this . data = data ; this . left = left ; this . right = right ; } } function kDistanceDownSum ( root , k ) { if ( root == null k < 0 ) { return } if ( k == 0 ) { sum += root . data ; return ; } kDistanceDownSum ( root . left , k - 1 ) ; kDistanceDownSum ( root . right , k - 1 ) ; } function kDistanceSum ( root , target , k ) { if ( root == null ) return - 1 ; if ( root . data == target ) { kDistanceDownSum ( root . left , k - 1 ) ; return 0 ; } let dl = - 1 ; if ( target < root . data ) { dl = kDistanceSum ( root . left , target , k ) ; } if ( dl != - 1 ) { if ( dl + 1 == k ) sum += root . data ; return - 1 ; } let dr = - 1 ; if ( target > root . data ) { dr = kDistanceSum ( root . right , target , k ) ; } if ( dr != - 1 ) { if ( dr + 1 == k ) sum += root . data ; else kDistanceDownSum ( root . left , k - dr - 2 ) ; return 1 + dr ; } return - 1 ; } function insertNode ( data , root ) { if ( root == null ) { let node = new TreeNode ( data ) ; return node ; } else if ( data > root . data ) { root . right = insertNode ( data , root . right ) ; } else if ( data <= root . data ) { root . left = insertNode ( data , root . left ) ; } return root ; } function findSum ( root , target , K ) { kDistanceSum ( root , target , K , sum ) ; document . write ( sum ) ; } let root = null ; let N = 11 ; let tree = [ 3 , 1 , 7 , 0 , 2 , 5 , 10 , 4 , 6 , 9 , 8 ] ; for ( let i = 0 ; i < N ; i ++ ) { root = insertNode ( tree [ i ] , root ) ; } let target = 7 ; let K = 2 ; findSum ( root , target , K ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program to check whether a number is Proth number or not | CPP program to check Proth number ; Utility function to check power of two ; Function to check if the Given number is Proth number or not ; check if k divides n or not ; Check if n \\/ k is power of 2 or not ; update k to next odd number ; If we reach here means there exists no value of K Such that k is odd number and n \\/ k is a power of 2 greater than k ; Driver code ; Get n ; Check n for Proth Number\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool isPowerOfTwo ( int n ) { return ( n && ! ( n & ( n - 1 ) ) ) ; } bool isProthNumber ( int n ) { int k = 1 ; while ( k < ( n \\/ k ) ) { if ( n % k == 0 ) { if ( isPowerOfTwo ( n \\/ k ) ) return true ; } k = k + 2 ; } return false ; } int main ( ) { int n = 25 ; if ( isProthNumber ( n - 1 ) ) 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\":\"\\\"Count subarrays having sum modulo K same as the length of the subarray | Function that counts the subarrays having sum modulo k equal to the length of subarray ; Stores the count of subarrays ; Stores prefix sum of the array ; Calculate prefix sum array ; Generate all the subarrays ; Check if this subarray is a valid subarray or not ; Total count of subarrays ; Given arr [ ] ; Size of the array ; Given K ; Function Call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function countSubarrays ( a , n , k ) { var ans = 0 ; var pref = [ ] ; pref . push ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) pref . push ( ( a [ i ] + pref [ i ] ) % k ) ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = i ; j <= n ; j ++ ) { if ( ( pref [ j ] - pref [ i - 1 ] + k ) % k == j - i + 1 ) { ans ++ ; } } } document . write ( ans + ' ' ) ; } var arr = [ 2 , 3 , 5 , 3 , 1 , 5 ] ; var N = arr . length ; var K = 4 ; countSubarrays ( arr , N , K ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\\\"\\nHow can the above be solved 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\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Shortest Uncommon Subsequence | A dynamic programming based PHP program to find shortest uncommon subsequence . ; Returns length of shortest common subsequence ; declaring 2D array of m + 1 rows and n + 1 columns dynamically ; T string is empty ; S string is empty ; char not present in T ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ GLOBALS [ ' MAX ' ] = 1005 ; function shortestSeq ( $ S , $ T ) { $ m = strlen ( $ S ) ; $ n = strlen ( $ T ) ; $ dp = array ( array ( ) ) ; for ( $ i = 0 ; $ i <= $ m ; $ i ++ ) $ dp [ $ i ] [ 0 ] = 1 ; for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) $ dp [ 0 ] [ $ i ] = $ GLOBALS [ ' MAX ' ] ; for ( $ i = 1 ; $ i <= $ m ; $ i ++ ) { for ( $ j = 1 ; $ j <= $ n ; $ j ++ ) { $ ch = $ S [ $ i - 1 ] ; for ( $ k = $ j - 1 ; $ k >= 0 ; $ k -- ) if ( $ T [ $ k ] == $ ch ) break ; if ( $ k == -1 ) $ dp [ $ i ] [ $ j ] = 1 ; else $ dp [ $ i ] [ $ j ] = min ( $ dp [ $ i - 1 ] [ $ j ] , $ dp [ $ i - 1 ] [ $ k ] + 1 ) ; } } $ ans = $ dp [ $ m ] [ $ n ] ; if ( $ ans >= $ GLOBALS [ ' MAX ' ] ) $ ans = -1 ; return $ ans ; } $ S = \\\" babab \\\" ; $ T = \\\" babba \\\" ; $ m = strlen ( $ S ) ; $ n = strlen ( $ T ) ; echo \\\" Length ▁ of ▁ shortest ▁ subsequence ▁ is ▁ : ▁ \\\" , shortestSeq ( $ S , $ T ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Rare Numbers | C # 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\\\"\\nSolution in C#:\",\"targets\":\"using System ; 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 bool isPerfectSquare ( double x ) { double sr = Math . Sqrt ( x ) ; return ( ( sr - Math . Floor ( sr ) ) == 0 ) ; } static bool 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 ) ) { 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\":\"\\\"Dynamic Programming | High | 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 code\\\"\\nSolution in Javascript:\",\"targets\":\"function maxTasks ( high , low , n ) { if ( n <= 0 ) return 0 ; return Math . max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ; } let n = 5 ; let high = [ 3 , 6 , 8 , 7 , 6 ] ; let low = [ 1 , 5 , 4 , 5 , 3 ] ; document . write ( maxTasks ( high , low , n ) ) ; ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count of pairs in an Array whose sum is Prime | Function for Sieve Of Eratosthenes ; Function to count total number of pairs of elements whose sum is prime ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def sieveOfEratosthenes ( N ) :\\n\\tisPrime = [ True for i in range ( N + 1 ) ]\\n\\tisPrime [ 0 ] = False\\n\\tisPrime [ 1 ] = False\\n\\ti = 2\\n\\twhile ( ( i * i ) <= N ) :\\n\\t\\tif ( isPrime [ i ] ) :\\n\\t\\t\\tj = 2\\n\\t\\t\\twhile ( i * j <= N ) :\\n\\t\\t\\t\\tisPrime [ i * j ] = False\\n\\t\\t\\t\\tj += 1\\n\\t\\ti += 1\\n\\treturn isPrime\\ndef numPairsWithPrimeSum ( arr , n ) :\\n\\tN = 2 * 1000000\\n\\tisPrime = sieveOfEratosthenes ( N )\\n\\tcount = 0\\n\\tfor i in range ( n ) :\\n\\t\\tfor j in range ( i + 1 , n ) :\\n\\t\\t\\tsum = arr [ i ] + arr [ j ]\\n\\t\\t\\tif ( isPrime [ sum ] ) :\\n\\t\\t\\t\\tcount += 1\\n\\treturn count\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tarr = [ 1 , 2 , 3 , 4 , 5 ]\\n\\tn = len ( arr )\\n\\tprint ( numPairsWithPrimeSum ( arr , n ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Total character pairs from two strings , with equal number of set bits in their ascii value | JavaScript implementation of the approach Function to get no of set bits in binary representation of positive integer n ; Function to return the count of valid pairs ; Store frequency of number of set bits for s1 ; Store frequency of number of set bits for s2 ; Calculate total pairs ; Return the count of valid pairs ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function countSetBits ( n ) { var count = 0 ; while ( n ) { count += n & 1 ; n >>= 1 ; } return count ; } function totalPairs ( s1 , s2 ) { var count = 0 ; var arr1 = new Array ( 7 ) . fill ( 0 ) ; var arr2 = new Array ( 7 ) . fill ( 0 ) ; for ( let i = 0 ; i < s1 . length ; i ++ ) { set_bits = countSetBits ( s1 [ i ] . charCodeAt ( 0 ) ) ; arr1 [ set_bits ] += 1 ; } for ( let i = 0 ; i < s2 . length ; i ++ ) { set_bits = countSetBits ( s2 [ i ] . charCodeAt ( 0 ) ) ; arr2 [ set_bits ] += 1 ; } for ( let i = 1 ; i < 7 ; i ++ ) { count += arr1 [ i ] * arr2 [ i ] ; } return count ; } var s1 = \\\" \\\" ; var s2 = \\\" \\\" ; document . write ( totalPairs ( s1 , s2 ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"Search , insert and delete in an unsorted array | C program to implement linear search in unsorted array ; Function to implement search operation ; Driver Code ; Using a last element as search element\\nHow can the above be solved 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 main ( ) { int arr [ ] = { 12 , 34 , 10 , 6 , 40 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int key = 40 ; int position = findElement ( arr , n , key ) ; if ( position == - 1 ) printf ( \\\" Element ▁ not ▁ found \\\" ) ; else printf ( \\\" Element ▁ Found ▁ at ▁ Position : ▁ % d \\\" , position + 1 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Smallest power of 2 greater than or equal to n | ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\nunsigned 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 ; printf ( \\\" % d \\\" , nextPowerOf2 ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-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 C++:\",\"targets\":\"#include \\nusing namespace std ; bool isSubsetSum ( int set [ ] , int n , int sum ) { bool subset [ n + 1 ] [ sum + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) subset [ i ] [ 0 ] = true ; for ( int i = 1 ; i <= sum ; i ++ ) subset [ 0 ] [ i ] = false ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( j < set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ; if ( j >= set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - set [ i - 1 ] ] ; } } for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= sum ; j ++ ) printf ( \\\" % 4d \\\" , subset [ i ] [ j ] ) ; cout << \\\" \\n \\\" ; } return subset [ n ] [ sum ] ; } 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 ▁ a ▁ subset ▁ with ▁ given ▁ sum \\\" ; else cout << \\\" No ▁ subset ▁ with ▁ given ▁ sum \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"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\":\"\\\"Minimum flips required to generate continuous substrings of 0 â €™ s and 1 â €™ s | Javascript 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\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function minChanges ( str , N ) { var res ; var count0 = 0 , count1 = 0 ; str . split ( ' ' ) . forEach ( x => { count0 += ( x == ' ' ) ; } ) ; res = count0 ; str . split ( ' ' ) . forEach ( x => { count0 -= ( x == ' ' ) ; count1 += ( x == ' ' ) ; res = Math . min ( res , count1 + count0 ) ; } ) ; return res ; } var N = 9 ; var str = \\\" \\\" ; document . write ( minChanges ( str , N ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"Find a triplet that sum to a given value | ; returns true if there is triplet with sum equal to ' sum ' present in A [ ] . Also , prints the triplet ; Fix the first element as A [ i ] ; Fix the second element as A [ j ] ; Now look for the third number ; If we reach here , then no triplet was found ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nbool find3Numbers ( int A [ ] , int arr_size , int sum ) { int l , r ; for ( int i = 0 ; i < arr_size - 2 ; i ++ ) { for ( int j = i + 1 ; j < arr_size - 1 ; j ++ ) { for ( int k = j + 1 ; k < arr_size ; k ++ ) { if ( A [ i ] + A [ j ] + A [ k ] == sum ) { printf ( \\\" Triplet ▁ is ▁ % d , ▁ % d , ▁ % d \\\" , A [ i ] , A [ j ] , A [ k ] ) ; return true ; } } } } return false ; } int main ( ) { int A [ ] = { 1 , 4 , 45 , 6 , 10 , 8 } ; int sum = 22 ; int arr_size = sizeof ( A ) \\/ sizeof ( A [ 0 ] ) ; find3Numbers ( A , arr_size , sum ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count of distinct pair sum between two 1 to N value Arrays | Java implementation to count of distinct pair sum between two Array with values 1 to N ; Function to find the distinct sums ; Set to store distinct sums ; Inserting every sum ; Returning distinct sums ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static int findDistinctSums ( int n ) { HashSet < Integer > s = new HashSet < > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = i ; j <= n ; j ++ ) { s . add ( i + j ) ; } } return s . size ( ) ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . print ( findDistinctSums ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Print all longest common sub | Javascript 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 ▁ and ▁ 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 ▁ why ▁ we ▁ start ▁ from ▁ ' 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 JS?\",\"targets\":\"let MAX = 100 ; let lcslen = 0 ; let dp = new Array ( MAX ) ; function lcs ( str1 , str2 , len1 , len2 , i , j ) { let 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 ; } function printAll ( str1 , str2 , len1 , len2 , data , indx1 , indx2 , currlcs ) { if ( currlcs == lcslen ) { data [ currlcs ] = null ; document . write ( data . join ( \\\" \\\" ) + \\\" \\\" ) ; return ; } if ( indx1 == len1 indx2 == len2 ) return ; for ( let ch = ' ' . charCodeAt ( 0 ) ; ch <= ' ' . charCodeAt ( 0 ) ; ch ++ ) { let done = false ; for ( let i = indx1 ; i < len1 ; i ++ ) { if ( ch == str1 [ i ] . charCodeAt ( 0 ) ) { for ( let j = indx2 ; j < len2 ; j ++ ) { if ( ch == str2 [ j ] . charCodeAt ( 0 ) && lcs ( str1 , str2 , len1 , len2 , i , j ) == lcslen - currlcs ) { data [ currlcs ] = String . fromCharCode ( ch ) ; printAll ( str1 , str2 , len1 , len2 , data , i + 1 , j + 1 , currlcs + 1 ) ; done = true ; break ; } } } if ( done ) break ; } } } function prinlAllLCSSorted ( str1 , str2 ) { let len1 = str1 . length , len2 = str2 . length ; for ( let i = 0 ; i < MAX ; i ++ ) { dp [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } lcslen = lcs ( str1 , str2 , len1 , len2 , 0 , 0 ) ; let data = new Array ( MAX ) ; printAll ( str1 , str2 , len1 , len2 , data , 0 , 0 , 0 ) ; } let str1 = \\\" \\\" , str2 = \\\" \\\" ; prinlAllLCSSorted ( str1 , str2 ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to split array into two subsets having difference between their sum equal to K | Java program for the above approach ; Function to count the number of ways to divide the array into two subsets and such that the difference between their sums is equal to diff ; Store the sum of the set S1 ; Initializing the matrix ; Number of ways to get sum using 0 elements is 0 ; Number of ways to get sum 0 using i elements is 1 ; Traverse the 2D array ; If the value is greater than the sum store the value of previous state ; Return the result ; Driver Code ; Given Input ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; public class GFG { static int countSubset ( int [ ] arr , int n , int diff ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; sum += diff ; sum = sum \\/ 2 ; int t [ ] [ ] = new int [ n + 1 ] [ sum + 1 ] ; for ( int j = 0 ; j <= sum ; j ++ ) t [ 0 ] [ j ] = 0 ; for ( int i = 0 ; i <= n ; i ++ ) t [ i ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( arr [ i - 1 ] > j ) t [ i ] [ j ] = t [ i - 1 ] [ j ] ; else { t [ i ] [ j ] = t [ i - 1 ] [ j ] + t [ i - 1 ] [ j - arr [ i - 1 ] ] ; } } } return t [ n ] [ sum ] ; } public static void main ( String [ ] args ) { int diff = 1 , n = 4 ; int arr [ ] = { 1 , 1 , 2 , 3 } ; System . out . print ( countSubset ( arr , n , diff ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Program to compute log a to any base b ( logb a ) | C program to find log ( a ) on any base b using Recursion ; Recursive function to compute log a to the base b ; Driver code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint log_a_to_base_b ( int a , int b ) { return ( a > b - 1 ) ? 1 + log_a_to_base_b ( a \\/ b , b ) : 0 ; } int main ( ) { int a = 3 ; int b = 2 ; printf ( \\\" % d \\n \\\" , log_a_to_base_b ( a , b ) ) ; a = 256 ; b = 4 ; printf ( \\\" % d \\n \\\" , log_a_to_base_b ( a , b ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"In | C ++ program in - place Merge Sort ; Merges two subarrays of arr [ ] . First subarray is arr [ l . . m ] Second subarray is arr [ m + 1. . r ] Inplace Implementation ; If the direct merge is already sorted ; Two pointers to maintain start of both arrays to merge ; If element 1 is in right place ; Shift all the elements between element 1 element 2 , right by 1. ; Update all the pointers ; l is for left index and r is right index of the sub - array of arr to be sorted ; Same as ( l + r ) \\/ 2 , but avoids overflow for large l and r ; Sort first and second halves ; Function to print an array ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\nvoid merge ( int arr [ ] , int start , int mid , int end ) { int start2 = mid + 1 ; if ( arr [ mid ] <= arr [ start2 ] ) { return ; } while ( start <= mid && start2 <= end ) { if ( arr [ start ] <= arr [ start2 ] ) { start ++ ; } else { int value = arr [ start2 ] ; int index = start2 ; while ( index != start ) { arr [ index ] = arr [ index - 1 ] ; index -- ; } arr [ start ] = value ; start ++ ; mid ++ ; start2 ++ ; } } } void mergeSort ( int arr [ ] , int l , int r ) { if ( l < r ) { int m = l + ( r - l ) \\/ 2 ; mergeSort ( arr , l , m ) ; mergeSort ( arr , m + 1 , r ) ; merge ( arr , l , m , r ) ; } } void printArray ( int A [ ] , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) printf ( \\\" % d ▁ \\\" , A [ i ] ) ; printf ( \\\" \\n \\\" ) ; } int main ( ) { int arr [ ] = { 12 , 11 , 13 , 5 , 6 , 7 } ; int arr_size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; mergeSort ( arr , 0 , arr_size - 1 ) ; printArray ( arr , arr_size ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Pascal 's Triangle | binomialCoeff ; Function to print first n lines of Pascal 's Triangle ; Iterate through every line and print entries in it ; Every line has number of integers equal to line number ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function binomialCoeff ( n , k ) { let res = 1 ; if ( k > n - k ) k = n - k ; for ( let i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res \\/= ( i + 1 ) ; } return res ; } function printPascal ( n ) { for ( let line = 0 ; line < n ; line ++ ) { for ( let i = 0 ; i <= line ; i ++ ) document . write ( binomialCoeff ( line , i ) + \\\" \\\" ) ; document . write ( \\\" \\\" ) ; } } let n = 7 ; printPascal ( n ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find count of Almost Prime numbers from 1 to N | Java 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\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int N = 100005 ; static boolean prime [ ] = new boolean [ N ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i < N ; i ++ ) prime [ i ] = true ; prime [ 1 ] = false ; for ( int p = 2 ; p * p < N ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i < N ; i += p ) prime [ i ] = false ; } } } static int almostPrimes ( int n ) { int ans = 0 ; for ( int i = 6 ; i <= n ; i ++ ) { int c = 0 ; for ( int j = 2 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { if ( j * j == i ) { if ( prime [ j ] ) c ++ ; } else { if ( prime [ j ] ) c ++ ; if ( prime [ i \\/ j ] ) c ++ ; } } } if ( c == 2 ) ans ++ ; } return ans ; } public static void main ( String [ ] args ) { SieveOfEratosthenes ( ) ; int n = 21 ; System . out . println ( almostPrimes ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximize the largest number K such that bitwise and of K till N is 0 | Function to find maximum value of k which makes bitwise AND zero . ; Finding the power less than N ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function findMaxK ( N ) { var p = Math . log ( N ) \\/ Math . log ( 2 ) ; return parseInt ( Math . pow ( 2 , p ) ) ; } var N = 5 ; document . write ( findMaxK ( N ) - 1 ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of consecutive sequences that can be formed in an array | PHP program find the minimum number of consecutive sequences in an array ; Driver Code ; function call to print required answer\\\"\\nSolution in php:\",\"targets\":\"< ? php function countSequences ( $ arr , $ n ) { $ count = 1 ; sort ( $ arr ) ; for ( $ i = 0 ; $ i < $ n - 1 ; $ i ++ ) if ( $ arr [ $ i ] + 1 != $ arr [ $ i + 1 ] ) $ count ++ ; return $ count ; } $ arr = array ( 1 , 7 , 3 , 5 , 10 ) ; $ n = count ( $ arr ) ; echo countSequences ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if a point lies inside a rectangle | Set | Java program to Check if a point lies on or inside a rectangle | Set - 2 ; function to find if given point lies inside a given rectangle or not . ; Driver code ; bottom - left and top - right corners of rectangle ; given point ; function call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static boolean FindPoint ( int x1 , int y1 , int x2 , int y2 , int x , int y ) { if ( x > x1 && x < x2 && y > y1 && y < y2 ) return true ; return false ; } public static void main ( String [ ] args ) { int x1 = 0 , y1 = 0 , x2 = 10 , y2 = 8 ; int x = 1 , y = 5 ; if ( FindPoint ( x1 , y1 , x2 , y2 , x , y ) ) 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\":\"\\\"Print characters and their frequencies in order of occurrence | C ++ implementation to print the characters and frequencies in order of its occurrence ; Store all characters and their frequencies in dictionary ; Print characters and their frequencies in same order of their appearance ; Print only if this character is not printed before ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void prCharWithFreq ( string s ) { unordered_map < char , int > d ; for ( char i : s ) { d [ i ] ++ ; } for ( char i : s ) { if ( d [ i ] != 0 ) { cout << i << d [ i ] << \\\" ▁ \\\" ; d [ i ] = 0 ; } } } int main ( ) { string s = \\\" geeksforgeeks \\\" ; prCharWithFreq ( s ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Number of solutions of n = x + n ⊠• x | C ++ implementation of above approach ; 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 C++?\",\"targets\":\"#include \\nusing namespace std ; int numberOfSolutions ( int n ) { int c = 0 ; for ( int x = 0 ; x <= n ; ++ x ) if ( n == x + n ^ x ) ++ c ; return c ; } int main ( ) { int n = 3 ; cout << numberOfSolutions ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Counts paths from a point to reach Origin | DP based function to count number of paths ; $dp [ $n + 1 ] [ $m + 1 ] ; Fill entries in bottommost row and leftmost columns ; Fill DP in bottom up manner ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function countPaths ( $ n , $ m ) { for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) $ dp [ $ i ] [ 0 ] = 1 ; for ( $ i = 0 ; $ i <= $ m ; $ i ++ ) $ dp [ 0 ] [ $ i ] = 1 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) for ( $ j = 1 ; $ j <= $ m ; $ j ++ ) $ dp [ $ i ] [ $ j ] = $ dp [ $ i - 1 ] [ $ j ] + $ dp [ $ i ] [ $ j - 1 ] ; return $ dp [ $ n ] [ $ m ] ; } $ n = 3 ; $ m = 2 ; echo \\\" ▁ Number ▁ of ▁ Paths ▁ \\\" , countPaths ( $ n , $ m ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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\\\"\\nHow can the above be solved 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\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Area of the largest Rectangle without a given point | C # implementation to find area of largest Rectangle without hole within a given Rectangle ; Function to find the maximum area such that it does not contains any hole ; Area for all the possible positions of the cut ; Find the maximum area among the above rectangles ; Driver Code ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void maximumArea ( int l , int b , int x , int y ) { int left , right , above , below ; left = x * b ; right = ( l - x - 1 ) * b ; above = l * y ; below = ( b - y - 1 ) * l ; Console . Write ( Math . Max ( Math . Max ( left , right ) , Math . Max ( above , below ) ) ) ; } public static void Main ( String [ ] args ) { int L = 8 , B = 8 ; int X = 0 , Y = 0 ; maximumArea ( L , B , X , Y ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find a Fixed Point ( Value equal to index ) in a given array | javascript 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\\\"\\nSolution in Javascript:\",\"targets\":\"function binarySearch ( arr , low , high ) { if ( high >= low ) { let mid = Math . floor ( ( 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 ; } let arr = [ - 10 , - 1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 ] ; let n = arr . length ; document . write ( \\\" \\\" + binarySearch ( arr , 0 , n - 1 ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count set bits in an integer | C program to count set bits by pre - storing count set bits in nibbles . ; Recursively get nibble of a given number and map them in the array ; Find last nibble ; Use pre - stored values to find count in last nibble plus recursively add remaining nibbles . ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\nint num_to_bits [ 16 ] = { 0 , 1 , 1 , 2 , 1 , 2 , 2 , 3 , 1 , 2 , 2 , 3 , 2 , 3 , 3 , 4 } ; unsigned int countSetBitsRec ( unsigned int num ) { int nibble = 0 ; if ( 0 == num ) return num_to_bits [ 0 ] ; nibble = num & 0xf ; return num_to_bits [ nibble ] + countSetBitsRec ( num >> 4 ) ; } int main ( ) { int num = 31 ; printf ( \\\" % d \\n \\\" , countSetBitsRec ( num ) ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Insert minimum number in array so that sum of array becomes prime | C # program to find minimum number to insert in array so their sum is prime ; Array to store primes ; 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\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"class GFG { static int MAX = 100005 ; static bool [ ] isPrime = new bool [ MAX ] ; static void sieveOfEratostheneses ( ) { isPrime [ 1 ] = true ; for ( int i = 2 ; i * i < MAX ; i ++ ) { if ( ! isPrime [ i ] ) { for ( int j = 2 * i ; j < MAX ; j += i ) isPrime [ j ] = true ; } } } static int findPrime ( int n ) { int num = n + 1 ; while ( num > 0 ) { if ( ! isPrime [ num ] ) return num ; num = num + 1 ; } return 0 ; } static int minNumber ( int [ ] arr , int n ) { sieveOfEratostheneses ( ) ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( ! isPrime [ sum ] ) return 0 ; int num = findPrime ( sum ) ; return num - sum ; } public static void Main ( ) { int [ ] arr = { 2 , 4 , 6 , 8 , 12 } ; int n = arr . Length ; System . Console . WriteLine ( minNumber ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count of subarrays with largest element at least twice the largest of remaining elements | C ++ program for the above approach ; Function to find count of subarrays which have max element greater than twice maximum of all other elements ; Stores the count of subarrays ; Generate all possible subarrays ; Stores the maximum element of the subarray ; Stores the maximum of all other elements ; Find the maximum element in the subarray [ i , j ] ; Find the maximum of all other elements ; If the maximum of subarray is greater than twice the maximum of other elements ; Print the maximum value obtained ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void countSubarray ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { int mxSubarray = 0 ; int mxOther = 0 ; for ( int k = i ; k <= j ; k ++ ) { mxSubarray = max ( mxSubarray , arr [ k ] ) ; } for ( int k = 0 ; k < i ; k ++ ) { mxOther = max ( mxOther , arr [ k ] ) ; } for ( int k = j + 1 ; k < n ; k ++ ) { mxOther = max ( mxOther , arr [ k ] ) ; } if ( mxSubarray > ( 2 * mxOther ) ) count ++ ; } } cout << count ; } int main ( ) { int arr [ ] = { 1 , 6 , 10 , 9 , 7 , 3 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; countSubarray ( arr , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum path sum from top left to bottom right of a matrix passing through one of the given cells | Stores the maximum path sum from the cell ( 1 , 1 ) to ( N , M ) ; Stores the maximum path sum from the cell ( j , j ) to ( N , M ) ; Function to find the maximum path sum from the cell ( 1 , 1 ) to ( N , M ) ; Traverse the first row ; Traverse the first column ; Traverse the matrix ; Update the value of start [ i ] [ j ] ; Function to find the maximum path sum from the cell ( j , j ) to ( N , M ) ; Traverse the last row ; Traverse the last column ; Traverse the matrix ; Update the value of ending [ i ] [ j ] ; Function to find the maximum path sum from the top - left to the bottom right cell such that path contains one of the cells in the array coordinates [ ] [ ] ; Initialize the start and the end matrices ; Calculate the start matrix ; Calculate the end matrix ; Stores the maximum path sum ; Traverse the coordinates ; Update the value of ans ; Print the resultant maximum sum path value ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"start = [ [ 0 for i in range ( 3 ) ] for j in range ( 3 ) ]\\nending = [ [ 0 for i in range ( 3 ) ] for j in range ( 3 ) ]\\ndef calculateStart ( n , m ) :\\n\\tfor i in range ( 1 , m , 1 ) :\\n\\t\\tstart [ 0 ] [ i ] += start [ 0 ] [ i - 1 ]\\n\\tfor i in range ( 1 , n , 1 ) :\\n\\t\\tstart [ i ] [ 0 ] += start [ i - 1 ] [ 0 ]\\n\\tfor i in range ( 1 , n , 1 ) :\\n\\t\\tfor j in range ( 1 , m , 1 ) :\\n\\t\\t\\tstart [ i ] [ j ] += max ( start [ i - 1 ] [ j ] , start [ i ] [ j - 1 ] )\\ndef calculateEnd ( n , m ) :\\n\\ti = n - 2\\n\\twhile ( i >= 0 ) :\\n\\t\\tending [ i ] [ m - 1 ] += ending [ i + 1 ] [ m - 1 ]\\n\\t\\ti -= 1\\n\\ti = m - 2\\n\\twhile ( i >= 0 ) :\\n\\t\\tending [ n - 1 ] [ i ] += ending [ n - 1 ] [ i + 1 ]\\n\\t\\ti -= 1\\n\\ti = n - 2\\n\\twhile ( i >= 0 ) :\\n\\t\\tj = m - 2\\n\\t\\twhile ( j >= 0 ) :\\n\\t\\t\\tending [ i ] [ j ] += max ( ending [ i + 1 ] [ j ] , ending [ i ] [ j + 1 ] )\\n\\t\\t\\tj -= 1\\n\\t\\ti -= 1\\ndef maximumPathSum ( mat , n , m , q , coordinates ) :\\n\\tfor i in range ( n ) :\\n\\t\\tfor j in range ( m ) :\\n\\t\\t\\tstart [ i ] [ j ] = mat [ i ] [ j ]\\n\\t\\t\\tending [ i ] [ j ] = mat [ i ] [ j ]\\n\\tcalculateStart ( n , m )\\n\\tcalculateEnd ( n , m )\\n\\tans = 0\\n\\tfor i in range ( q ) :\\n\\t\\tX = coordinates [ i ] [ 0 ] - 1\\n\\t\\tY = coordinates [ i ] [ 1 ] - 1\\n\\t\\tans = max ( ans , start [ X ] [ Y ] + ending [ X ] [ Y ] - mat [ X ] [ Y ] )\\n\\tprint ( ans )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tmat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]\\n\\tN = 3\\n\\tM = 3\\n\\tQ = 2\\n\\tcoordinates = [ [ 1 , 2 ] , [ 2 , 2 ] ]\\n\\tmaximumPathSum ( mat , N , M , Q , coordinates )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the largest and smallest ASCII valued characters in a string | function that return the largest alphabet . ; initializing max alphabet to ' a ' ; find largest alphabet ; returning largest element ; function that return the smallest alphabet ; initializing smallest alphabet to ' z ' ; find smallest alphabet ; returning smallest alphabet ; Input String ; Calculating size of the string ; calling functions and print returned value\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function largest_alphabet ( a , n ) { let max = ' ' ; for ( let i = 0 ; i < n ; i ++ ) if ( a [ i ] . charCodeAt ( ) > max . charCodeAt ( ) ) max = a [ i ] ; return max ; } function smallest_alphabet ( a , n ) { let min = ' ' ; for ( let i = 0 ; i < n - 1 ; i ++ ) if ( a [ i ] . charCodeAt ( ) < min . charCodeAt ( ) ) min = a [ i ] ; return min ; } let a = \\\" \\\" ; let size = a . length ; document . write ( \\\" \\\" ) ; document . write ( largest_alphabet ( a , size ) + \\\" \\\" ) ; document . write ( smallest_alphabet ( a , size ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count subarrays having an equal count of 0 s and 1 s segregated | Java 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 Java:\",\"targets\":\"import java . util . * ; 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 ++ ; } } } System . out . print ( ans + \\\"\\n\\\"); } public static void main ( String [ ] args ) { int A [ ] = { 1 , 1 , 0 , 0 , 1 , 0 } ; int N = A . length ; countSubarrays ( A , N ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Number of ways to reach Nth floor by taking at | PHP program to reach N - th stair by taking a maximum of K leap ; elements of combo [ ] stores the no of possible ways to reach it by all combinations of k leaps or less ; assuming leap 0 exist and assigning its value to 1 for calculation ; loop to iterate over all possible leaps upto k ; ; in this loop we count all possible leaps to reach the jth stair with the help of ith leap or less ; if the leap is not more than the i - j ; calculate the value and store in combo [ j ] to reuse it for next leap calculation for the jth stair ; returns the no of possible number of leaps to reach the top of building of n stairs ; N i the no of total stairs K is the value of the greatest leap\\\"\\nSolution in php:\",\"targets\":\"< ? php function solve ( $ N , $ K ) { $ combo [ $ N + 1 ] = array ( ) ; $ combo [ 0 ] = 1 ; for ( $ i = 1 ; $ i <= $ K ; $ i ++ ) { for ( $ j = 0 ; $ j <= $ N ; $ j ++ ) { if ( $ j >= $ i ) { $ combo [ $ j ] += $ combo [ $ j - $ i ] ; } } } return $ combo [ $ N ] ; } $ N = 29 ; $ K = 5 ; echo solve ( $ N , $ K ) ; solve ( $ N , $ K ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Median of difference of all pairs from an Array | Java program to implement the above approach ; Function check if mid can be median index of the difference array ; Size of the array ; Total possible no of pair possible ; The index of the element in the difference of all pairs from the array ; Count the number of pairs having difference <= mid ; If the difference between end and first element is less then or equal to mid ; Checking for the no of element less than or equal to mid is greater than median or not ; Function to calculate the median of differences of all pairs from the array ; Size of the array ; Initialising the low and high ; Binary search ; Calculate mid ; If mid can be the median of the array ; Returning the median of the differences of pairs from the array ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static boolean possible ( long mid , int [ ] a ) { long n = a . length ; long total = ( n * ( n - 1 ) ) \\/ 2 ; long need = ( total + 1 ) \\/ 2 ; long count = 0 ; long start = 0 , end = 1 ; while ( end < n ) { if ( a [ ( int ) end ] - a [ ( int ) start ] <= mid ) { end ++ ; } else { count += ( end - start - 1 ) ; start ++ ; } } if ( end == n && start < end && a [ ( int ) end - 1 ] - a [ ( int ) start ] <= mid ) { long t = end - start - 1 ; count += ( t * ( t + 1 ) \\/ 2 ) ; } if ( count >= need ) return true ; else return false ; } static long findMedian ( int [ ] a ) { long n = a . length ; long low = 0 , high = a [ ( int ) n - 1 ] - a [ 0 ] ; while ( low <= high ) { long mid = ( low + high ) \\/ 2 ; if ( possible ( mid , a ) ) high = mid - 1 ; else low = mid + 1 ; } return high + 1 ; } public static void main ( String [ ] args ) { int [ ] a = { 1 , 7 , 5 , 2 } ; Arrays . sort ( a ) ; System . out . println ( findMedian ( a ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 [ ] [ ] ; Stores the index of the resultant pair ; To count the occurences ; Iterate to check every pair ; Set count to 0 ; Condition to checked for overlapping of pairs ; If that pair can cover all other pairs then store its position ; If position not found ; Otherwise ; Driver Code ; Give 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 count ; for ( int i = 0 ; i < N ; i ++ ) { count = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( arr [ i , 0 ] <= arr [ j , 0 ] && arr [ i , 1 ] >= arr [ j , 1 ] ) { count ++ ; } } if ( count == N ) { pos = i ; } } if ( pos == - 1 ) { Console . Write ( pos ) ; } else { Console . Write ( pos + 1 ) ; } } public static void Main ( ) { 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\":\"\\\"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\\\"\\nHow can the above be solved 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\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the repeating and the missing | Added 3 new methods | C program to Find the repeating and missing elements ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nvoid printTwoElements ( int arr [ ] , int size ) { int i ; printf ( \\\" The repeating element is \\\" for ( i = 0 ; i < size ; i ++ ) { if ( arr [ abs ( arr [ i ] ) - 1 ] > 0 ) arr [ abs ( arr [ i ] ) - 1 ] = - arr [ abs ( arr [ i ] ) - 1 ] ; else printf ( \\\" ▁ % d ▁ \\\" , abs ( arr [ i ] ) ) ; } printf ( \\\" and the missing element is \\\" for ( i = 0 ; i < size ; i ++ ) { if ( arr [ i ] > 0 ) printf ( \\\" % d \\\" , i + 1 ) ; } } int main ( ) { int arr [ ] = { 7 , 3 , 4 , 5 , 5 , 6 , 2 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printTwoElements ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"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\\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\":\"\\\"Find depth of the deepest odd level leaf node | C # program to find depth of the deepest odd level leaf node of binary tree ; tree node ; returns a new tree Node ; return max odd number depth of leaf node ; create a queue for level order traversal ; traverse until the queue is empty ; traverse for complete level ; check if the node is leaf node and level is odd if level is odd , then update result ; check for left child ; check for right child ; Driver Code ; construct a tree\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { public class Node { public int data ; public Node left , right ; } ; static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static int maxOddLevelDepth ( Node root ) { if ( root == null ) return 0 ; Queue < Node > q = new Queue < Node > ( ) ; q . Enqueue ( root ) ; int result = int . MaxValue ; int level = 0 ; while ( q . Count != 0 ) { int size = q . Count ; level += 1 ; while ( size > 0 ) { Node temp = q . Peek ( ) ; q . Dequeue ( ) ; if ( temp . left == null && temp . right == null && ( level % 2 != 0 ) ) { result = level ; } if ( temp . left != null ) { q . Enqueue ( temp . left ) ; } if ( temp . right != null ) { q . Enqueue ( temp . right ) ; } size -= 1 ; } } return result ; } public static void Main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . right . left = newNode ( 5 ) ; root . right . right = newNode ( 6 ) ; root . right . left . right = newNode ( 7 ) ; root . right . right . right = newNode ( 8 ) ; root . right . left . right . left = newNode ( 9 ) ; root . right . right . right . right = newNode ( 10 ) ; root . right . right . right . right . left = newNode ( 11 ) ; int result = maxOddLevelDepth ( root ) ; if ( result == int . MaxValue ) Console . WriteLine ( \\\" No ▁ leaf ▁ node ▁ at ▁ odd ▁ level \\\" ) ; else { Console . Write ( result ) ; Console . WriteLine ( \\\" ▁ is ▁ the ▁ required ▁ depth ▁ \\\" ) ; } } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Modify array to another given array by replacing array elements with the sum of the array | C # program for the above approach ; Function to check if the arr [ ] can be converted to target [ ] by replacing any element in arr [ ] by the sum of arr [ ] ; Store the maximum element ; Store the index of the maximum element ; Traverse the array target [ ] ; If current element is greater than max ; If max element is 1 ; Traverse the array , target [ ] ; If current index is not equal to maximum element index ; Update max ; If max is less than or equal to 0 , ; Update the maximum element ; Recursively call the function ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { public static bool isPossible ( int [ ] target ) { int max = 0 ; int index = 0 ; for ( int i = 0 ; i < target . Length ; i ++ ) { if ( max < target [ i ] ) { max = target [ i ] ; index = i ; } } if ( max == 1 ) return true ; for ( int i = 0 ; i < target . Length ; i ++ ) { if ( i != index ) { max -= target [ i ] ; if ( max <= 0 ) return false ; } } target [ index ] = max ; return isPossible ( target ) ; } static public void Main ( ) { int [ ] target = { 9 , 3 , 5 } ; bool res = isPossible ( target ) ; if ( res ) { 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\":\"\\\"The Stock Span Problem | Java program for a linear time solution for stock span problem without using stack ; An efficient method to calculate stock span values implementing the same idea without using stack ; Span value of first element is always 1 ; Calculate span values for rest of the elements ; A utility function to print elements of array ; Driver code ; Fill the span values in array S [ ] ; print the calculated span values\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static void calculateSpan ( int A [ ] , int n , int ans [ ] ) { ans [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { int counter = 1 ; while ( ( i - counter ) >= 0 && A [ i ] >= A [ i - counter ] ) { counter += ans [ i - counter ] ; } ans [ i ] = counter ; } } static void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + \\\" ▁ \\\" ) ; } public static void main ( String [ ] args ) { int price [ ] = { 10 , 4 , 5 , 90 , 120 , 80 } ; int n = price . length ; int S [ ] = new int [ n ] ; calculateSpan ( price , n , S ) ; printArray ( S , n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Smallest divisor of N closest to X | Python3 program for the above approach ; Stores divisors for all numbers in the vector divisors ; i is the divisor and j is the multiple ; Function to compare the closeness of the given target ; Function to find the element closest to target in divisors vector ; Corner cases ; Perform binary search ; Check if target is less than the array element then search in left half ; Check if target is greater than previous to mid , return closest of two ; Repeat for left half ; Check if target is greater than mid ; Update i ; Only single element left after search ; Function to print the divisor of N closest to X ; Function call to calculate and stores divisors of all numbers in a vector ; Stores the closest value to target ; Print the answer ; Driver Code ; Given N & X ; Function Call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"MAX = 10000\\ndivisors = [ [ ] for i in range ( MAX + 1 ) ]\\ndef computeDivisors ( ) :\\n\\tglobal divisors\\n\\tglobal MAX\\n\\tfor i in range ( 1 , MAX + 1 , 1 ) :\\n\\t\\tfor j in range ( i , MAX + 1 , i ) :\\n\\t\\t\\tdivisors [ j ] . append ( i )\\ndef getClosest ( val1 , val2 , target ) :\\n\\tif ( target - val1 >= val2 - target ) :\\n\\t\\treturn val2\\n\\telse :\\n\\t\\treturn val1\\ndef findClosest ( arr , n , target ) :\\n\\tif ( target <= arr [ 0 ] ) :\\n\\t\\treturn arr [ 0 ]\\n\\tif ( target >= arr [ n - 1 ] ) :\\n\\t\\treturn arr [ n - 1 ]\\n\\ti = 0\\n\\tj = n\\n\\tmid = 0\\n\\twhile ( i < j ) :\\n\\t\\tmid = ( i + j ) \\/\\/ 2\\n\\t\\tif ( arr [ mid ] == target ) :\\n\\t\\t\\treturn arr [ mid ]\\n\\t\\tif ( target < arr [ mid ] ) :\\n\\t\\t\\tif ( mid > 0 and target > arr [ mid - 1 ] ) :\\n\\t\\t\\t\\treturn getClosest ( arr [ mid - 1 ] , arr [ mid ] , target )\\n\\t\\t\\tj = mid\\n\\t\\telse :\\n\\t\\t\\tif ( mid < n - 1 and target < arr [ mid + 1 ] ) :\\n\\t\\t\\t\\treturn getClosest ( arr [ mid ] , arr [ mid + 1 ] , target )\\n\\t\\t\\ti = mid + 1\\n\\treturn arr [ mid ]\\ndef printClosest ( N , X ) :\\n\\tglobal divisors\\n\\tcomputeDivisors ( )\\n\\tans = findClosest ( divisors [ N ] , len ( divisors [ N ] ) , X )\\n\\tprint ( ans )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 16\\n\\tX = 5\\n\\tprintClosest ( N , X )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Double the first element and move zero to end | Java implementation to rearrange the array elements after modification ; function which pushes all zeros to end of an array . ; Count of non - zero elements ; Traverse the array . If element encountered is non - zero , then replace the element at index ' count ' with this element ; here count is incremented ; Now all non - zero elements have been shifted to front and ' count ' is set as index of first 0. Make all elements 0 from count to end . ; function to rearrange the array elements after modification ; if ' arr [ ] ' contains a single element only ; traverse the array ; if true , perform the required modification ; double current index value ; put 0 in the next index ; increment by 1 so as to move two indexes ahead during loop iteration ; push all the zeros at the end of ' arr [ ] ' ; function to print the array elements ; Driver program to test above\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static void pushZerosToEnd ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] != 0 ) arr [ count ++ ] = arr [ i ] ; while ( count < n ) arr [ count ++ ] = 0 ; } static void modifyAndRearrangeArr ( int arr [ ] , int n ) { if ( n == 1 ) return ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( ( arr [ i ] != 0 ) && ( arr [ i ] == arr [ i + 1 ] ) ) { arr [ i ] = 2 * arr [ i ] ; arr [ i + 1 ] = 0 ; i ++ ; } } pushZerosToEnd ( arr , n ) ; } static void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + \\\" ▁ \\\" ) ; System . out . println ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 2 , 2 , 2 , 0 , 6 , 6 , 0 , 0 , 8 } ; int n = arr . length ; System . out . print ( \\\" Original ▁ array : ▁ \\\" ) ; printArray ( arr , n ) ; modifyAndRearrangeArr ( arr , n ) ; System . out . print ( \\\" Modified ▁ array : ▁ \\\" ) ; printArray ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count of unordered pairs ( x , y ) of Array which satisfy given equation | Return the number of unordered pairs satisfying the conditions ; ans stores the number of unordered pairs ; Making each value of array to positive ; Sort the array ; For each index calculating the right boundary for the unordered pairs ; Return the final result ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def numPairs ( a , n ) :\\n\\tans = 0\\n\\tfor i in range ( n ) :\\n\\t\\ta [ i ] = abs ( a [ i ] )\\n\\ta . sort ( )\\n\\tfor i in range ( n ) :\\n\\t\\tindex = 0\\n\\t\\tfor j in range ( i + 1 , n ) :\\n\\t\\t\\tif ( 2 * a [ i ] >= a [ j - 1 ] and 2 * a [ i ] < a [ j ] ) :\\n\\t\\t\\t\\tindex = j\\n\\t\\tif index == 0 :\\n\\t\\t\\tindex = n\\n\\t\\tans += index - i - 1\\n\\treturn ans\\na = [ 3 , 6 ]\\nn = len ( a )\\nprint ( numPairs ( a , n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Number with maximum number of prime factors | C # program to find integer having maximum number of prime factor in first N natural numbers . ; Return smallest number having 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 C-Sharp?\",\"targets\":\"using System ; class GFG { static int maxPrimefactorNum ( int N ) { int [ ] arr = new int [ N + 5 ] ; for ( int i = 2 ; i * i <= N ; i ++ ) { if ( arr [ i ] == 0 ) { for ( int j = 2 * i ; j <= N ; j += i ) { arr [ j ] ++ ; } } arr [ i ] = 1 ; } int maxval = 0 , maxint = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( arr [ i ] > maxval ) { maxval = arr [ i ] ; maxint = i ; } } return maxint ; } public static void Main ( ) { int N = 40 ; Console . WriteLine ( maxPrimefactorNum ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Longest Bitonic Subsequence | DP | lbs ( ) returns the length of the Longest Bitonic Subsequence in arr [ ] of size n . The function mainly creates two temporary arrays lis [ ] and lds [ ] and returns the maximum lis [ i ] + lds [ i ] - 1. lis [ i ] == > Longest Increasing subsequence ending with arr [ i ] lds [ i ] == > Longest decreasing subsequence starting with arr [ i ] ; Allocate memory for LIS [ ] and initialize LIS values as 1 for all indexes ; Compute LIS values from left to right ; Allocate memory for lds and initialize LDS values for all indexes ; Compute LDS values from right to left ; Return the maximum value of lis [ i ] + lds [ i ] - 1 ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function lbs ( & $ arr , $ n ) { $ lis = array_fill ( 0 , $ n , NULL ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ lis [ $ i ] = 1 ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) for ( $ j = 0 ; $ j < $ i ; $ j ++ ) if ( $ arr [ $ i ] > $ arr [ $ j ] && $ lis [ $ i ] < $ lis [ $ j ] + 1 ) $ lis [ $ i ] = $ lis [ $ j ] + 1 ; $ lds = array_fill ( 0 , $ n , NULL ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ lds [ $ i ] = 1 ; for ( $ i = $ n - 2 ; $ i >= 0 ; $ i -- ) for ( $ j = $ n - 1 ; $ j > $ i ; $ j -- ) if ( $ arr [ $ i ] > $ arr [ $ j ] && $ lds [ $ i ] < $ lds [ $ j ] + 1 ) $ lds [ $ i ] = $ lds [ $ j ] + 1 ; $ max = $ lis [ 0 ] + $ lds [ 0 ] - 1 ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) if ( $ lis [ $ i ] + $ lds [ $ i ] - 1 > $ max ) $ max = $ lis [ $ i ] + $ lds [ $ i ] - 1 ; return $ max ; } $ arr = array ( 0 , 8 , 4 , 12 , 2 , 10 , 6 , 14 , 1 , 9 , 5 , 13 , 3 , 11 , 7 , 15 ) ; $ n = sizeof ( $ arr ) ; echo \\\" Length ▁ of ▁ LBS ▁ is ▁ \\\" . lbs ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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\\\"\\nHow can the above be solved 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 ▁ a ▁ subset \\\" + \\\" ▁ with ▁ given ▁ sum \\\" ) ; else System . out . println ( \\\" No ▁ subset ▁ with \\\" + \\\" ▁ given ▁ sum \\\" ) ; } }\",\"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 | CPP program to calculate area of a trapezoid ; Function for the area ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\ndouble Area ( int b1 , int b2 , int h ) { return ( ( b1 + b2 ) \\/ 2 ) * h ; } int main ( ) { int base1 = 8 , base2 = 10 , height = 6 ; double area = Area ( base1 , base2 , height ) ; printf ( \\\" Area ▁ is : ▁ % .1lf \\\" , area ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count composite fibonacci numbers from given array | C ++ 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\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; set < int > createhashmap ( int Max ) { set < int > hashmap ; int curr = 1 ; int prev = 0 ; hashmap . insert ( prev ) ; while ( curr <= Max ) { hashmap . insert ( curr ) ; int temp = curr ; curr = curr + prev ; prev = temp ; } return hashmap ; } vector < bool > SieveOfEratosthenes ( int Max ) { vector < bool > isPrime ( Max , 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 ; } } } return isPrime ; } int cntFibonacciPrime ( int arr [ ] , int N ) { int Max = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { Max = max ( Max , arr [ i ] ) ; } vector < bool > isPrime = SieveOfEratosthenes ( Max ) ; set < int > hashmap = createhashmap ( Max ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) continue ; if ( ( hashmap . count ( arr [ i ] ) ) && ! isPrime [ arr [ i ] ] ) { cout << arr [ i ] << \\\" ▁ \\\" ; } } } int main ( ) { int arr [ ] = { 13 , 55 , 7 , 3 , 5 , 21 , 233 , 144 , 89 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cntFibonacciPrime ( arr , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum difference between groups of size two | PHP program to find minimum difference between groups of highest and lowest sums . ; Sorting the whole array . ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function CalculateMax ( $ arr , $ n ) { sort ( $ arr ) ; $ min_sum = $ arr [ 0 ] + $ arr [ 1 ] ; $ max_sum = $ arr [ $ n - 1 ] + $ arr [ $ n - 2 ] ; return abs ( $ max_sum - $ min_sum ) ; } $ arr = array ( 6 , 7 , 1 , 11 ) ; $ n = sizeof ( $ arr ) ; echo CalculateMax ( $ arr , $ n ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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\":\"\\\"Count of alphabets having ASCII value less than and greater than k | Function to count the number of characters whose ascii value is less than k ; Initialising the count to 0 ; Incrementing the count if the value is less ; return the count ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def CountCharacters ( str , k ) :\\n\\tcnt = 0\\n\\tl = len ( str )\\n\\tfor i in range ( l ) :\\n\\t\\tif ( ord ( str [ i ] ) < k ) :\\n\\t\\t\\tcnt += 1\\n\\treturn cnt\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tstr = \\\" GeeksForGeeks \\\"\\n\\tk = 90\\n\\tcount = CountCharacters ( str , k )\\n\\tprint ( \\\" Characters ▁ with ▁ ASCII ▁ values \\\" , \\\" less ▁ than ▁ K ▁ are \\\" , count )\\n\\tprint ( \\\" Characters ▁ with ▁ ASCII ▁ values \\\" , \\\" greater ▁ than ▁ or ▁ equal ▁ to ▁ K ▁ are \\\" , len ( str ) - count )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\\"\\nSolution 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 ▁ Point ▁ is ▁ % d \\\" , linearSearch ( arr , n ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximize length of longest subarray consisting of same elements by at most K decrements | Python3 program to implement the above approach ; Function to construct Segment Tree to return the minimum element in a range ; If leaf nodes of the tree are found ; Update the value in segment tree from given array ; Divide left and right subtree ; Stores smallest element in subarray : arr [ start ] , arr [ mid ] ; Stores smallest element in subarray : arr [ mid + 1 ] , arr [ end ] ; Stores smallest element in subarray : arr [ start ] , arr [ end ] ; Function to find the smallest element present in a subarray ; If elements of the subarray are not in the range [ l , r ] ; If all the elements of the subarray are in the range [ l , r ] ; Divide tree into left and right subtree ; Stores smallest element in left subtree ; Stores smallest element in right subtree ; Function that find length of longest subarray with all equal elements in atmost K decrements ; Stores length of longest subarray with all equal elements in atmost K decrements . ; Store the prefix sum array ; Calculate the prefix sum array ; Build the segment tree for range min query ; Traverse the array ; Stores start index of the subarray ; Stores end index of the subarray ; Stores end index of the longest subarray ; Performing the binary search to find the endpoint for the selected range ; Find the mid for binary search ; Find the smallest element in range [ i , mid ] using Segment Tree ; Stores total sum of subarray after K decrements ; Stores sum of elements of subarray before K decrements ; If subarray found with all equal elements ; Update start ; Update max_index ; If false , it means that the selected range is invalid ; Update end ; Store the length of longest subarray ; Return result ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"import sys\\ndef build ( tree , A , start , end , node ) :\\n\\tif ( start == end ) :\\n\\t\\ttree [ node ] = A [ start ]\\n\\t\\treturn tree [ node ]\\n\\tmid = ( int ) ( ( start + end ) \\/ 2 )\\n\\tX = build ( tree , A , start , mid , 2 * node + 1 )\\n\\tY = build ( tree , A , mid + 1 , end , 2 * node + 2 )\\n\\treturn ( tree [ node ] == min ( X , Y ) )\\ndef query ( tree , start , end , l , r , node ) :\\n\\tif ( start > r or end < l ) :\\n\\t\\treturn sys . maxsize\\n\\tif ( start >= l and end <= r ) :\\n\\t\\treturn tree [ node ]\\n\\tmid = ( int ) ( ( start + end ) \\/ 2 )\\n\\tX = query ( tree , start , mid , l , r , 2 * node + 1 )\\n\\tY = query ( tree , mid + 1 , end , l , r , 2 * node + 2 )\\n\\treturn min ( X , Y )\\ndef longestSubArray ( A , N , K ) :\\n\\tres = 1\\n\\tpreSum = [ 0 ] * ( N + 1 )\\n\\tpreSum [ 0 ] = A [ 0 ]\\n\\tfor i in range ( N ) :\\n\\t\\tpreSum [ i + 1 ] = preSum [ i ] + A [ i ]\\n\\ttree = [ 0 ] * ( 4 * N + 5 )\\n\\tbuild ( tree , A , 0 , N - 1 , 0 )\\n\\tfor i in range ( N ) :\\n\\t\\tstart = i\\n\\t\\tend = N - 1\\n\\t\\tmax_index = i\\n\\t\\twhile ( start <= end ) :\\n\\t\\t\\tmid = ( int ) ( ( start + end ) \\/ 2 )\\n\\t\\t\\tmin_element = query ( tree , 0 , N - 1 , i , mid , 0 )\\n\\t\\t\\texpected_sum = ( mid - i + 1 ) * min_element\\n\\t\\t\\tactual_sum = preSum [ mid + 1 ] - preSum [ i ]\\n\\t\\t\\tif ( actual_sum - expected_sum <= K ) :\\n\\t\\t\\t\\tstart = mid + 1\\n\\t\\t\\t\\tmax_index = max ( max_index , mid )\\n\\t\\t\\telse :\\n\\t\\t\\t\\tend = mid - 1\\n\\t\\tres = max ( res , max_index - i + 2 )\\n\\treturn res\\narr = [ 1 , 7 , 3 , 4 , 5 , 6 ]\\nk = 6\\nn = 6\\nprint ( longestSubArray ( arr , n , k ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\\"\\nHow can the above be solved 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\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 ; Precomputing the countDP prefix sum of the matrix ; Loop to solve Queries ; Calculating the maximum possible distance of the centre from edge ; Calculating the number of 1 s in the submatrix ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void largestSquare ( int [ , ] matrix , int R , int C , int [ ] q_i , int [ ] q_j , int K , int Q ) { int [ , ] countDP = new int [ R , C ] ; 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 = Math . Min ( Math . Min ( i , j ) , Math . Min ( R - i - 1 , C - j - 1 ) ) ; int ans = - 1 ; for ( int k = 0 ; k <= min_dist ; k ++ ) { int x1 = i - k , x2 = i + k ; int y1 = j - k , y2 = j + k ; 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 ) break ; ans = 2 * k + 1 ; } Console . Write ( ans + \\\" \\n \\\" ) ; } } public static void Main ( String [ ] args ) { int [ , ] matrix = { { 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 ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Reverse vowels in a given string | utility function to check for vowel ; Function to reverse order of vowels ; Start two indexes from two corners and move toward each other ; swapping ; Driver function\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function isVowel ( c ) { return ( c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' ) ; } function reverseVowel ( str ) { let i = 0 ; let j = str . length - 1 ; let str1 = str . split ( \\\" \\\" ) ; while ( i < j ) { if ( ! isVowel ( str1 [ i ] ) ) { i ++ ; continue ; } if ( ! isVowel ( str1 [ j ] ) ) { j -- ; continue ; } let t = str1 [ i ] ; str1 [ i ] = str1 [ j ] ; str1 [ j ] = t ; i ++ ; j -- ; } let str2 = ( str1 ) . join ( \\\" \\\" ) ; return str2 ; } let str = \\\" \\\" ; document . write ( reverseVowel ( str ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"DFA for Strings not ending with \\\" THE \\\" | C program to implement DFS that accepts all string that do not end with \\\" THE \\\" ; dfa tells the number associated with the present state ; This function is for the starting state ( zeroth ) of DFA ; On receiving ' T ' or ' t ' goto first state ( 1 ) ; This function is for the first state of DFA ; On receiving ' T ' or ' t ' goto first state ( 1 ) ; On receiving ' H ' or ' h ' goto second state ( 2 ) ; else goto starting state ( 0 ) ; This function is for the second state of DFA ; On receiving ' E ' or ' e ' goto third state ( 3 ) else goto starting state ( 0 ) ; This function is for the third state of DFA ; On receiving ' T ' or ' t ' goto first state ( 1 ) else goto starting state ( 0 ) ; store length of string ; driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nint dfa = 0 ; void start ( char c ) { if ( c == ' t ' c == ' T ' ) dfa = 1 ; } void state1 ( char c ) { if ( c == ' t ' c == ' T ' ) dfa = 1 ; else if ( c == ' h ' c == ' H ' ) dfa = 2 ; else dfa = 0 ; } void state2 ( char c ) { if ( c == ' e ' c == ' E ' ) dfa = 3 ; else if ( c == ' t ' c == ' T ' ) dfa = 1 ; else dfa = 0 ; } void state3 ( char c ) { if ( c == ' t ' c == ' T ' ) dfa = 1 ; else dfa = 0 ; } bool isAccepted ( char str [ ] ) { int len = strlen ( str ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( dfa == 0 ) start ( str [ i ] ) ; else if ( dfa == 1 ) state1 ( str [ i ] ) ; else if ( dfa == 2 ) state2 ( str [ i ] ) ; else state3 ( str [ i ] ) ; } return ( dfa != 3 ) ; } int main ( ) { char str [ ] = \\\" forTHEgeeks \\\" ; if ( isAccepted ( str ) == true ) printf ( \\\" ACCEPTED \\n \\\" ) ; else printf ( \\\" NOT ▁ ACCEPTED \\n \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"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\":\"\\\"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\\\"\\nSolution 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 ▁ distance ▁ is ▁ % 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\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to calculate distance between two points | C ++ code to compute distance ; Function to calculate distance ; Calculating distance ; Drivers Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; float distance ( int x1 , int y1 , int x2 , int y2 ) { return sqrt ( pow ( x2 - x1 , 2 ) + pow ( y2 - y1 , 2 ) * 1.0 ) ; } int main ( ) { cout << distance ( 3 , 4 , 4 , 3 ) ; 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 | PHP 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 php:\",\"targets\":\"< ? php $ N = 1000005 ; function isPrime ( $ n ) { global $ 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 SumOfPrimeDivisors ( $ n ) { $ sum = 0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { if ( $ n % $ i == 0 ) { if ( isPrime ( $ i ) ) $ sum += $ i ; } } return $ sum ; } $ n = 60 ; echo \\\" Sum ▁ of ▁ prime ▁ divisors ▁ of ▁ 60 ▁ is ▁ \\\" . SumOfPrimeDivisors ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"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\":\"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\":\"\\\"Lexicographically smallest K | C ++ program for the above approach ; Function to find lexicographically smallest subsequence of size K ; Length of string ; Stores the minimum subsequence ; Traverse the string S ; If the stack is empty ; Iterate till the current character is less than the the character at the top of stack ; Check if there are enough characters remaining to obtain length K ; If stack size is < K ; Push the current character into it ; Stores the resultant string ; Iterate until stack is empty ; Reverse the string ; Print the string ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void smallestSubsequence ( string & S , int K ) { int N = S . size ( ) ; stack < char > answer ; for ( int i = 0 ; i < N ; ++ i ) { if ( answer . empty ( ) ) { answer . push ( S [ i ] ) ; } else { while ( ( ! answer . empty ( ) ) && ( S [ i ] < answer . top ( ) ) && ( answer . size ( ) - 1 + N - i >= K ) ) { answer . pop ( ) ; } if ( answer . empty ( ) || answer . size ( ) < K ) { answer . push ( S [ i ] ) ; } } } string ret ; while ( ! answer . empty ( ) ) { ret . push_back ( answer . top ( ) ) ; answer . pop ( ) ; } reverse ( ret . begin ( ) , ret . end ( ) ) ; cout << ret ; } int main ( ) { string S = \\\" aabdaabc \\\" ; int K = 3 ; smallestSubsequence ( S , K ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find the two repeating elements in a given array | printRepeating function ; S is for sum of elements in arr ; P is for product of elements in arr ; x and y are two repeating elements ; D is for difference of x and y , i . e . , x - y ; Calculate Sum and Product of all elements in arr ; S is x + y now ; P is x * y now ; D is x - y now ; factorial of n ; driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function printRepeating ( arr , size ) { var S = 0 ; var P = 1 ; var x , y ; var D ; var n = size - 2 , i ; for ( i = 0 ; i < size ; i ++ ) { S = S + arr [ i ] ; P = P * arr [ i ] ; } S = S - n * parseInt ( ( n + 1 ) \\/ 2 ) ; P = parseInt ( P \\/ fact ( n ) ) ; D = parseInt ( Math . sqrt ( S * S - 4 * P ) ) ; x = parseInt ( ( D + S ) \\/ 2 ) ; y = parseInt ( ( S - D ) \\/ 2 ) ; document . write ( \\\" \\\" ) ; document . write ( x + \\\" \\\" + y ) ; } function fact ( n ) { var ans = false ; if ( n == 0 ) return 1 ; else return ( n * fact ( n - 1 ) ) ; } var arr = [ 4 , 2 , 4 , 5 , 2 , 3 , 1 ] ; var arr_size = arr . length ; printRepeating ( arr , arr_size ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if N and M can be made equal by increasing N by A and decreasing M by B | C # program to check if two numbers can be made equal by increasing the first by a and decreasing the second by b ; Function to whether the numbers can be made equal or not ; Check whether the numbers can reach an equal point or not ; M and N cannot be made equal by increasing M and decreasing N when M is already greater than N ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static bool checkEqualNo ( int m , int n , int a , int b ) { if ( m <= n ) { if ( ( n - m ) % ( a + b ) == 0 ) { return true ; } else { return false ; } } else { return false ; } } public static void Main ( String [ ] args ) { int M = 2 ; int N = 8 ; int A = 3 ; int B = 3 ; if ( checkEqualNo ( M , N , A , B ) == true ) Console . WriteLine ( \\\" Yes \\\" ) ; else Console . WriteLine ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count of pairs of ( i , j ) such that ( ( n % i ) % j ) % n is maximized | C # implementation of above approach ; Function to return the count of required pairs ; Special case ; Number which will give the max value for ( ( n % i ) % j ) % n ; To store the maximum possible value of ( ( n % i ) % j ) % n ; Count of possible pairs ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int countPairs ( int n ) { if ( n == 2 ) return 4 ; int num = ( ( n \\/ 2 ) + 1 ) ; int max = n % num ; int count = n - max ; return count ; } static public void Main ( ) { int n = 5 ; Console . WriteLine ( countPairs ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimum steps to reduce N to 0 by given operations | Java program for the above approach ; 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 ; Driver Code ; Given number N ; Function call\\\"\\nSolution in Java:\",\"targets\":\"import java . util . HashMap ; class GFG { static int count ( int n ) { HashMap < Integer , Integer > dp = new HashMap < Integer , Integer > ( ) ; dp . put ( 0 , 0 ) ; dp . put ( 1 , 1 ) ; if ( ! dp . containsKey ( n ) ) dp . put ( n , 1 + Math . min ( n % 2 + count ( n \\/ 2 ) , n % 3 + count ( n \\/ 3 ) ) ) ; return dp . get ( n ) ; } public static void main ( String [ ] args ) { int N = 6 ; System . out . println ( String . valueOf ( ( count ( N ) ) ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all distances between occurrences of same characters in a given string | C ++ program for the above approach ; Function to calculate the sum of distances between occurrences of same characters in a string ; If similar characters are found ; Add the difference of their positions ; Return the answer ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int findSum ( string s ) { int sum = 0 ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { for ( int j = i + 1 ; j < s . size ( ) ; j ++ ) { if ( s [ i ] == s [ j ] ) { sum += ( j - i ) ; } } } return sum ; } int main ( ) { string s = \\\" ttt \\\" ; cout << findSum ( s ) << endl ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if a large number is divisible by 2 , 3 and 5 or not | Java program to Check if a large number is divisible by 2 , 3 and 5 or not . ; function to return sum of digits of a number ; function to Check if a large number is divisible by 2 , 3 and 5 or not ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int SumOfDigits ( String str , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += ( int ) ( str . charAt ( i ) - '0' ) ; return sum ; } static boolean Divisible ( String str , int n ) { if ( SumOfDigits ( str , n ) % 3 == 0 && str . charAt ( n - 1 ) == '0' ) return true ; return false ; } public static void main ( String [ ] args ) { String str = \\\"263730746028908374890\\\" ; int n = str . length ( ) ; if ( Divisible ( str , 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\":\"\\\"Intersecting rectangle when bottom | C # program to find intersection rectangle of given two rectangles . ; 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 ; Driver code ; bottom - left and top - right corners of first rectangle ; bottom - left and top - right corners of first rectangle ; function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void FindPoints ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 , int x4 , int y4 ) { int x5 = Math . Max ( x1 , x3 ) ; int y5 = Math . Max ( y1 , y3 ) ; int x6 = Math . Min ( x2 , x4 ) ; int y6 = Math . Min ( y2 , y4 ) ; if ( x5 > x6 y5 > y6 ) { Console . WriteLine ( \\\" No ▁ intersection \\\" ) ; return ; } Console . Write ( \\\" ( \\\" + x5 + \\\" , ▁ \\\" + y5 + \\\" ) ▁ \\\" ) ; Console . Write ( \\\" ( \\\" + x6 + \\\" , ▁ \\\" + y6 + \\\" ) ▁ \\\" ) ; int x7 = x5 ; int y7 = y6 ; Console . Write ( \\\" ( \\\" + x7 + \\\" , ▁ \\\" + y7 + \\\" ) ▁ \\\" ) ; int x8 = x6 ; int y8 = y5 ; Console . Write ( \\\" ( \\\" + x8 + \\\" , ▁ \\\" + y8 + \\\" ) ▁ \\\" ) ; } public static void Main ( ) { int x1 = 0 , y1 = 0 , x2 = 10 , y2 = 8 ; int x3 = 2 , y3 = 3 , x4 = 7 , y4 = 9 ; FindPoints ( x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Construct Special Binary Tree from given Inorder traversal | program to construct tree from inorder traversal ; A binary tree node has data , pointer to left child and a pointer to right child ; Prototypes of a utility function to get the maximum value in inorder [ start . . end ] ; Recursive function to construct binary of size len from Inorder traversal inorder [ ] . Initial values of start and end should be 0 and len - 1. ; Find index of the maximum element from Binary Tree ; Pick the maximum value and make it root ; If this is the only element in inorder [ start . . end ] , then return it ; Using index in Inorder traversal , construct left and right subtress ; Function to find index of the maximum value in arr [ start ... end ] ; Helper function that allocates a new node with the given data and NULL left and right pointers . ; This funtcion is here just to test buildTree ( ) ; first recur on left child ; then print the data of node ; now recur on right child ; Driver program to test above functions ; Assume that inorder traversal of following tree is given 40 \\/ \\\\ 10 30 \\/ \\\\ 5 28 ; Let us test the built tree by printing Insorder traversal\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nstruct node { int data ; struct node * left ; struct node * right ; } ; int max ( int inorder [ ] , int strt , int end ) ; struct node * newNode ( int data ) ; struct node * buildTree ( int inorder [ ] , int start , int end ) { if ( start > end ) return NULL ; int i = max ( inorder , start , end ) ; struct node * root = newNode ( inorder [ i ] ) ; if ( start == end ) return root ; root -> left = buildTree ( inorder , start , i - 1 ) ; root -> right = buildTree ( inorder , i + 1 , end ) ; return root ; } int max ( int arr [ ] , int strt , int end ) { int i , max = arr [ strt ] , maxind = strt ; for ( i = strt + 1 ; i <= end ; i ++ ) { if ( arr [ i ] > max ) { max = arr [ i ] ; maxind = i ; } } return maxind ; } 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 printInorder ( struct node * node ) { if ( node == NULL ) return ; printInorder ( node -> left ) ; printf ( \\\" % d ▁ \\\" , node -> data ) ; printInorder ( node -> right ) ; } int main ( ) { int inorder [ ] = { 5 , 10 , 40 , 30 , 28 } ; int len = sizeof ( inorder ) \\/ sizeof ( inorder [ 0 ] ) ; struct node * root = buildTree ( inorder , 0 , len - 1 ) ; printf ( \\\" Inorder traversal of the constructed tree is \\\" printInorder ( root ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of operations required to reduce N to 0 | Function to count the minimum steps required to reduce n ; Base case ; Allocate memory for storing intermediate results ; Store base values ; Stores square root of each number ; Compute square root ; Use rule 1 to find optimized answer ; Check if it perfectly divides n ; Use of rule 2 to find the optimized answer ; Store computed value ; Return answer ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function downToZero ( n ) { if ( n <= 3 ) return n ; let dp = new Array ( n + 1 ) dp . fill ( - 1 ) ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; dp [ 2 ] = 2 ; dp [ 3 ] = 3 ; let sqr ; for ( let i = 4 ; i <= n ; i ++ ) { sqr = Math . sqrt ( i ) ; let best = Number . MAX_VALUE ; while ( sqr > 1 ) { if ( i % sqr == 0 ) { best = Math . min ( best , 1 + dp [ sqr ] ) ; } sqr -- ; } best = Math . min ( best , 1 + dp [ i - 1 ] ) ; dp [ i ] = best ; } return dp [ n ] ; } let n = 4 ; document . write ( downToZero ( n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Randomized Binary Search Algorithm | To generate random number between x and y ie . . [ x , y ] ; A iterative randomized binary search function . It returns location of x in given array arr [ l . . r ] if present , otherwise - 1 ; Here we have defined middle as random index between l and r ie . . [ l , r ] ; Check if x is present at mid ; If x greater , ignore left half ; If x is smaller , ignore right half ; If we reach here , then element was not present ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function getRandom ( x , y ) { return Math . floor ( x + Math . floor ( Math . random ( ) * 10 ) % ( y - x + 1 ) ) ; } function randomizedBinarySearch ( arr , l , r , x ) { while ( l <= r ) { let m = getRandom ( l , r ) ; if ( arr [ m ] == x ) return m ; if ( arr [ m ] < x ) l = m + 1 ; else r = m - 1 ; } return - 1 ; } let arr = [ 2 , 3 , 4 , 10 , 40 ] ; let n = arr . length ; let x = 10 ; let result = randomizedBinarySearch ( arr , 0 , n - 1 , x ) ; if ( result == - 1 ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" , result ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Nth term of Ruler Function Series | C # program for the above approach ; Function to count the number of set bits in the number N ; Store the number of setbits ; Update the value of n ; Update the count ; Return the total count ; Function to find the Nth term of the Ruler Function Series ; Store the result ; Print the result ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int setBits ( long n ) { int count = 0 ; while ( n > 0 ) { n = n & ( n - 1 ) ; count ++ ; } return count ; } static void findNthTerm ( int N ) { int x = setBits ( N ^ ( N - 1 ) ) ; Console . WriteLine ( x ) ; } public static void Main ( string [ ] args ) { int N = 8 ; findNthTerm ( N ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Insert minimum number in array so that sum of array becomes prime | function to check if a number is prime or not ; Corner case ; Check from 2 to n - 1 ; Find prime number greater than a number ; find prime greater than n ; check if num is prime ; Increment num ; To find number to be added so sum of array is prime ; To find sum of array elements ; If sum is already prime return 0 ; To find prime number greater than sum ; Return difference of sum and num ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def isPrime ( n ) :\\n\\tif n <= 1 :\\n\\t\\treturn False\\n\\tfor i in range ( 2 , n ) :\\n\\t\\tif n % i == 0 :\\n\\t\\t\\treturn False\\n\\treturn True\\ndef findPrime ( n ) :\\n\\tnum = n + 1\\n\\twhile ( num ) :\\n\\t\\tif isPrime ( num ) :\\n\\t\\t\\treturn num\\n\\t\\tnum += 1\\n\\treturn 0\\ndef minNumber ( arr ) :\\n\\ts = 0\\n\\tfor i in range ( 0 , len ( arr ) ) :\\n\\t\\ts += arr [ i ]\\n\\tif isPrime ( s ) :\\n\\t\\treturn 0\\n\\tnum = findPrime ( s )\\n\\treturn num - s\\narr = [ 2 , 4 , 6 , 8 , 12 ]\\nprint ( minNumber ( arr ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program to find transpose of a matrix | C # Program to find transpose of a matrix ; Finds transpose of A [ ] [ ] in - place ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int N = 4 ; static void transpose ( int [ , ] A ) { for ( int i = 0 ; i < N ; i ++ ) for ( int j = i + 1 ; j < N ; j ++ ) { int temp = A [ i , j ] ; A [ i , j ] = A [ j , i ] ; A [ j , i ] = temp ; } } public static void Main ( ) { int [ , ] A = { { 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 } } ; transpose ( A ) ; Console . WriteLine ( \\\" Modified ▁ matrix ▁ is ▁ \\\" ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) Console . Write ( A [ i , j ] + \\\" ▁ \\\" ) ; Console . WriteLine ( ) ; } } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count smaller elements on right side | ; initialize all the counts in countSmaller array as 0 ; Utility function that prints out an array on a line ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"void constructLowerArray ( int * arr [ ] , int * countSmaller , int n ) { int i , j ; for ( i = 0 ; i < n ; i ++ ) countSmaller [ i ] = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] < arr [ i ] ) countSmaller [ i ] ++ ; } } } void printArray ( int arr [ ] , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) printf ( \\\" % d ▁ \\\" , arr [ i ] ) ; printf ( \\\" \\n \\\" ) ; } int main ( ) { int arr [ ] = { 12 , 10 , 5 , 4 , 2 , 20 , 6 , 1 , 0 , 2 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int * low = ( int * ) malloc ( sizeof ( int ) * n ) ; constructLowerArray ( arr , low , n ) ; printArray ( low , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if given four integers ( or sides ) make rectangle | Function to check if the given integers value make a rectangle ; Square is also a rectangle ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function isRectangle ( a , b , c , d ) { if ( a == b && a == c && a == d && c == d && b == c && b == 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 ; } let a = 1 , b = 2 , c = 3 , d = 4 ; if ( isRectangle ( a , b , c , d ) ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Majority Element | Function to find Majority element in an array ; sentinels ; update maxCount if count of current element is greater ; if maxCount is greater than n \\/ 2 return the corresponding element ; Driver code ; Function calling\\\"\\nSolution in php:\",\"targets\":\"< ? php function findMajority ( $ arr , $ n ) { $ maxCount = 0 ; $ index = -1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ count = 0 ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { if ( $ arr [ $ i ] == $ arr [ $ j ] ) $ count ++ ; } if ( $ count > $ maxCount ) { $ maxCount = $ count ; $ index = $ i ; } } if ( $ maxCount > $ n \\/ 2 ) echo $ arr [ $ index ] . \\\" \\n \\\" ; else echo \\\" No ▁ Majority ▁ Element \\\" . \\\" \\n \\\" ; } $ arr = array ( 1 , 1 , 2 , 1 , 3 , 5 , 1 ) ; $ n = sizeof ( $ arr ) ; findMajority ( $ arr , $ n ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find K consecutive integers such that their sum is N | Function to check if a number can be expressed as the sum of k consecutive ; Finding the first term of AP ; Checking if first term is an integer ; Loop to prvar the K consecutive integers ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function checksum ( n , k ) { var first_term = ( ( ( 2 * n ) \\/ k + ( 1 - k ) ) \\/ 2.0 ) ; if ( first_term - parseInt ( ( first_term ) ) == 0 ) { for ( i = parseInt ( first_term ) ; i <= first_term + k - 1 ; i ++ ) { document . write ( i + \\\" \\\" ) ; } } else document . write ( \\\" \\\" ) ; } var n = 33 , k = 6 ; checksum ( n , k ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"Program to find GCD or HCF of two numbers | C program to find GCD of two numbers ; Recursive function to return gcd of a and b ; Driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } int main ( ) { int a = 98 , b = 56 ; printf ( \\\" GCD ▁ of ▁ % d ▁ and ▁ % d ▁ is ▁ % d ▁ \\\" , a , b , gcd ( a , b ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Rabin | d is the number of characters in the input alphabet ; pat -> pattern txt -> text q -> A prime number ; hash value for pattern t = 0 hash value for txt ; The value of h would be \\\" pow ( d , ▁ M - 1 ) % q \\\" ; Calculate the hash value of pattern and first window of text ; Slide the pattern over text one by one ; Check the hash values of current window of text and pattern if the hash values match then only check for characters on by one ; Check for characters one by one ; if p == t and pat [ 0. . . M - 1 ] = txt [ i , i + 1 , ... i + M - 1 ] ; Calculate hash value for next window of text : Remove leading digit , add trailing digit ; We might get negative values of t , converting it to positive ; Driver Code ; A prime number ; Function Call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"d = 256\\ndef search ( pat , txt , q ) :\\n\\tM = len ( pat )\\n\\tN = len ( txt )\\n\\ti = 0\\n\\tj = 0\\n\\th = 1\\n\\tfor i in xrange ( M - 1 ) :\\n\\t\\th = ( h * d ) % q\\n\\tfor i in xrange ( M ) :\\n\\t\\tp = ( d * p + ord ( pat [ i ] ) ) % q\\n\\t\\tt = ( d * t + ord ( txt [ i ] ) ) % q\\n\\tfor i in xrange ( N - M + 1 ) :\\n\\t\\tif p == t :\\n\\t\\t\\tfor j in xrange ( M ) :\\n\\t\\t\\t\\tif txt [ i + j ] != pat [ j ] :\\n\\t\\t\\t\\t\\tbreak\\n\\t\\t\\t\\telse : j += 1\\n\\t\\t\\tif j == M :\\n\\t\\t\\t\\tprint \\\" Pattern ▁ found ▁ at ▁ index ▁ \\\" + str ( i )\\n\\t\\tif i < N - M :\\n\\t\\t\\tt = ( d * ( t - ord ( txt [ i ] ) * h ) + ord ( txt [ i + M ] ) ) % q\\n\\t\\t\\tif t < 0 :\\n\\t\\t\\t\\tt = t + q\\ntxt = \\\" GEEKS ▁ FOR ▁ GEEKS \\\"\\npat = \\\" GEEK \\\"\\nq = 101\\nsearch ( pat , txt , q )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Maximum sum from a tree with adjacent levels not allowed | Tree node class for Binary Tree representation ; Recursive function to find the maximum sum returned for a root node and its grandchildren ; Returns maximum sum with adjacent levels not allowed . This function mainly uses getSumAlternate ( ) ; We compute sum of alternate levels starting first level and from second level . And return maximum of two values . ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"class Node { constructor ( data ) { this . data = data ; this . left = this . right = null ; } } function getSumAlternate ( root ) { if ( root == null ) return 0 ; let sum = root . data ; if ( root . left != null ) { sum += getSum ( root . left . left ) ; sum += getSum ( root . left . right ) ; } if ( root . right != null ) { sum += getSum ( root . right . left ) ; sum += getSum ( root . right . right ) ; } return sum ; } function getSum ( root ) { if ( root == null ) return 0 ; return Math . max ( getSumAlternate ( root ) , ( getSumAlternate ( root . left ) + getSumAlternate ( root . right ) ) ) ; } let root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . right . left = new Node ( 4 ) ; root . right . left . right = new Node ( 5 ) ; root . right . left . right . left = new Node ( 6 ) ; document . write ( getSum ( root ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Number of ways to reach at starting node after travelling through exactly K edges in a complete graph | Java program for the above approach ; Function to find number of ways to reach from node 1 to 1 again , after moving exactly K edges ; Initialize a dp [ ] array , where dp [ i ] stores number of ways to reach at a i node ; Initialize the dp array with 0 ; Base Case ; Iterate for the number of edges moved ; Sum will store number of ways to reach all the nodes ; Iterate for every possible state for the current step ; Update the value of the dp array after travelling each edge ; Print dp [ 0 ] as the answer ; Driver Code ; Given Input ; Function Call\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static void numberOfWays ( int n , int k ) { int [ ] dp = new int [ 1000 ] ; for ( int i = 0 ; i < n ; i ++ ) { dp [ i ] = 0 ; } dp [ 0 ] = 1 ; for ( int i = 1 ; i <= k ; i ++ ) { int numWays = 0 ; for ( int j = 0 ; j < n ; j ++ ) { numWays += dp [ j ] ; } for ( int j = 0 ; j < n ; j ++ ) { dp [ j ] = numWays - dp [ j ] ; } } System . out . println ( dp [ 0 ] + \\\"\\n\\\"); } public static void main ( String args [ ] ) { int N = 5 , K = 3 ; numberOfWays ( N , K ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sum of absolute differences of indices of occurrences of each array element | Set 2 | Stores the count of occurrences and previous index of every element ; Constructor ; Function to calculate the sum of absolute differences of indices of occurrences of array element ; Stores the count of elements and their previous indices ; Initialize 2 arrays left [ ] and right [ ] of size N ; Traverse the given array ; If arr [ i ] is present in the Map ; Update left [ i ] to 0 and update the value of arr [ i ] in map ; Otherwise , get the value from the map and update left [ i ] ; Clear the map to calculate right [ ] array ; Traverse the array arr [ ] in reverse ; If arr [ i ] is present in theMap ; Update right [ i ] to 0 and update the value of arr [ i ] in the Map ; Otherwise get the value from the map and update right [ i ] ; Iterate in the range [ 0 , N - 1 ] and print the sum of left [ i ] and right [ i ] as the result ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"class pair { constructor ( count , prevIndex ) { this . count = count ; this . prevIndex = prevIndex ; } } function findSum ( arr , n ) { let map = new Map ( ) ; let left = new Array ( n ) ; let right = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! map . has ( arr [ i ] ) ) { left [ i ] = 0 ; map . set ( arr [ i ] , new pair ( 1 , i ) ) ; } else { let tmp = map . get ( arr [ i ] ) ; left [ i ] = ( tmp . count ) * ( i - tmp . prevIndex ) + left [ tmp . prevIndex ] ; map . set ( arr [ i ] , new pair ( tmp . count + 1 , i ) ) ; } } map . clear ( ) ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( ! map . has ( arr [ i ] ) ) { right [ i ] = 0 ; map . set ( arr [ i ] , new pair ( 1 , i ) ) ; } else { let tmp = map . get ( arr [ i ] ) ; right [ i ] = ( tmp . count ) * ( Math . abs ( i - tmp . prevIndex ) ) + right [ tmp . prevIndex ] ; map . set ( arr [ i ] , new pair ( tmp . count + 1 , i ) ) ; } } for ( let i = 0 ; i < n ; i ++ ) document . write ( left [ i ] + right [ i ] + \\\" \\\" ) ; } let arr = [ 1 , 3 , 1 , 1 , 2 ] ; let N = arr . length ; findSum ( arr , N ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Remove an element to minimize the LCM of the given array | Java implementation of the above approach ; Function to return the LCM of two numbers ; Function to return the minimum LCM after removing a single element from the given array ; Prefix and Suffix arrays ; Single state dynamic programming relation for storing LCM of first i elements from the left in Prefix [ i ] ; Initializing Suffix array ; Single state dynamic programming relation for storing LCM of all the elements having index greater than or equal to i in Suffix [ i ] ; If first or last element of the array has to be removed ; If any other element is replaced ; Return the minimum LCM ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int lcm ( int a , int b ) { int GCD = __gcd ( a , b ) ; return ( a * b ) \\/ GCD ; } static int MinLCM ( int a [ ] , int n ) { int [ ] Prefix = new int [ n + 2 ] ; int [ ] Suffix = new int [ n + 2 ] ; Prefix [ 1 ] = a [ 0 ] ; for ( int i = 2 ; i <= n ; i += 1 ) { Prefix [ i ] = lcm ( Prefix [ i - 1 ] , a [ i - 1 ] ) ; } Suffix [ n ] = a [ n - 1 ] ; for ( int i = n - 1 ; i >= 1 ; i -= 1 ) { Suffix [ i ] = lcm ( Suffix [ i + 1 ] , a [ i - 1 ] ) ; } int ans = Math . min ( Suffix [ 2 ] , Prefix [ n - 1 ] ) ; for ( int i = 2 ; i < n ; i += 1 ) { ans = Math . min ( ans , lcm ( Prefix [ i - 1 ] , Suffix [ i + 1 ] ) ) ; } return ans ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int a [ ] = { 5 , 15 , 9 , 36 } ; int n = a . length ; System . out . println ( MinLCM ( a , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Partition problem | DP | 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 JS?\",\"targets\":\"function findPartiion ( arr , n ) { let sum = 0 ; let i , j ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; let part = new Array ( parseInt ( sum \\/ 2 + 1 , 10 ) ) ; for ( i = 0 ; i <= parseInt ( sum \\/ 2 , 10 ) ; i ++ ) { part [ i ] = false ; } for ( i = 0 ; i < n ; i ++ ) { for ( j = parseInt ( sum \\/ 2 , 10 ) ; j >= arr [ i ] ; j -- ) { if ( part [ j - arr [ i ] ] == true j == arr [ i ] ) part [ j ] = true ; } } return part [ parseInt ( sum \\/ 2 , 10 ) ] ; } let arr = [ 1 , 3 , 3 , 2 , 3 , 2 ] ; let n = arr . length ; if ( findPartiion ( arr , n ) == true ) document . write ( \\\" \\\" + \\\" \\\" ) ; else document . write ( \\\" \\\" + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"K | Return the K - th smallest element . ; sort ( arr , arr + n ) ; ; Checking if k lies before 1 st element ; If k is the first element of array arr [ ] . ; If k is more than last element ; If first element of array is 1. ; Reducing k by numbers before arr [ 0 ] . ; Finding k 'th smallest element after removing array elements. ; Finding count of element between i - th and ( i - 1 ) - th element . ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function ksmallest ( $ arr , $ n , $ k ) { sort ( $ arr ) ; if ( $ k < $ arr [ 0 ] ) return $ k ; if ( $ k == $ arr [ 0 ] ) return $ arr [ 0 ] + 1 ; if ( $ k > $ arr [ $ n - 1 ] ) return $ k + $ n ; if ( $ arr [ 0 ] == 1 ) $ k -- ; else $ k -= ( $ arr [ 0 ] - 1 ) ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { $ c = $ arr [ $ i ] - $ arr [ $ i - 1 ] - 1 ; if ( $ k <= $ c ) return $ arr [ $ i - 1 ] + $ k ; else $ k -= $ c ; } return $ arr [ $ n - 1 ] + $ k ; } $ k = 1 ; $ arr = array ( 1 ) ; $ n = sizeof ( $ arr ) ; echo ksmallest ( $ arr , $ n , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Sum of prime numbers without odd prime digits | Java 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 Java?\",\"targets\":\"import java . util . * ; class GFG { static int MAX = 100005 ; static Vector < Integer > addPrimes ( ) { int n = MAX ; boolean [ ] prime = new boolean [ n + 1 ] ; Arrays . fill ( prime , 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 ; } } Vector < Integer > ans = new Vector < Integer > ( ) ; for ( int p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) ans . add ( p ) ; return ans ; } static boolean is_prime ( int n ) { return ( n == 3 n == 5 n == 7 ) ; } static int find_Sum ( int n ) { int sum = 0 ; Vector < Integer > v = addPrimes ( ) ; for ( int i = 0 ; i < v . size ( ) && n > 0 ; i ++ ) { int flag = 1 ; int a = v . get ( i ) ; while ( a != 0 ) { int d = a % 10 ; a = a \\/ 10 ; if ( is_prime ( d ) ) { flag = 0 ; break ; } } if ( flag == 1 ) { n -- ; sum = sum + v . get ( i ) ; } } return sum ; } public static void main ( String [ ] args ) { int n = 7 ; System . out . println ( find_Sum ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum removals to make array sum odd | Function to find minimum removals ; Count odd numbers ; If the counter is odd return 0 otherwise return 1 ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function findCount ( $ arr , $ n ) { $ countOdd = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( $ arr [ $ i ] % 2 == 1 ) $ countOdd ++ ; if ( $ countOdd % 2 == 0 ) return 1 ; else return 0 ; } $ arr = array ( 1 , 2 , 3 , 5 , 1 ) ; $ n = sizeof ( $ arr ) ; echo ( findCount ( $ arr , $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Lexicographically smallest string of length N and sum K | Function to return the lexicographically smallest string of length n that satisfies the given condition ; Iteration from the last position in the array ; If k is a positive integer ; ' z ' needs to be inserted ; Add the required character ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def lexo_small ( n , k ) :\\n\\tarr = \\\" \\\" ;\\n\\tfor i in range ( n ) :\\n\\t\\tarr += ' a ' ;\\n\\tfor i in range ( n - 1 , - 1 , - 1 ) :\\n\\t\\tk -= i ;\\n\\t\\tif ( k >= 0 ) :\\n\\t\\t\\tif ( k >= 26 ) :\\n\\t\\t\\t\\tarr = arr [ : i ] + ' z ' + arr [ i + 1 : ] ;\\n\\t\\t\\t\\tk -= 26 ;\\n\\t\\t\\telse :\\n\\t\\t\\t\\tc = ( k + 97 - 1 ) ;\\n\\t\\t\\t\\tarr = arr [ : i ] + chr ( c ) + arr [ i + 1 : ] ;\\n\\t\\t\\t\\tk -= ord ( arr [ i ] ) - ord ( ' a ' ) + 1 ;\\n\\t\\telse :\\n\\t\\t\\tbreak ;\\n\\t\\tk += i ;\\n\\treturn arr ;\\nif __name__ == ' _ _ main _ _ ' :\\n\\tn = 5 ; k = 42 ;\\n\\tarr = lexo_small ( n , k ) ;\\n\\tprint ( arr ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimize sum of smallest elements from K subsequences of length L | C # program to find the minimum possible sum of the smallest elements from K subsequences ; Function to find the minimum sum ; Sort the array ; Calculate sum of smallest K elements ; Return the sum ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int findMinSum ( int [ ] arr , int K , int L , int size ) { if ( K * L > size ) return - 1 ; int minsum = 0 ; Array . Sort ( arr ) ; for ( int i = 0 ; i < K ; i ++ ) minsum += arr [ i ] ; return minsum ; } public static void Main ( ) { int [ ] arr = { 2 , 15 , 5 , 1 , 35 , 16 , 67 , 10 } ; int K = 3 ; int L = 2 ; int length = arr . Length ; Console . Write ( findMinSum ( arr , K , L , length ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Chocolate Distribution Problem | Set 2 | C # program for above approach ; Function to return minimum number of chocolates ; decreasing sequence ; add the chocolates received by that person ; end point of decreasing sequence ; val = 1 ; reset value at that index ; increasing sequence ; flat sequence ; add value of chocolates at position n - 1 ; helper function to get sum of decreasing sequence ; value obtained from decreasing sequence also the count of values in the sequence ; assigning max of values obtained from increasing and decreasing sequences ; sum of count - 1 values & peak value sum of natural numbers : ( n * ( n + 1 ) ) \\/ 2 ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GFG { public static int minChocolates ( int [ ] a , int n ) { int i = 0 , j = 0 ; int res = 0 , val = 1 ; while ( j < n - 1 ) { if ( a [ j ] > a [ j + 1 ] ) { j += 1 ; continue ; } if ( i == j ) res += val ; else { res += get_sum ( val , i , j ) ; } if ( a [ j ] < a [ j + 1 ] ) val += 1 ; else val = 1 ; j += 1 ; i = j ; } if ( i == j ) res += val ; else res += get_sum ( val , i , j ) ; return res ; } public static int get_sum ( int peak , int start , int end ) { int count = end - start + 1 ; peak = ( peak > count ) ? peak : count ; int s = peak + ( ( ( count - 1 ) * count ) >> 1 ) ; return s ; } static public void Main ( ) { int [ ] a = { 5 , 5 , 4 , 3 , 2 , 1 } ; int n = a . Length ; Console . WriteLine ( \\\" Minimum ▁ number ▁ of ▁ chocolates ▁ = ▁ \\\" + minChocolates ( a , n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Nth non | function to find the nth Non - Square Number ; conversion from int to long double is necessary in order to preserve decimal places after square root . ; calculating the result ; initializing the term number ; Print the result\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findNthNonSquare ( $ n ) { $ x = $ n ; $ ans = $ x + floor ( 0.5 + sqrt ( $ x ) ) ; return ( int ) $ ans ; } $ n = 16 ; echo \\\" The ▁ \\\" . $ n . \\\" th ▁ Non - Square ▁ number ▁ is ▁ \\\" ; echo findNthNonSquare ( $ n ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Repeated Unit Divisibility | CPP program to find least value of k for which R ( k ) is divisible by n ; To find least value of k ; To check n is coprime or not ; to store R ( k ) mod n and 10 ^ k mod n value ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int repUnitValue ( int n ) { if ( n % 2 == 0 n % 5 == 0 ) return 0 ; int rem = 1 ; int power = 1 ; int k = 1 ; while ( rem % n != 0 ) { k ++ ; power = power * 10 % n ; rem = ( rem + power ) % n ; } return k ; } int main ( ) { int n = 13 ; cout << repUnitValue ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Find if possible to visit every nodes in given Graph exactly once based on given conditions | C ++ program for above approach . ; Function to find print path ; If a [ 0 ] is 1 ; Printing path ; Seeking for a [ i ] = 0 and a [ i + 1 ] = 1 ; Printing path ; If a [ N - 1 ] = 0 ; Driver Code ; Given Input ; Function Call\\nHow can the above be solved in C?\",\"targets\":\"#include \\nusing namespace std ; void findpath ( int N , int a [ ] ) { if ( a [ 0 ] ) { printf ( \\\" % d ▁ \\\" , N + 1 ) ; for ( int i = 1 ; i <= N ; i ++ ) printf ( \\\" % d ▁ \\\" , i ) ; return ; } for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( ! a [ i ] && a [ i + 1 ] ) { for ( int j = 1 ; j <= i ; j ++ ) printf ( \\\" % d ▁ \\\" , j ) ; printf ( \\\" % d ▁ \\\" , N + 1 ) ; for ( int j = i + 1 ; j <= N ; j ++ ) printf ( \\\" % d ▁ \\\" , j ) ; return ; } } for ( int i = 1 ; i <= N ; i ++ ) printf ( \\\" % d ▁ \\\" , i ) ; printf ( \\\" % d ▁ \\\" , N + 1 ) ; } int main ( ) { int N = 3 , arr [ ] = { 0 , 1 , 0 } ; findpath ( N , arr ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Sum of even values and update queries on an array | Function to return the sum of even elements after updating value at given index ; Add given value to A [ index ] ; To store the sum of even elements ; If current element is even ; Function to print result for every query ; Resultant vector that stores the result for every query ; Get sum of even elements after updating value at given index ; Store sum for each query ; Print the result for every query ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def EvenSum ( A , index , value ) :\\n\\tA [ index ] = A [ index ] + value\\n\\tsum = 0\\n\\tfor i in A :\\n\\t\\tif ( i % 2 == 0 ) :\\n\\t\\t\\tsum = sum + i\\n\\treturn sum\\ndef BalanceArray ( A , Q ) :\\n\\tANS = [ ]\\n\\ti , sum = 0 , 0\\n\\tfor i in range ( len ( Q ) ) :\\n\\t\\tindex = Q [ i ] [ 0 ]\\n\\t\\tvalue = Q [ i ] [ 1 ]\\n\\t\\tsum = EvenSum ( A , index , value )\\n\\t\\tANS . append ( sum )\\n\\tfor i in ANS :\\n\\t\\tprint ( i , end = \\\" ▁ \\\" )\\nA = [ 1 , 2 , 3 , 4 ]\\nQ = [ [ 0 , 1 ] , [ 1 , - 3 ] , [ 0 , - 4 ] , [ 3 , 2 ] ]\\nBalanceArray ( A , Q )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimize cost of removals required to make all remaining characters of the string unique | Function to find the minimum cost of removing characters to make the string unique ; Store the minimum cost required ; Create a dictionary to store the maximum cost of removal a character ; Create a dictionary to store the total deletion cost of a character ; Traverse the string , S ; Keep track of maximum cost of each character ; Update the maximum deletion cost ; Keep track of the total cost of each character ; Update the total deletion cost ; Traverse through all the unique characters ; Keep the maximum cost character and delete the rest ; Return the answer ; Given string ; Given cost array ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function delCost ( s , cost ) { var ans = 0 ; var forMax = new Map ( ) ; var forTot = new Map ( ) ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( ! forMax . has ( s [ i ] ) ) { forMax . set ( s [ i ] , cost [ i ] ) ; } else { forMax . set ( s [ i ] , Math . max ( forMax . get ( s [ i ] ) , cost [ i ] ) ) } if ( ! forTot . has ( s [ i ] ) ) { forTot . set ( s [ i ] , cost [ i ] ) ; } else { forTot . set ( s [ i ] , forTot . get ( s [ i ] ) + cost [ i ] ) } } forMax . forEach ( ( value , key ) => { ans += forTot . get ( key ) - value ; } ) ; return ans ; } var s = \\\" \\\" ; var cost = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; document . write ( delCost ( s , cost ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"Maximum Sum Increasing Subsequence | DP | Dynamic Programming implementation of Maximum Sum Increasing Subsequence ( MSIS ) problem ; maxSumIS ( ) returns the maximum sum of increasing subsequence in arr [ ] of size n ; Initialize msis values for all indexes ; Compute maximum sum values in bottom up manner ; Pick maximum of all msis values ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint maxSumIS ( int arr [ ] , int n ) { int i , j , max = 0 ; int msis [ n ] ; for ( i = 0 ; i < n ; i ++ ) msis [ i ] = arr [ i ] ; for ( i = 1 ; i < n ; i ++ ) for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ; for ( i = 0 ; i < n ; i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ; return max ; } int main ( ) { int arr [ ] = { 1 , 101 , 2 , 3 , 100 , 4 , 5 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Sum ▁ of ▁ maximum ▁ sum ▁ increasing ▁ \\\" \\\" subsequence ▁ is ▁ % d \\n \\\" , maxSumIS ( arr , n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Subtract two numbers without using arithmetic operators | PHP Program to subtract two Number without using arithmetic operator ; Iterate till there is no carry ; borrow contains common set bits of y and unset bits of x ; Subtraction of bits of x and y where at least one of the bits is not set ; Borrow is shifted by one so that subtracting it from x gives the required sum ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function subtract ( $ x , $ y ) { while ( $ y != 0 ) { $ borrow = ( ~ $ x ) & $ y ; $ x = $ x ^ $ y ; $ y = $ borrow << 1 ; } return $ x ; } $ x = 29 ; $ y = 13 ; echo \\\" x ▁ - ▁ y ▁ is ▁ \\\" , subtract ( $ x , $ y ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum operations of given type to make all elements of a matrix equal | C # implementation of the approach ; Function to return the minimum number of operations required ; Create another array to store the elements of matrix ; If not possible ; Sort the array to get median ; To count the minimum operations ; If there are even elements , then there are two medians . We consider the best of two as answer . ; Return minimum operations required ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int minOperations ( int n , int m , int k , int [ , ] matrix ) { int [ ] arr = new int [ n * m ] ; int mod = matrix [ 0 , 0 ] % k ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { arr [ i * m + j ] = matrix [ i , j ] ; if ( matrix [ i , j ] % k != mod ) { return - 1 ; } } } Array . Sort ( arr ) ; int median = arr [ ( n * m ) \\/ 2 ] ; int minOperations = 0 ; for ( int i = 0 ; i < n * m ; ++ i ) minOperations += Math . Abs ( arr [ i ] - median ) \\/ k ; if ( ( n * m ) % 2 == 0 ) { int median2 = arr [ ( ( n * m ) \\/ 2 ) - 1 ] ; int minOperations2 = 0 ; for ( int i = 0 ; i < n * m ; ++ i ) minOperations2 += Math . Abs ( arr [ i ] - median2 ) \\/ k ; minOperations = Math . Min ( minOperations , minOperations2 ) ; } return minOperations ; } public static void Main ( ) { int [ , ] matrix = { { 2 , 4 , 6 } , { 8 , 10 , 12 } , { 14 , 16 , 18 } , { 20 , 22 , 24 } } ; int n = matrix . GetLength ( 0 ) ; int m = matrix . GetLength ( 1 ) ; int k = 2 ; Console . WriteLine ( minOperations ( n , m , k , matrix ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Print list items containing all characters of a given word | C program to print all strings that contain all characters of a word ; prints list items having all characters of word ; Since calloc is used , map [ ] is initialized as 0 ; Set the values in map ; Get the length of given word ; Check each item of list if has all characters of word ; unset the bit so that strings like sss not printed ; Set the values in map for next item ; Driver program to test to pront printDups\\\"\\nSolution in C:\",\"targets\":\"# include \\n# include \\n# include \\n# define NO_OF_CHARS 256\\nvoid print ( char * list [ ] , char * word , int list_size ) { int * map = ( int * ) calloc ( sizeof ( int ) , NO_OF_CHARS ) ; int i , j , count , word_size ; for ( i = 0 ; * ( word + i ) ; i ++ ) map [ * ( word + i ) ] = 1 ; word_size = strlen ( word ) ; for ( i = 0 ; i < list_size ; i ++ ) { for ( j = 0 , count = 0 ; * ( list [ i ] + j ) ; j ++ ) { if ( map [ * ( list [ i ] + j ) ] ) { count ++ ; map [ * ( list [ i ] + j ) ] = 0 ; } } if ( count == word_size ) printf ( \\\" % s \\\" , list [ i ] ) ; for ( j = 0 ; * ( word + j ) ; j ++ ) map [ * ( word + j ) ] = 1 ; } } int main ( ) { char str [ ] = \\\" sun \\\" ; char * list [ ] = { \\\" geeksforgeeks \\\" , \\\" unsorted \\\" , \\\" sunday \\\" , \\\" just \\\" , \\\" sss \\\" } ; print ( list , str , 5 ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-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 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 ▁ > = ▁ r - index \\\" makes sure that including one element at index will make a combination with remaining elements at remaining positions ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\nvoid combinationUtil ( int arr [ ] , int data [ ] , int start , int end , int index , int r ) ; void printCombination ( int arr [ ] , int n , int r ) { int data [ r ] ; combinationUtil ( arr , data , 0 , n - 1 , 0 , r ) ; } void combinationUtil ( int arr [ ] , int data [ ] , int start , int end , int index , int r ) { if ( index == r ) { for ( int j = 0 ; j < r ; j ++ ) printf ( \\\" % d ▁ \\\" , data [ j ] ) ; printf ( \\\" \\n \\\" ) ; 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 ) ; } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int r = 3 ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printCombination ( arr , n , r ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimize cost to reach end of an array by two forward jumps or one backward jump in each move | C # Program to implement the above approach ; Function to find the minimum cost to reach the end of an array ; Base Case : When N < 3 ; Store the results in table ; Initialize base cases ; Iterate over the range [ 2 , N - 2 ] to construct the dp array ; Handle case for the last index , i . e . N - 1 ; Print the answer ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; public class GFG { static void minCost ( int [ ] arr , int n ) { if ( n < 3 ) { Console . WriteLine ( arr [ 0 ] ) ; return ; } int [ ] dp = new int [ n ] ; dp [ 0 ] = arr [ 0 ] ; dp [ 1 ] = dp [ 0 ] + arr [ 1 ] + arr [ 2 ] ; for ( int i = 2 ; i < n - 1 ; i ++ ) dp [ i ] = Math . Min ( dp [ i - 2 ] + arr [ i ] , dp [ i - 1 ] + arr [ i ] + arr [ i + 1 ] ) ; dp [ n - 1 ] = Math . Min ( dp [ n - 2 ] , dp [ n - 3 ] + arr [ n - 1 ] ) ; Console . WriteLine ( dp [ n - 1 ] ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 9 , 4 , 6 , 8 , 5 } ; int N = arr . Length ; minCost ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count Negative Numbers in a Column | JavaScript implementation of Naive method to count of negative numbers in M [ n ] [ m ] ; Follow the path shown using arrows above ; no more negative numbers in this row ; Driver program to test above functions\\\"\\nSolution in Javascript:\",\"targets\":\"function countNegative ( M , n , m ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( M [ i ] [ j ] < 0 ) count += 1 ; else break ; } } return count ; } let M = [ [ - 3 , - 2 , - 1 , 1 ] , [ - 2 , 2 , 3 , 4 ] , [ 4 , 5 , 7 , 8 ] ] ; document . write ( countNegative ( M , 3 , 4 ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimize cost of placing tiles of dimensions 2 * 1 over a Matrix | Function to find the minimum cost in placing N tiles in a grid M [ ] [ ] ; Stores the minimum profit after placing i tiles ; Traverse the grid [ ] [ ] ; Update the orig_cost ; Traverse over the range [ 2 , N ] ; Place tiles horizentally or vertically ; Print the answer ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def tile_placing ( grid , N ) :\\n\\tdp = [ 0 ] * ( N + 5 ) ;\\n\\torig_cost = 0 ;\\n\\tfor i in range ( 2 ) :\\n\\t\\tfor j in range ( N ) :\\n\\t\\t\\torig_cost += grid [ i ] [ j ] ;\\n\\tdp [ 0 ] = 0 ;\\n\\tdp [ 1 ] = abs ( grid [ 0 ] [ 0 ] - grid [ 1 ] [ 0 ] ) ;\\n\\tfor i in range ( 2 , N + 1 ) :\\n\\t\\tdp [ i ] = max ( dp [ i - 1 ] + abs ( grid [ 0 ] [ i - 1 ] - grid [ 1 ] [ i - 1 ] ) , dp [ i - 2 ] + abs ( grid [ 0 ] [ i - 2 ] - grid [ 0 ] [ i - 1 ] ) + abs ( grid [ 1 ] [ i - 2 ] - grid [ 1 ] [ i - 1 ] ) ) ;\\n\\tprint ( orig_cost - dp [ N ] , end = \\\" \\\" ) ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tM = [ [ 7 , 5 , 1 , 3 ] , [ 8 , 6 , 0 , 2 ] ] ;\\n\\tN = len ( M [ 0 ] ) ;\\n\\ttile_placing ( M , N ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count subarrays having sum modulo K same as the length of the subarray | Java 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\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static void countSubarrays ( int a [ ] , int n , int k ) { HashMap < Integer , Integer > cnt = new HashMap < > ( ) ; long ans = 0 ; ArrayList < Integer > pref = new ArrayList < > ( ) ; pref . add ( 0 ) ; for ( int i = 0 ; i < n ; i ++ ) pref . add ( ( a [ i ] + pref . get ( i ) ) % k ) ; cnt . put ( 0 , 1 ) ; for ( int i = 1 ; i <= n ; i ++ ) { int remIdx = i - k ; if ( remIdx >= 0 ) { if ( cnt . containsKey ( ( pref . get ( remIdx ) - remIdx % k + k ) % k ) ) cnt . put ( ( pref . get ( remIdx ) - remIdx % k + k ) % k , cnt . get ( ( pref . get ( remIdx ) - remIdx % k + k ) % k ) - 1 ) ; else cnt . put ( ( pref . get ( remIdx ) - remIdx % k + k ) % k , - 1 ) ; } if ( cnt . containsKey ( ( pref . get ( i ) - i % k + k ) % k ) ) ans += cnt . get ( ( pref . get ( i ) - i % k + k ) % k ) ; if ( cnt . containsKey ( ( pref . get ( i ) - i % k + k ) % k ) ) cnt . put ( ( pref . get ( i ) - i % k + k ) % k , cnt . get ( ( pref . get ( i ) - i % k + k ) % k ) + 1 ) ; else cnt . put ( ( pref . get ( i ) - i % k + k ) % k , 1 ) ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) throws java . lang . Exception { int arr [ ] = { 2 , 3 , 5 , 3 , 1 , 5 } ; int N = arr . length ; int K = 4 ; countSubarrays ( arr , N , K ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Angle between two Planes in 3D | C program to find the Angle between two Planes in 3 D . ; Function to find Angle ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nvoid distance ( float a1 , float b1 , float c1 , float a2 , float b2 , float c2 ) { float d = ( a1 * a2 + b1 * b2 + c1 * c2 ) ; float e1 = sqrt ( a1 * a1 + b1 * b1 + c1 * c1 ) ; float e2 = sqrt ( a2 * a2 + b2 * b2 + c2 * c2 ) ; d = d \\/ ( e1 * e2 ) ; float pi = 3.14159 ; float A = ( 180 \\/ pi ) * ( acos ( d ) ) ; printf ( \\\" Angle ▁ is ▁ % .2f ▁ degree \\\" , A ) ; } int main ( ) { float a1 = 1 ; float b1 = 1 ; float c1 = 2 ; float d1 = 1 ; float a2 = 2 ; float b2 = -1 ; float c2 = 1 ; float d2 = -4 ; distance ( a1 , b1 , c1 , a2 , b2 , c2 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if a number starts with another number or not | C ++ program for the above approach ; Function to check if B is a prefix of A or not ; Convert numbers into strings ; Check if s2 is a prefix of s1 or not using starts_with ( ) function ; If result is true , print \\\" Yes \\\" ; Driver Code ; Given numbers ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#include \\nusing namespace std ; void checkprefix ( int A , int B ) { string s1 = to_string ( A ) ; string s2 = to_string ( B ) ; bool result ; result = boost :: algorithm :: starts_with ( s1 , s2 ) ; if ( result ) { cout << \\\" Yes \\\" ; } else { cout << \\\" No \\\" ; } } int main ( ) { int A = 12345 , B = 12 ; checkprefix ( A , B ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Longest substring such that no three consecutive characters are same | Java 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 Java?\",\"targets\":\"import java . util . * ; class GFG { static 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 . charAt ( i ) != s . charAt ( i - 1 ) || s . charAt ( i ) != s . charAt ( i - 2 ) ) temp ++ ; else { ans = Math . max ( temp , ans ) ; temp = 2 ; } } ans = Math . max ( temp , ans ) ; return ans ; } public static void main ( String [ ] args ) { String s = \\\" baaabbabbb \\\" ; System . out . println ( maxLenSubStr ( s ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check whether a given number is Polydivisible or Not | C # program to check whether a number is polydivisible or not ; function to check polydivisible number ; digit extraction of input number ; store the digits in an array ; n contains first i digits ; n should be divisible by i ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void check_polydivisible ( int n ) { int N = n ; List < int > digit = new List < int > ( ) ; while ( n > 0 ) { digit . Add ( ( int ) n % 10 ) ; n \\/= 10 ; } digit . Reverse ( ) ; bool flag = true ; n = digit [ 0 ] ; for ( int i = 1 ; i < digit . Count ; i ++ ) { n = n * 10 + digit [ i ] ; if ( n % ( i + 1 ) != 0 ) { flag = false ; break ; } } if ( flag ) Console . WriteLine ( N + \\\" ▁ is ▁ Polydivisible ▁ number . \\\" ) ; else Console . WriteLine ( N + \\\" ▁ is ▁ Not ▁ Polydivisible ▁ number . \\\" ) ; } public static void Main ( String [ ] args ) { int n = 345654 ; check_polydivisible ( n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Smallest number greater than or equal to N having sum of digits not exceeding S | Java program for the above approach ; Function to calculate sum digits of n ; Function to find the smallest possible integer satisfying the given condition ; If the sum of digits is already smaller than S ; Initialize variables ; Finding last kth digit ; Add remaining to make digit 0 ; If sum of digits does not exceed S ; Update k ; Driver Code ; Given N and S ; Function call\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int sum ( int n ) { int res = 0 ; while ( n > 0 ) { res += n % 10 ; n \\/= 10 ; } return res ; } static int smallestNumber ( int n , int s ) { if ( sum ( n ) <= s ) { return n ; } int ans = n , k = 1 ; for ( int i = 0 ; i < 9 ; ++ i ) { int digit = ( ans \\/ k ) % 10 ; int add = k * ( ( 10 - digit ) % 10 ) ; ans += add ; if ( sum ( ans ) <= s ) { break ; } k *= 10 ; } return ans ; } public static void main ( String [ ] args ) { int N = 3 , S = 2 ; System . out . println ( smallestNumber ( N , S ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Index of character depending on frequency count in string | C # implementation of the approach ; Function to perform the queries ; L [ i , j ] stores the largest i such that ith character appears exactly jth times in str [ 0. . . i ] ; F [ i , j ] stores the smallest i such that ith character appears exactly jth times in str [ 0. . . i ] ; To store the frequency of each of the character of str ; Current character of str ; Update its frequency ; For every lowercase character of the English alphabet ; If it is equal to the character under consideration then update L [ , ] and R [ , ] as it is cnt [ j ] th occurrence of character k ; Only update L [ , ] as k has not been occurred so only index has to be incremented ; Perform the queries ; Type 1 query ; Type 2 query ; Driver code ; Queries ; Perform the queries\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int MAX = 26 ; static void performQueries ( String str , int q , int [ ] type , char [ ] ch , int [ ] freq ) { int n = str . Length ; int [ , ] L = new int [ MAX , n ] ; int [ , ] F = new int [ MAX , n ] ; int [ ] cnt = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { int k = str [ i ] - ' a ' ; cnt [ k ] ++ ; for ( int j = 0 ; j < MAX ; j ++ ) { if ( k == j ) { L [ j , cnt [ j ] ] = i ; F [ j , cnt [ j ] ] = i ; } else L [ j , cnt [ j ] ] = L [ j , cnt [ j ] ] + 1 ; } } for ( int i = 0 ; i < q ; i ++ ) { if ( type [ i ] == 1 ) { Console . Write ( L [ ch [ i ] - ' a ' , freq [ i ] ] ) ; } else { Console . Write ( F [ ch [ i ] - ' a ' , freq [ i ] ] ) ; } Console . Write ( \\\" \\n \\\" ) ; } } public static void Main ( String [ ] args ) { String str = \\\" geeksforgeeks \\\" ; int [ ] type = { 1 , 2 } ; char [ ] ch = { ' e ' , ' k ' } ; int [ ] freq = { 2 , 2 } ; int q = type . Length ; performQueries ( str , q , type , ch , freq ) ; } }\",\"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\":\"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\\nHow can the above be solved in C?\",\"targets\":\"#include \\nvoid printDivisors ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) if ( n % i == 0 ) printf ( \\\" % d ▁ \\\" , i ) ; } int main ( ) { printf ( \\\" The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ \\n \\\" ) ; printDivisors ( 100 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of quadruples where the first three terms are in AP and last three terms are in GP | C # implementation of the approach ; Function to return the count of quadruples ; Hash table to count the number of occurrences ; Traverse and increment the count ; Run two nested loop for second and third element ; If they are same ; Initially decrease the count ; Find the first element using common difference ; Find the fourth element using GP y ^ 2 = x * z property ; If it is an integer ; If not equal ; Same elements ; Later increase the value for future calculations ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int countQuadruples ( int [ ] a , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( mp . ContainsKey ( a [ i ] ) ) { mp [ a [ i ] ] = mp [ a [ i ] ] + 1 ; } else { mp . Add ( a [ i ] , 1 ) ; } int count = 0 ; for ( int j = 0 ; j < n ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { if ( j == k ) continue ; mp [ a [ j ] ] = mp [ a [ j ] ] - 1 ; mp [ a [ k ] ] = mp [ a [ k ] ] - 1 ; int first = a [ j ] - ( a [ k ] - a [ j ] ) ; int fourth = ( a [ k ] * a [ k ] ) \\/ a [ j ] ; if ( ( a [ k ] * a [ k ] ) % a [ j ] == 0 ) { if ( a [ j ] != a [ k ] ) { if ( mp . ContainsKey ( first ) && mp . ContainsKey ( fourth ) ) count += mp [ first ] * mp [ fourth ] ; } else if ( mp . ContainsKey ( first ) && mp . ContainsKey ( fourth ) ) count += mp [ first ] * ( mp [ fourth ] - 1 ) ; } if ( mp . ContainsKey ( a [ j ] ) ) { mp [ a [ j ] ] = mp [ a [ j ] ] + 1 ; } else { mp . Add ( a [ j ] , 1 ) ; } if ( mp . ContainsKey ( a [ k ] ) ) { mp [ a [ k ] ] = mp [ a [ k ] ] + 1 ; } else { mp . Add ( a [ k ] , 1 ) ; } } } return count ; } public static void Main ( String [ ] args ) { int [ ] a = { 2 , 6 , 4 , 9 , 2 } ; int n = a . Length ; Console . Write ( countQuadruples ( a , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find the sum of all Betrothed numbers up to N | C ++ program to find the sum of the all betrothed numbers up to N ; Function to find the sum of the all betrothed numbers ; To store the betrothed numbers ; Calculate sum of number_1 's divisors 1 is always a divisor ; i = 2 because we don 't want to include 1 as a divisor. ; Sum all betrothed numbers up to N ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int Betrothed_Sum ( int n ) { vector < int > Set ; for ( int number_1 = 1 ; number_1 < n ; number_1 ++ ) { int sum_divisor_1 = 1 ; int i = 2 ; while ( i * i <= number_1 ) { if ( number_1 % i == 0 ) { sum_divisor_1 = sum_divisor_1 + i ; if ( i * i != number_1 ) sum_divisor_1 += number_1 \\/ i ; } i ++ ; } if ( sum_divisor_1 > number_1 ) { int number_2 = sum_divisor_1 - 1 ; int sum_divisor_2 = 1 ; int j = 2 ; while ( j * j <= number_2 ) { if ( number_2 % j == 0 ) { sum_divisor_2 += j ; if ( j * j != number_2 ) sum_divisor_2 += number_2 \\/ j ; } j = j + 1 ; } if ( sum_divisor_2 == number_1 + 1 and number_1 <= n && number_2 <= n ) { Set . push_back ( number_1 ) ; Set . push_back ( number_2 ) ; } } } int Summ = 0 ; for ( auto i : Set ) { if ( i <= n ) Summ += i ; } return Summ ; } int main ( ) { int n = 78 ; cout << Betrothed_Sum ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to calculate GST from original and net prices | Python3 Program to compute GST from original and net prices . ; return value after calculate GST % ; Driver program to test above functions\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def Calculate_GST ( org_cost , N_price ) :\\n\\treturn ( ( ( N_price - org_cost ) * 100 ) \\/ org_cost ) ;\\norg_cost = 100\\nN_price = 120\\nprint ( \\\" GST ▁ = ▁ \\\" , end = ' ' )\\nprint ( round ( Calculate_GST ( org_cost , N_price ) ) , end = ' ' )\\nprint ( \\\" % \\\" )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Area of a square inscribed in a circle which is inscribed in an equilateral triangle | Function to find the area of the square ; a cannot be negative ; area of the square ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function area ( $ a ) { if ( $ a < 0 ) return -1 ; $ area = sqrt ( $ a ) \\/ 6 ; return $ area ; } $ a = 10 ; echo area ( $ a ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Length of the longest substring with every character appearing even number of times | Function to find length of the longest substring with each element occurring even number of times ; Initialize unordered_map ; Stores the length of the longest required substring ; Traverse the string ; Stores the value of the digit present at current index ; Bitwise XOR of the mask with 1 left - shifted by val ; Check if the value of mask is already present in ind or not ; Update the final answer ; Otherwise ; Return the answer ; Driver Code ; Given string ; : Length of the given string ; Function Call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def lenOfLongestReqSubstr ( s , N ) :\\n\\tind = { }\\n\\tmask = 0\\n\\tind [ 0 ] = - 1\\n\\tans = 0\\n\\tfor i in range ( N ) :\\n\\t\\tval = ord ( s [ i ] ) - ord ( '0' )\\n\\t\\tmask ^= ( 1 << val )\\n\\t\\tif ( mask in ind ) :\\n\\t\\t\\tans = max ( ans , i - ind [ mask ] )\\n\\t\\telse :\\n\\t\\t\\tind [ mask ] = i\\n\\treturn ans\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\ts = \\\"223015150\\\"\\n\\tN = len ( s )\\n\\tprint ( lenOfLongestReqSubstr ( s , N ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Ways to split array into two groups of same XOR value | CPP Program to count number of ways to split array into two groups such that each group has equal XOR value ; Return the count number of ways to split array into two groups such that each group has equal XOR value . ; We can split only if XOR is 0. Since XOR of all is 0 , we can consider all subsets as one group . ; Driver Program\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int countgroup ( int a [ ] , int n ) { int xs = 0 ; for ( int i = 0 ; i < n ; i ++ ) xs = xs ^ a [ i ] ; if ( xs == 0 ) return ( 1 << ( n - 1 ) ) - 1 ; return 0 ; } int main ( ) { int a [ ] = { 1 , 2 , 3 } ; int n = sizeof ( a ) \\/ sizeof ( a [ 0 ] ) ; cout << countgroup ( a , n ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Temple Offerings | Returns minimum offerings required ; Go through all templs one by one ; Go to left while height keeps increasing ; Go to right while height keeps increasing ; This temple should offer maximum of two values to follow the rule . ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function offeringNumber ( $ n , $ templeHeight ) { for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { $ left = 0 ; $ right = 0 ; for ( $ j = $ i - 1 ; $ j >= 0 ; -- $ j ) { if ( $ templeHeight [ $ j ] < $ templeHeight [ $ j + 1 ] ) ++ $ left ; else break ; } for ( $ j = $ i + 1 ; $ j < $ n ; ++ $ j ) { if ( $ templeHeight [ $ j ] < $ templeHeight [ $ j - 1 ] ) ++ $ right ; else break ; } $ sum += max ( $ right , $ left ) + 1 ; } return $ sum ; } $ arr1 = array ( 1 , 2 , 2 ) ; echo offeringNumber ( 3 , $ arr1 ) , \\\" \\n \\\" ; $ arr2 = array ( 1 , 4 , 3 , 6 , 2 , 1 ) ; echo offeringNumber ( 6 , $ arr2 ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Search an element in a sorted and rotated array | Java program to search an element in sorted and rotated array using single pass of Binary Search ; Returns index of key in arr [ l . . h ] if key is present , otherwise returns - 1 ; If arr [ l ... mid ] first subarray 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 ] first subarray is not sorted , then arr [ mid ... h ] must be sorted subarry ; main function\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class Main { 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 ] ) { 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 ( String args [ ] ) { int arr [ ] = { 4 , 5 , 6 , 7 , 8 , 9 , 1 , 2 , 3 } ; int n = arr . length ; int key = 6 ; int i = search ( arr , 0 , n - 1 , key ) ; if ( i != - 1 ) System . out . println ( \\\" Index : ▁ \\\" + i ) ; else System . out . println ( \\\" Key ▁ not ▁ found \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Print reverse string after removing vowels | Function for replacing the string ; initialize a string of length n ; Traverse through all characters of string ; assign the value to string r from last index of string s ; if s [ i ] is a consonant then print r [ i ] ; Driver function\\\"\\nSolution in Javascript:\",\"targets\":\"function replaceOriginal ( s , n ) { var r = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { r [ i ] = s . charAt ( n - 1 - i ) ; if ( s . charAt ( i ) != ' ' && s . charAt ( i ) != ' ' && s . charAt ( i ) != ' ' && s . charAt ( i ) != ' ' && s . charAt ( i ) != ' ' ) { document . write ( r [ i ] ) ; } } document . write ( \\\" \\\" ) ; } var s = \\\" \\\" ; var n = s . length ; replaceOriginal ( s , n ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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 program\\\"\\nSolution in C:\",\"targets\":\"#include \\nint fact ( int n ) { if ( n == 0 ) return 1 ; return n * fact ( n - 1 ) ; } int div ( int x ) { int ans = 0 ; for ( int i = 1 ; i <= x ; i ++ ) if ( x % i == 0 ) ans += i ; return ans ; } int sumFactDiv ( int n ) { return div ( fact ( n ) ) ; } int main ( ) { int n = 4 ; printf ( \\\" % d \\\" , sumFactDiv ( n ) ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Reverse String according to the number of words | C program to reverse string according to the number of words ; Reverse the letters of the word ; Temporary variable to store character ; Swapping the first and last character ; This function forms the required string ; Checking the number of words present in string to reverse ; Reverse the letter of the words ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nvoid reverse ( char str [ ] , int start , int end ) { char temp ; while ( start <= end ) { temp = str [ start ] ; str [ start ] = str [ end ] ; str [ end ] = temp ; start ++ ; end -- ; } } void reverseletter ( char str [ ] , int start , int end ) { int wstart , wend ; for ( wstart = wend = start ; wend < end ; wend ++ ) { if ( str [ wend ] == ' ▁ ' ) continue ; while ( str [ wend ] != ' ▁ ' && wend <= end ) wend ++ ; wend -- ; reverse ( str , wstart , wend ) ; } } int main ( ) { char str [ 1000 ] = \\\" Ashish ▁ Yadav ▁ Abhishek ▁ Rajput ▁ Sunil ▁ Pundir \\\" ; reverseletter ( str , 0 , strlen ( str ) - 1 ) ; printf ( \\\" % s \\\" , str ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Treasure and Cities | A memoization based program to find maximum treasure that can be collected . ; k is current index and col is previous color . ; base case ; we have two options either visit current city or skip that ; check if color of this city is equal to prev visited city ; return max of both options ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"MAX = 1001\\ndp = [ [ - 1 for i in range ( MAX ) ] for i in range ( MAX ) ]\\ndef MaxProfit ( treasure , color , n , k , col , A , B ) :\\n\\tif ( k == n ) :\\n\\t\\tdp [ k ] [ col ] = 0\\n\\t\\treturn dp [ k ] [ col ]\\n\\tif ( dp [ k ] [ col ] != - 1 ) :\\n\\t\\treturn dp [ k ] [ col ]\\n\\tsumm = 0\\n\\tif ( col == color [ k ] ) :\\n\\t\\tsumm += max ( A * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) )\\n\\telse :\\n\\t\\tsumm += max ( B * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) )\\n\\tdp [ k ] [ col ] = summ\\n\\treturn dp [ k ] [ col ]\\nA = - 5\\nB = 7\\ntreasure = [ 4 , 8 , 2 , 9 ]\\ncolor = [ 2 , 2 , 6 , 2 ]\\nn = len ( color )\\nprint ( MaxProfit ( treasure , color , n , 0 , 0 , A , B ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program to print non square numbers | Javascript program to print first n non - square numbers . ; Print curr_count numbers . curr_count is current gap between two square numbers . ; Skip a square number . ; Count of next non - square numbers is next even number . ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function printNonSquare ( n ) { let curr_count = 2 , num = 2 , count = 0 ; while ( count < n ) { for ( let i = 0 ; i < curr_count && count < n ; i ++ ) { document . write ( num + \\\" \\\" ) ; count ++ ; num ++ ; } num ++ ; curr_count += 2 ; } } let n = 10 ; printNonSquare ( n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if a string has all characters with same frequency with one variation allowed | 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 ; 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\\\"\\nSolution in Python:\",\"targets\":\"CHARS = 26\\ndef isValidString ( str ) :\\n\\tfreq = [ 0 ] * CHARS\\n\\tfor i in range ( len ( str ) ) :\\n\\t\\tfreq [ ord ( str [ i ] ) - ord ( ' a ' ) ] += 1\\n\\tfreq1 = 0\\n\\tcount_freq1 = 0\\n\\tfor i in range ( CHARS ) :\\n\\t\\tif ( freq [ i ] != 0 ) :\\n\\t\\t\\tfreq1 = freq [ i ]\\n\\t\\t\\tcount_freq1 = 1\\n\\t\\t\\tbreak\\n\\tfreq2 = 0\\n\\tcount_freq2 = 0\\n\\tfor j in range ( i + 1 , CHARS ) :\\n\\t\\tif ( freq [ j ] != 0 ) :\\n\\t\\t\\tif ( freq [ j ] == freq1 ) :\\n\\t\\t\\t\\tcount_freq1 += 1\\n\\t\\t\\telse :\\n\\t\\t\\t\\tcount_freq2 = 1\\n\\t\\t\\t\\tfreq2 = freq [ j ]\\n\\t\\t\\t\\tbreak\\n\\tfor k in range ( j + 1 , CHARS ) :\\n\\t\\tif ( freq [ k ] != 0 ) :\\n\\t\\t\\tif ( freq [ k ] == freq1 ) :\\n\\t\\t\\t\\tcount_freq1 += 1\\n\\t\\t\\tif ( freq [ k ] == freq2 ) :\\n\\t\\t\\t\\tcount_freq2 += 1\\n\\t\\t\\telse :\\n\\t\\t\\t\\treturn False\\n\\t\\tif ( count_freq1 > 1 and count_freq2 > 1 ) :\\n\\t\\t\\treturn False\\n\\treturn True\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tstr = \\\" abcbc \\\"\\n\\tif ( isValidString ( str ) ) :\\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\":\"\\\"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\\\"\\nSolution in Javascript:\",\"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\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Numbers in a Range with given Digital Root | C # implementation of the approach ; 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\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int countNumbers ( int L , int R , int K ) { if ( K == 9 ) { K = 0 ; } int totalnumbers = R - L + 1 ; int factor9 = totalnumbers \\/ 9 ; int rem = totalnumbers % 9 ; int ans = factor9 ; for ( int i = R ; i > R - rem ; i -- ) { int rem1 = i % 9 ; if ( rem1 == K ) { ans ++ ; } } return ans ; } public static void Main ( ) { int L = 10 ; int R = 22 ; int K = 3 ; Console . WriteLine ( countNumbers ( L , R , K ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count numbers in range such that digits in it and it 's product with q are unequal | C # program for above approach ; Function to check if all of the digits in a number and it 's product with q are unequal or not ; convert first number into string ; Insert elements from 1 st number to hash ; Calculate corresponding product ; Convert the product to string ; Using the hash check if any digit of product matches with the digits of input number ; If yes , return false ; Else , return true ; Function to count numbers in the range [ l , r ] such that all of the digits of the number and it 's product with q are unequal ; check for every number between l and r ; Driver Code ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GfG { static bool checkIfUnequal ( int n , int q ) { string s1 = n . ToString ( ) ; int [ ] a = new int [ 26 ] ; for ( int i = 0 ; i < s1 . Length ; i ++ ) a [ s1 [ i ] - '0' ] ++ ; int prod = n * q ; string s2 = prod . ToString ( ) ; for ( int i = 0 ; i < s2 . Length ; i ++ ) { if ( a [ s2 [ i ] - '0' ] ) return false ; } return true ; } static int countInRange ( int l , int r , int q ) { int count = 0 ; for ( int i = l ; i <= r ; i ++ ) { if ( checkIfUnequal ( i , q ) ) count ++ ; } return count ; } public static void Main ( ) { int l = 10 , r = 12 , q = 2 ; Console . WriteLine ( countInRange ( l , r , q ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"Program to find whether a no is power of two | C Program to find whether a no is power of two ; Function to check if x is power of 2 ; Driver program\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\n#include \\nbool isPowerOfTwo ( int n ) { if ( n == 0 ) return false ; return ( ceil ( log2 ( n ) ) == floor ( log2 ( n ) ) ) ; } 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\":\"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 ▁ number ▁ of ▁ multiplications ▁ is ▁ % d ▁ \\\" , MatrixChainOrder ( arr , size ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the Magnitude of a Vector | Function to calculate magnitude of a 3 dimensional vector ; Stores the sum of squares of coordinates of a vector ; Return the magnitude ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function vectorMagnitude ( x , y , z ) { var sum = x * x + y * y + z * z ; return Math . sqrt ( sum ) ; } var x = 1 ; var y = 2 ; var z = 3 ; document . write ( vectorMagnitude ( x , y , z ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximum count of common divisors of A and B such that all are co | C # implementation of the above 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 C-Sharp?\",\"targets\":\"using System ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static int maxCommonFactors ( int a , int b ) { int __gcd = gcd ( a , b ) ; int ans = 1 ; for ( int i = 2 ; i * i <= __gcd ; i ++ ) { if ( __gcd % i == 0 ) { ans ++ ; while ( __gcd % i == 0 ) __gcd \\/= i ; } } if ( __gcd != 1 ) ans ++ ; return ans ; } public static void Main ( String [ ] args ) { int a = 12 , b = 18 ; Console . WriteLine ( maxCommonFactors ( a , b ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Lexicographically smallest K | C # program to find lexicographically smallest K - length substring containing maximum number of vowels ; Function that prints the lexicographically smallest K - length substring containing maximum number of vowels ; Store the length of the string ; Initialize a prefix sum array ; Loop through the string to create the prefix sum array ; Store 1 at the index if it is a vowel ; Otherwise , store 0 ; Process the prefix array ; Initialize the variable to store maximum count of vowels ; Initialize the variable to store substring with maximum count of vowels ; Loop through the prefix array ; Store the current count of vowels ; Update the result if current count is greater than maximum count ; Update lexicographically smallest substring if the current count is equal to the maximum count ; Return the result ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static string maxVowelSubString ( string str , int K ) { int N = str . Length ; int [ ] pref = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' a ' str [ i ] == ' e ' str [ i ] == ' i ' str [ i ] == ' o ' str [ i ] == ' u ' ) pref [ i ] = 1 ; else pref [ i ] = 0 ; if ( i != 0 ) pref [ i ] += pref [ i - 1 ] ; } int maxCount = pref [ K - 1 ] ; string res = str . Substring ( 0 , K ) ; for ( int i = K ; i < N ; i ++ ) { int currCount = pref [ i ] - pref [ i - K ] ; if ( currCount > maxCount ) { maxCount = currCount ; res = str . Substring ( i - K + 1 , K ) ; } else if ( currCount == maxCount ) { string temp = str . Substring ( i - K + 1 , K ) ; if ( string . Compare ( temp , res ) == - 1 ) res = temp ; } } return res ; } public static void Main ( ) { string str = \\\" ceebbaceeffo \\\" ; int K = 3 ; Console . Write ( maxVowelSubString ( str , K ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"Find maximum ( or minimum ) in Binary Tree | C program to find maximum and minimum in a Binary Tree ; A tree node ; A utility function to create a new node ; Returns maximum value in a given Binary Tree ; Base case ; Return maximum of 3 values : 1 ) Root 's data 2) Max in Left Subtree 3) Max in right subtree ; Driver code ; Function call\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#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 ) ; } int findMax ( struct Node * root ) { if ( root == NULL ) return INT_MIN ; int res = root -> data ; int lres = findMax ( root -> left ) ; int rres = findMax ( root -> right ) ; if ( lres > res ) res = lres ; if ( rres > res ) res = rres ; return res ; } 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 ( \\\" Maximum ▁ element ▁ is ▁ % d ▁ \\n \\\" , findMax ( root ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Modify string by removing vowels in between two consonants | C ++ program to remove all Vowels in between two consonants from the string ; Function to check if the character x is a vowel or not ; Returns the updated string formed after removing all the Sandwiched Vowels from the given string ; string to store the Updated String after removing the Sandwiched Vowels ; traverse the string from left to right ; if the current character is the first or the last character of the string then , this needs to be appended to the updatedString , since the corner alphabet irrespective of it being a vowel or a consonant , is never ' Sandwiched ' ; Check if the current character of the string is a vowel and both the previous and the next characters are consonants , if so then this is a sandwiched vowel , thus is ignored and not appended to the updated string ; if this character is not a sandwiched Vowel append it to the updated String ; Driver Code ; Remove all the Sandwitched Vowels\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool isVowel ( char x ) { if ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) return true ; else return false ; } string updateSandwichedVowels ( string a ) { int n = a . length ( ) ; string updatedString = \\\" \\\" ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! i i == n - 1 ) { updatedString += a [ i ] ; continue ; } if ( isVowel ( a [ i ] ) && ! isVowel ( a [ i - 1 ] ) && ! isVowel ( a [ i + 1 ] ) ) { continue ; } updatedString += a [ i ] ; } return updatedString ; } int main ( ) { string str = \\\" geeksforgeeks \\\" ; string updatedString = updateSandwichedVowels ( str ) ; cout << updatedString ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"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\\\"\\nHow can the above be solved in JS?\",\"targets\":\"let sum = 0 ; function Combination ( a , combi , n , r , depth , index ) { if ( index == r ) { let product = 1 ; for ( let i = 0 ; i < r ; i ++ ) product = product * combi [ i ] ; sum += product ; return ; } for ( let i = depth ; i < n ; i ++ ) { combi [ index ] = a [ i ] ; Combination ( a , combi , n , r , i + 1 , index + 1 ) ; } } function allCombination ( a , n ) { for ( let i = 1 ; i <= n ; i ++ ) { let combi = [ ] ; Combination ( a , combi , n , i , 0 , 0 ) ; document . write ( \\\" \\\" + i + \\\" \\\" + sum + \\\" \\\" ) ; sum = 0 ; } } let n = 5 ; let a = [ ] ; for ( let i = 0 ; i < n ; i ++ ) a [ i ] = i + 1 ; allCombination ( a , n ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"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 po in an array using binary search ; low + ( high - low ) \\/ 2 ; ; Return - 1 if there is no Fixed Po ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function binarySearch ( $ arr , $ low , $ high ) { if ( $ high >= $ low ) { $ mid = ( int ) ( ( $ 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 ; } $ arr = array ( -10 , -1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 ) ; $ n = count ( $ arr ) ; echo \\\" Fixed ▁ Point ▁ is : ▁ \\\" . binarySearch ( $ arr , 0 , $ n - 1 ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Check if a given string can be converted to another by given possible swaps | Java 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\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static boolean checkStr1CanConStr2 ( String str1 , String str2 ) { int N = str1 . length ( ) ; int M = str2 . length ( ) ; HashSet < Integer > st1 = new HashSet < > ( ) ; HashSet < Integer > st2 = new HashSet < > ( ) ; int hash1 [ ] = new int [ 256 ] ; for ( int i = 0 ; i < N ; i ++ ) { hash1 [ str1 . charAt ( i ) ] ++ ; } for ( int i = 0 ; i < N ; i ++ ) { st1 . add ( ( int ) str1 . charAt ( i ) ) ; } for ( int i = 0 ; i < M ; i ++ ) { st2 . add ( ( int ) str2 . charAt ( i ) ) ; } if ( ! st1 . equals ( st2 ) ) { return false ; } int hash2 [ ] = new int [ 256 ] ; for ( int i = 0 ; i < M ; i ++ ) { hash2 [ str2 . charAt ( i ) ] ++ ; } Arrays . sort ( hash1 ) ; Arrays . sort ( hash2 ) ; for ( int i = 0 ; i < 256 ; i ++ ) { if ( hash1 [ i ] != hash2 [ i ] ) { return false ; } } return true ; } public static void main ( String [ ] args ) { String str1 = \\\" xyyzzlll \\\" ; String str2 = \\\" yllzzxxx \\\" ; if ( checkStr1CanConStr2 ( str1 , str2 ) ) { System . out . print ( \\\" True \\\" ) ; } else { System . out . print ( \\\" False \\\" ) ; } } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimal product subsequence where adjacent elements are separated by a maximum distance of K | Python3 implementation of the above approach . ; Function to get the minimum product of subsequence such that adjacent elements are separated by a max distance of K ; multiset will hold pairs pair = ( log value of product , dp [ j ] value ) dp [ j ] = minimum product % mod multiset will be sorted according to log values Therefore , corresponding to the minimum log value dp [ j ] value can be obtained . ; For the first k - sized window . ; Update log value by adding previous minimum log value ; Update dp [ i ] ; Insert it again into the multiset since it is within the k - size window ; Eliminate previous value which falls out of the k - sized window ; Insert newest value to enter in the k - sized window . ; dp [ n - 1 ] will have minimum product % mod such that adjacent elements are separated by a max distance K ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import math\\nmod = 1000000007 ;\\nMAX = 100005 ;\\ndef minimumProductSubsequence ( arr , n , k ) :\\n\\ts = [ ]\\n\\tdp = [ 0 for i in range ( MAX ) ] ;\\n\\tp = [ 0.0 for i in range ( MAX ) ] ;\\n\\tdp [ 0 ] = arr [ 0 ] ;\\n\\tp [ 0 ] = math . log ( arr [ 0 ] ) ;\\n\\ts . append ( [ p [ 0 ] , dp [ 0 ] ] ) ;\\n\\ts . sort ( )\\n\\tfor i in range ( 1 , k ) :\\n\\t\\tl = s [ 0 ] [ 0 ]\\n\\t\\tmin = s [ 0 ] [ 1 ]\\n\\t\\tp [ i ] = math . log ( arr [ i ] ) + l ;\\n\\t\\tdp [ i ] = ( arr [ i ] * min ) % mod ;\\n\\t\\ts . append ( [ p [ i ] , dp [ i ] ] ) ;\\n\\t\\ts . sort ( )\\n\\tfor i in range ( k , n ) :\\n\\t\\tl = s [ 0 ] [ 0 ]\\n\\t\\tmin = s [ 0 ] [ 1 ]\\n\\t\\tp [ i ] = math . log ( arr [ i ] ) + l ;\\n\\t\\tdp [ i ] = ( arr [ i ] * min ) % mod ;\\n\\t\\tif [ p [ i - k ] , dp [ i - k ] ] in s :\\n\\t\\t\\ts . pop ( s . index ( [ p [ i - k ] , dp [ i - k ] ] ) )\\n\\t\\ts . append ( [ p [ i ] , dp [ i ] ] ) ;\\n\\t\\ts . sort ( )\\n\\treturn dp [ n - 1 ] ;\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 1 , 2 , 3 , 4 ]\\n\\tn = len ( arr )\\n\\tk = 2 ;\\n\\tprint ( minimumProductSubsequence ( arr , n , k ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Special two digit numbers in a Binary Search Tree | C program to count number of nodes in BST containing two digit special number ; A Tree node ; Function to create a new node ; If the tree is empty , return a new , single node ; Otherwise , recur down the tree ; Function to find if number is special or not ; Check if number is two digit or not ; Function to count number of special two digit number ; Driver program to test ; Function call , to check each node for special two digit number\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nstruct Node { struct Node * left ; int info ; struct Node * right ; } ; void insert ( struct Node * * rt , int key ) { if ( * rt == NULL ) { ( * rt ) = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; ( * rt ) -> left = NULL ; ( * rt ) -> right = NULL ; ( * rt ) -> info = key ; } else if ( key < ( ( * rt ) -> info ) ) insert ( & ( ( * rt ) -> left ) , key ) ; else insert ( & ( * rt ) -> right , key ) ; } int check ( int num ) { int sum = 0 , i = num , sum_of_digits , prod_of_digits ; if ( num < 10 num > 99 ) return 0 ; else { sum_of_digits = ( i % 10 ) + ( i \\/ 10 ) ; prod_of_digits = ( i % 10 ) * ( i \\/ 10 ) ; sum = sum_of_digits + prod_of_digits ; } if ( sum == num ) return 1 ; else return 0 ; } void countSpecialDigit ( struct Node * rt , int * c ) { int x ; if ( rt == NULL ) return ; else { x = check ( rt -> info ) ; if ( x == 1 ) * c = * c + 1 ; countSpecialDigit ( rt -> left , c ) ; countSpecialDigit ( rt -> right , c ) ; } } int main ( ) { struct Node * root = NULL ; int count = 0 ; insert ( & root , 50 ) ; insert ( & root , 29 ) ; insert ( & root , 59 ) ; insert ( & root , 19 ) ; insert ( & root , 53 ) ; insert ( & root , 556 ) ; insert ( & root , 56 ) ; insert ( & root , 94 ) ; insert ( & root , 13 ) ; countSpecialDigit ( root , & count ) ; printf ( \\\" % d \\\" , count ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Largest area square in an array when elements can be shuffled | C # 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\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static bool 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 ( ) { int [ ] arr = { 1 , 3 , 4 , 5 , 5 } ; int n = arr . Length ; Console . WriteLine ( maxArea ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check if linked list is sorted ( Iterative and Recursive ) | Java program to check Linked List is sorted in descending order or not ; Linked list node ; function to Check Linked List is sorted in descending order or not ; Traverse the list till last node and return false if a node is smaller than or equal its next . ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static class Node { int data ; Node next ; } ; static boolean isSortedDesc ( Node head ) { if ( head == null ) return true ; for ( Node t = head ; t . next != null ; t = t . next ) if ( t . data <= t . next . data ) return false ; return true ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . next = null ; temp . data = data ; return temp ; } public static void main ( String [ ] args ) { Node head = newNode ( 7 ) ; head . next = newNode ( 5 ) ; head . next . next = newNode ( 4 ) ; head . next . next . next = newNode ( 3 ) ; if ( isSortedDesc ( head ) ) 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\":\"\\\"Highest power of 2 less than or equal to given number | Java program to find highest power of 2 smaller than or equal to n . ; If i is a power of 2 ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int highestPowerof2 ( int n ) { int res = 0 ; for ( int i = n ; i >= 1 ; i -- ) { if ( ( i & ( i - 1 ) ) == 0 ) { res = i ; break ; } } return res ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . print ( highestPowerof2 ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximum length subsequence such that adjacent elements in the subsequence have a common factor | JavaScript implementation of the above approach ; Function to compute least prime divisor of i upto MAX element of the input array it will be space efficient if more test cases are there it 's better to find prime divisor upto upperbound of input element it will be cost efficient ; Function that returns the maximum length subsequence such that adjacent elements have a common factor . ; Initialize dp array with 1. ; p has appeared at least once . ; Update latest occurrence of prime p . ; Take maximum value as the answer . ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"let N , MAX ; let lpd ; function preCompute ( ) { lpd = new Array ( MAX + 1 ) ; for ( let i = 0 ; i < lpd . length ; i ++ ) { lpd [ i ] = 0 ; } lpd [ 0 ] = lpd [ 1 ] = 1 ; for ( let i = 2 ; i * i <= MAX ; i ++ ) { for ( let j = i * 2 ; j <= MAX ; j += i ) { if ( lpd [ j ] == 0 ) { lpd [ j ] = i ; } } } for ( let i = 2 ; i <= MAX ; i ++ ) { if ( lpd [ i ] == 0 ) { lpd [ i ] = i ; } } } function maxLengthSubsequence ( arr , n ) { let dp = new Array ( N ) ; let pos = new Map ( ) ; for ( let i = 0 ; i <= n ; i ++ ) dp [ i ] = 1 ; for ( let i = 0 ; i <= n ; i ++ ) { while ( arr [ i ] > 1 ) { let p = lpd [ arr [ i ] ] ; if ( pos . has ( p ) ) { dp [ i ] = Math . max ( dp [ i ] , 1 + dp [ pos . get ( p ) ] ) ; } pos . set ( p , i ) ; while ( arr [ i ] % p == 0 ) arr [ i ] = Math . floor ( arr [ i ] \\/ p ) ; } } let ans = Math . max ( ... dp ) ; return ans ; } let arr = [ 13 , 2 , 8 , 6 , 3 , 1 , 9 ] ; N = arr . length ; MAX = Math . max ( ... arr ) ; preCompute ( ) ; document . write ( maxLengthSubsequence ( arr , N - 1 ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Largest Even and Odd N | Function to print the largest n - digit even and odd numbers in hexadecimal number system ; Append ' F ' ( N - 1 ) times ; Append ' E ' for an even number ; Append ' F ' for an odd number ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function findNumbers ( n ) { var ans = \\\" \\\" . repeat ( n - 1 ) ; var even = ans + ' ' ; var odd = ans + ' ' ; document . write ( \\\" \\\" + even + \\\" \\\" ) ; document . write ( \\\" \\\" + odd + \\\" \\\" ) ; } var n = 2 ; findNumbers ( n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Add 1 to a given number | ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int addOne ( int x ) { return ( - ( ~ x ) ) ; } int main ( ) { cout << addOne ( 13 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Anti | C # program for the above approach ; Iterative function to reverse digits of num ; Return the reversed num ; Function to calculate sum of reverse all proper divisors ; Final result of summation of divisors ; Find all divisors of num ; If ' i ' is divisor of ' num ' ; If both divisors are same then add it only once else add both ; Add 1 to the result as 1 is also a divisor ; Function to check if N is anti - perfect or not ; Driver Code ; Given Number N ; Function Call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int rev ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num \\/ 10 ; } return rev_num ; } static int divSum ( int num ) { int result = 0 ; for ( int i = 2 ; i <= Math . Sqrt ( num ) ; i ++ ) { if ( num % i == 0 ) { if ( i == ( num \\/ i ) ) result += rev ( i ) ; else result += ( rev ( i ) + rev ( num \\/ i ) ) ; } } return ( result + 1 ) ; } static Boolean isAntiPerfect ( int n ) { return divSum ( n ) == n ; } public static void Main ( String [ ] args ) { int N = 244 ; if ( isAntiPerfect ( N ) ) Console . Write ( \\\" Yes \\\" ) ; else Console . Write ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Efficiently check whether n is a multiple of 4 or not | function to check whether ' n ' is a multiple of 4 or not ; if true , then ' n ' is a multiple of 4 ; else ' n ' is not a multiple of 4 ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def isAMultipleOf4 ( n ) :\\n\\tif ( ( n & 3 ) == 0 ) :\\n\\t\\treturn \\\" Yes \\\"\\n\\treturn \\\" No \\\"\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tn = 16\\n\\tprint ( isAMultipleOf4 ( n ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Majority Element | Function to find Majority element in an array ; sentinels ; update maxCount if count of current element is greater ; if maxCount is greater than n \\/ 2 return the corresponding element ; Driver code ; Function calling\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findMajority ( $ arr , $ n ) { $ maxCount = 0 ; $ index = -1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ count = 0 ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { if ( $ arr [ $ i ] == $ arr [ $ j ] ) $ count ++ ; } if ( $ count > $ maxCount ) { $ maxCount = $ count ; $ index = $ i ; } } if ( $ maxCount > $ n \\/ 2 ) echo $ arr [ $ index ] . \\\" \\n \\\" ; else echo \\\" No ▁ Majority ▁ Element \\\" . \\\" \\n \\\" ; } $ arr = array ( 1 , 1 , 2 , 1 , 3 , 5 , 1 ) ; $ n = sizeof ( $ arr ) ; findMajority ( $ arr , $ n ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Construct a frequency array of digits of the values obtained from x ^ 1 , x ^ 2 , ... ... . . , x ^ n | Function that traverses digits in a number and modifies frequency count array ; Array to keep count of digits ; Traversing through x ^ 1 to x ^ n ; For power function , both its parameters are to be in double ; calling countDigits function on x ^ i ; Printing count of digits 0 - 9 ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function countDigits ( $ val , & $ arr ) { while ( $ val > 0 ) { $ digit = $ val % 10 ; $ arr [ ( int ) ( $ digit ) ] += 1 ; $ val = ( int ) ( $ val \\/ 10 ) ; } return ; } function countFrequency ( $ x , $ n ) { $ freq_count = array_fill ( 0 , 10 , 0 ) ; for ( $ i = 1 ; $ i < $ n + 1 ; $ i ++ ) { $ val = pow ( $ x , $ i ) ; countDigits ( $ val , $ freq_count ) ; } for ( $ i = 0 ; $ i < 10 ; $ i ++ ) { echo $ freq_count [ $ i ] . \\\" \\\" ; } } $ x = 15 ; $ n = 3 ; countFrequency ( $ x , $ n ) ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Split a given string into substrings of length K with equal sum of ASCII values | C # program to check if a given string can be split into substrings of size K having an equal sum of ASCII values . ; Function for checking string ; Check if the string can be split into substrings of K length only ; Compute the sum of first substring of length K ; Compute the sum of remaining substrings ; Check if sum is equal to that of the first substring ; Since all sums are not equal , return false ; All sums are equal , Return true ; All substrings cannot be of size K ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static bool check ( string str , int K ) { if ( str . Length % K == 0 ) { int sum = 0 , i ; for ( i = 0 ; i < K ; i ++ ) { sum += str [ i ] ; } for ( int j = i ; j < str . Length ; j += K ) { int s_comp = 0 ; for ( int p = j ; p < j + K ; p ++ ) s_comp += str [ p ] ; if ( s_comp != sum ) return false ; } return true ; } return false ; } public static void Main ( string [ ] args ) { int K = 3 ; string str = \\\" abdcbbdba \\\" ; if ( check ( str , K ) ) Console . Write ( \\\" Yes \\\" ) ; else Console . Write ( \\\" No \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find number of times a string occurs as a subsequence in given string | Iterative DP function to find the number of times the second string occurs in the first string , whether continuous or discontinuous ; Create a table to store results of sub - problems ; If second string is empty ; Fill lookup [ ] [ ] in bottom up manner ; If last characters are same , we have two options - 1. consider last characters of both strings in solution 2. ignore last character of first string ; If last character are different , ignore last character of first string ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function count1 ( $ a , $ b ) { $ m = strlen ( $ a ) ; $ n = strlen ( $ b ) ; $ lookup = array_fill ( 0 , $ m + 1 , array_fill ( 0 , $ n + 1 , 0 ) ) ; for ( $ i = 0 ; $ i <= $ m ; ++ $ i ) $ lookup [ $ i ] [ 0 ] = 1 ; for ( $ i = 1 ; $ i <= $ m ; $ i ++ ) { for ( $ j = 1 ; $ j <= $ n ; $ j ++ ) { if ( $ a [ $ i - 1 ] == $ b [ $ j - 1 ] ) $ lookup [ $ i ] [ $ j ] = $ lookup [ $ i - 1 ] [ $ j - 1 ] + $ lookup [ $ i - 1 ] [ $ j ] ; else $ lookup [ $ i ] [ $ j ] = $ lookup [ $ i - 1 ] [ $ j ] ; } } return $ lookup [ $ m ] [ $ n ] ; } $ a = \\\" GeeksforGeeks \\\" ; $ b = \\\" Gks \\\" ; echo count1 ( $ a , $ b ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Search an Element in Doubly Circular Linked List | Python3 program to illustrate inserting a Node in a Cicular Doubly Linked list in begging , end and middle ; Structure of a Node ; Function to insert a node at the end ; If the list is empty , create a single node circular and doubly list ; Find last node ; Create Node dynamically ; Start is going to be next of new_node ; Make new node previous of start ; Make last preivous of new node ; Make new node next of old last ; Function to display the circular doubly linked list ; Function to search the particular element from the list ; Declare the temp variable ; Declare other control variable for the searching ; If start is None return - 1 ; Move the temp pointer until , temp . next doesn 't move start address (Circular Fashion) ; Increment count for location ; If it is found raise the flag and break the loop ; Increment temp pointer ; Check whether last element in the list content the value if contain , raise a flag and increment count ; If flag is true , then element found , else not ; Driver code ; Start with the empty list ; Insert 4. So linked list becomes 4. None ; Insert 5. So linked list becomes 4.5 ; Insert 7. So linked list becomes 4.5 . 7 ; Insert 8. So linked list becomes 4.5 . 7.8 ; Insert 6. So linked list becomes 4.5 . 7.8 . 6\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import math\\nclass Node :\\n\\tdef __init__ ( self , data ) :\\n\\t\\tself . data = data\\n\\t\\tself . next = None\\ndef insertNode ( start , value ) :\\n\\tif ( start == None ) :\\n\\t\\tnew_node = Node ( value )\\n\\t\\tnew_node . data = value\\n\\t\\tnew_node . next = new_node\\n\\t\\tnew_node . prev = new_node\\n\\t\\tstart = new_node\\n\\t\\treturn new_node\\n\\tlast = start . prev\\n\\tnew_node = Node ( value )\\n\\tnew_node . data = value\\n\\tnew_node . next = start\\n\\t( start ) . prev = new_node\\n\\tnew_node . prev = last\\n\\tlast . next = new_node\\n\\treturn start\\ndef displayList ( start ) :\\n\\ttemp = start\\n\\twhile ( temp . next != start ) :\\n\\t\\tprint ( temp . data , end = \\\" ▁ \\\" )\\n\\t\\ttemp = temp . next\\n\\tprint ( temp . data )\\ndef searchList ( start , search ) :\\n\\ttemp = start\\n\\tcount = 0\\n\\tflag = 0\\n\\tvalue = 0\\n\\tif ( temp == None ) :\\n\\t\\treturn - 1\\n\\telse :\\n\\t\\twhile ( temp . next != start ) :\\n\\t\\t\\tcount = count + 1\\n\\t\\t\\tif ( temp . data == search ) :\\n\\t\\t\\t\\tflag = 1\\n\\t\\t\\t\\tcount = count - 1\\n\\t\\t\\t\\tbreak\\n\\t\\t\\ttemp = temp . next\\n\\t\\tif ( temp . data == search ) :\\n\\t\\t\\tcount = count + 1\\n\\t\\t\\tflag = 1\\n\\t\\tif ( flag == 1 ) :\\n\\t\\t\\tprint ( search , \\\" found ▁ at ▁ location ▁ \\\" , count )\\n\\t\\telse :\\n\\t\\t\\tprint ( search , \\\" ▁ not ▁ found \\\" )\\n\\treturn - 1\\nif __name__ == ' _ _ main _ _ ' :\\n\\tstart = None\\n\\tstart = insertNode ( start , 4 )\\n\\tstart = insertNode ( start , 5 )\\n\\tstart = insertNode ( start , 7 )\\n\\tstart = insertNode ( start , 8 )\\n\\tstart = insertNode ( start , 6 )\\n\\tprint ( \\\" Created ▁ circular ▁ doubly ▁ linked ▁ list ▁ is : ▁ \\\" , end = \\\" \\\" )\\n\\tdisplayList ( start )\\n\\tsearchList ( start , 5 )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the head start in a race | Function to find the B start to C ; When B completed it 's 100 meter then Completed meters by C is ; Driver Code ; When A completed it 's 100 meter Then completed meters of B and C is\\\"\\nSolution in php:\",\"targets\":\"< ? php function Race ( $ B , $ C ) { $ result = 0 ; $ result = ( ( $ C * 100 ) \\/ $ B ) ; return 100 - $ result ; } $ B = 10 ; $ C = 28 ; $ B = 100 - $ B ; $ C = 100 - $ C ; echo Race ( $ B , $ C ) . \\\" ▁ meters \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program for factorial of a number | PHP program to find factorial of given number ; single line to find factorial ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function factorial ( $ n ) { return ( $ n == 1 $ n == 0 ) ? 1 : $ n * factorial ( $ n - 1 ) ; } $ num = 5 ; echo \\\" Factorial ▁ of ▁ \\\" , $ num , \\\" ▁ is ▁ \\\" , factorial ( $ num ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Binary Search | C program to implement iterative Binary Search ; A iterative binary search function . It returns location of x in given array arr [ l . . r ] if present , otherwise - 1 ; Check if x is present at mid ; If x greater , ignore left half ; If x is smaller , ignore right half ; if we reach here , then element was not present ; Driver method to test above\\\"\\nSolution in C:\",\"targets\":\"#include \\nint binarySearch ( int arr [ ] , int l , int r , int x ) { while ( l <= r ) { int m = l + ( r - l ) \\/ 2 ; if ( arr [ m ] == x ) return m ; if ( arr [ m ] < x ) l = m + 1 ; else r = m - 1 ; } return -1 ; } int main ( void ) { int arr [ ] = { 2 , 3 , 4 , 10 , 40 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int x = 10 ; int result = binarySearch ( arr , 0 , n - 1 , x ) ; ( result == -1 ) ? printf ( \\\" Element ▁ is ▁ not ▁ present \\\" \\\" ▁ in ▁ array \\\" ) : printf ( \\\" Element ▁ is ▁ present ▁ at ▁ \\\" \\\" index ▁ % d \\\" , result ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Sort an Array which contain 1 to N values in O ( N ) using Cycle Sort | C ++ program for the above approach ; Function to swap two a & b value ; Function to print array element ; Traverse the array ; Function to sort the array in O ( N ) ; Traverse the array ; If the current element is at correct position ; Else swap the current element with it 's correct position ; Driver Code ; Function call to sort the array ; Function call to print the array\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\\" bits \\/ stdc + + . h \\\"\\nusing namespace std ; void swap ( int * a , int * b ) { int temp = * a ; * a = * b ; * b = temp ; } void printArray ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { cout << arr [ i ] << ' ▁ ' ; } } void sortArray ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; ) { if ( arr [ i ] == i + 1 ) { i ++ ; } else { swap ( & arr [ i ] , & arr [ arr [ i ] - 1 ] ) ; } } } int main ( ) { int arr [ ] = { 2 , 1 , 5 , 3 , 4 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; sortArray ( arr , N ) ; printArray ( arr , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimize steps to form string S from any random string of length K using a fixed length subsequences | ''Function to find the minimum number of string required to generate the original string ; '' Stores the frequency of each character of String S ; '' Stores the frequency of each character of String S ; '' Count unique characters in S ; '' If unique characters is greater then N, then return -1 ; '' Otherwise ; '' Perform Binary Search ; '' Find the value of mid ; '' Iterate over the range [0, 26] ; '' If the amount[i] is greater than 0 ; '' Update the ranges ; '' Find the resultant string ; Generate the subsequence ; ' ' ▁ If ▁ the ▁ length ▁ of ▁ resultant ▁ ▁ string ▁ is ▁ less ▁ than ▁ N ▁ than ▁ ▁ add ▁ a ▁ character ▁ ' a ' ; '' Print the string ; ''Driver code\\\"\\nSolution in Python:\",\"targets\":\"def findString ( S , N ) :\\n\\tamounts = [ 0 ] * 26\\n\\tfor i in range ( len ( S ) ) :\\n\\t\\tamounts [ ord ( S [ i ] ) - 97 ] += 1\\n\\tcount = 0\\n\\tfor i in range ( 26 ) :\\n\\t\\tif amounts [ i ] > 0 :\\n\\t\\t\\tcount += 1\\n\\tif count > N :\\n\\t\\tprint ( \\\" - 1\\\" )\\n\\telse :\\n\\t\\tans = \\\" \\\"\\n\\t\\thigh = 100001\\n\\t\\tlow = 0\\n\\t\\twhile ( high - low ) > 1 :\\n\\t\\t\\ttotal = 0\\n\\t\\t\\tmid = ( high + low ) \\/\\/ 2\\n\\t\\t\\tfor i in range ( 26 ) :\\n\\t\\t\\t\\tif amounts [ i ] > 0 :\\n\\t\\t\\t\\t\\ttotal += ( amounts [ i ] - 1 ) \\/\\/ mid + 1\\n\\t\\t\\tif total <= N :\\n\\t\\t\\t\\thigh = mid\\n\\t\\t\\telse :\\n\\t\\t\\t\\tlow = mid\\n\\t\\tprint ( high , end = \\\" ▁ \\\" )\\n\\t\\ttotal = 0\\n\\t\\tfor i in range ( 26 ) :\\n\\t\\t\\tif amounts [ i ] > 0 :\\n\\t\\t\\t\\ttotal += ( amounts [ i ] - 1 ) \\/\\/ high + 1\\n\\t\\t\\t\\tfor j in range ( ( amounts [ i ] - 1 ) \\/\\/ high + 1 ) :\\n\\t\\t\\t\\t\\tans += chr ( i + 97 )\\n\\t\\tfor i in range ( total , N ) :\\n\\t\\t\\tans += ' a '\\n\\t\\tans = ans [ : : - 1 ]\\n\\t\\tprint ( ans )\\nS = \\\" toffee \\\"\\nK = 4\\nfindString ( S , K )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Largest number less than or equal to N in BST ( Iterative Approach ) | Java code to find the largest value smaller than or equal to N ; To create new BST Node ; To insert a new node in BST ; if tree is empty return new node ; if key is less then or greater then node value then recur down the tree ; return the ( unchanged ) node pointer ; Returns largest value smaller than or equal to key . If key is smaller than the smallest , it returns - 1. ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static class Node { int key ; Node left , right ; } ; static Node newNode ( int item ) { Node temp = new Node ( ) ; temp . key = item ; temp . left = temp . right = null ; return temp ; } static Node insert ( Node node , int key ) { if ( node == null ) return newNode ( key ) ; if ( key < node . key ) node . left = insert ( node . left , key ) ; else if ( key > node . key ) node . right = insert ( node . right , key ) ; return node ; } static int findFloor ( Node root , int key ) { Node curr = root , ans = null ; while ( curr != null ) { if ( curr . key <= key ) { ans = curr ; curr = curr . right ; } else curr = curr . left ; } if ( ans != null ) return ans . key ; return - 1 ; } public static void main ( String [ ] args ) { int N = 25 ; Node root = new Node ( ) ; insert ( root , 19 ) ; insert ( root , 2 ) ; insert ( root , 1 ) ; insert ( root , 3 ) ; insert ( root , 12 ) ; insert ( root , 9 ) ; insert ( root , 21 ) ; insert ( root , 19 ) ; insert ( root , 25 ) ; System . out . printf ( \\\" % d \\\" , findFloor ( root , N ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find the sum of all the terms in the n | C # 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\\\"\\nSolution in C#:\",\"targets\":\"using System ; class Test { static int sumOfTermsInNthRow ( int n ) { int sum = ( int ) ( n * ( 2 * Math . Pow ( n , 2 ) + 1 ) ) ; return sum ; } public static void Main ( ) { int n = 4 ; Console . Write ( \\\" Sum ▁ of ▁ all ▁ the ▁ terms ▁ in ▁ nth ▁ row ▁ = ▁ \\\" + sumOfTermsInNthRow ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count numbers from a given range that are not divisible by any of the array elements | Function to find the non - multiples till k ; Stores all unique multiples ; Iterate the array ; For finding duplicates only once ; Inserting all multiples into the set ; Returning only the count of numbers that are not divisible by any of the array elements ; Function to count the total values in the range [ L , R ] ; Count all values in the range using exclusion principle ; Driver Code ; Function Call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function findNonMultiples ( arr , n , k ) { let multiples = new Set ( ) ; for ( let i = 0 ; i < n ; ++ i ) { if ( ! multiples . has ( arr [ i ] ) ) { for ( let j = 1 ; j <= k \\/ arr [ i ] ; j ++ ) { multiples . add ( arr [ i ] * j ) ; } } } return k - multiples . size ; } function countValues ( arr , N , L , R ) { return findNonMultiples ( arr , N , R ) - findNonMultiples ( arr , N , L - 1 ) ; } let arr = [ 2 , 3 , 4 , 5 , 6 ] ; let N = arr . length ; let L = 1 , R = 20 ; document . write ( countValues ( arr , N , L , R ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"Sum of all the numbers that are formed from root to leaf paths | C program to find sum of all paths from root to leaves ; function to allocate new node with given data ; Returns sum of all root to leaf paths . The first parameter is root of current subtree , the second parameter is value of the number formed by nodes from root to this node ; Base case ; Update val ; if current node is leaf , return the current value of val ; recur sum of values for left and right subtree ; A wrapper function over treePathsSumUtil ( ) ; Pass the initial value as 0 as there is nothing above root ; Driver function to test the above functions\\nHow can the above be solved 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 ) ; } int treePathsSumUtil ( struct node * root , int val ) { if ( root == NULL ) return 0 ; val = ( val * 10 + root -> data ) ; if ( root -> left == NULL && root -> right == NULL ) return val ; return treePathsSumUtil ( root -> left , val ) + treePathsSumUtil ( root -> right , val ) ; } int treePathsSum ( struct node * root ) { return treePathsSumUtil ( root , 0 ) ; } int main ( ) { struct node * root = newNode ( 6 ) ; root -> left = newNode ( 3 ) ; root -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 2 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 4 ) ; root -> left -> right -> left = newNode ( 7 ) ; root -> left -> right -> right = newNode ( 4 ) ; printf ( \\\" Sum ▁ of ▁ all ▁ paths ▁ is ▁ % d \\\" , treePathsSum ( root ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum pairs required to be removed such that the array does not contain any pair with sum K | Java program for the above approach ; Function to find the maximum count of pairs required to be removed such that no pairs exist whose sum equal to K ; Stores maximum count of pairs required to be removed such that no pairs exist whose sum equal to K ; Base Case ; Sort the array ; Stores index of left pointer ; Stores index of right pointer ; Stores sum of left and right pointer ; If s equal to k ; Update cntPairs ; Update left ; Update right ; If s > k ; Update right ; Update left ; Return the cntPairs ; Driver Code ; Function call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static int maxcntPairsSumKRemoved ( int [ ] arr , int k ) { int cntPairs = 0 ; if ( arr . length <= 1 ) return cntPairs ; Arrays . sort ( arr ) ; int left = 0 ; int right = arr . length - 1 ; while ( left < right ) { int s = arr [ left ] + arr [ right ] ; if ( s == k ) { cntPairs += 1 ; left += 1 ; right -= 1 ; } else if ( s > k ) right -= 1 ; else left += 1 ; } return cntPairs ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 } ; int K = 5 ; System . out . println ( maxcntPairsSumKRemoved ( arr , K ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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\\\"\\nSolution in Python:\",\"targets\":\"def MinOperations ( n , x , arr ) :\\n\\ttotal = 0\\n\\tfor i in range ( n ) :\\n\\t\\tif ( arr [ i ] > x ) :\\n\\t\\t\\tdifference = arr [ i ] - x\\n\\t\\t\\ttotal = total + difference\\n\\t\\t\\tarr [ i ] = x\\n\\tfor i in range ( n ) :\\n\\t\\tLeftNeigbouringSum = arr [ i ] + arr [ i - 1 ]\\n\\t\\tif ( LeftNeigbouringSum > x ) :\\n\\t\\t\\tcurrent_diff = LeftNeigbouringSum - x\\n\\t\\t\\tarr [ i ] = max ( 0 , arr [ i ] - current_diff )\\n\\t\\t\\ttotal = total + current_diff\\n\\treturn total\\nX = 1\\narr = [ 1 , 6 , 1 , 2 , 0 , 4 ]\\nN = len ( arr )\\nprint ( MinOperations ( N , X , arr ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if X and Y elements can be selected from two arrays respectively such that the maximum in X is less than the minimum in Y | C ++ program for the above approach ; Function to check if it is possible to choose X and Y elements from a [ ] and b [ ] such that maximum element among X element is less than minimum element among Y elements ; Check if there are atleast X elements in arr1 [ ] and atleast Y elements in arr2 [ ] ; Sort arrays in ascending order ; Check if ( X - 1 ) - th element in arr1 [ ] is less than from M - Yth element in arr2 [ ] ; Return false ; Driver Code ; Function Call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; string check ( int a [ ] , int b [ ] , int Na , int Nb , int k , int m ) { if ( Na < k Nb < m ) return \\\" No \\\" ; sort ( a , a + Na ) ; sort ( b , b + Nb ) ; if ( a [ k - 1 ] < b [ Nb - m ] ) { return \\\" Yes \\\" ; } return \\\" No \\\" ; } int main ( ) { int arr1 [ ] = { 1 , 2 , 3 } ; int arr2 [ ] = { 3 , 4 , 5 } ; int N = sizeof ( arr1 ) \\/ sizeof ( arr1 [ 0 ] ) ; int M = sizeof ( arr2 ) \\/ sizeof ( arr2 [ 0 ] ) ; int X = 2 , Y = 1 ; cout << check ( arr1 , arr2 , N , M , X , Y ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Manacher 's Algorithm | Python program to implement Manacher 's Algorithm ; Position count ; LPS Length Array ; centerPosition ; centerRightPosition ; currentRightPosition ; currentLeftPosition ; Uncomment it to print LPS Length array printf ( \\\" % d ▁ % d ▁ \\\" , L [ 0 ] , L [ 1 ] ) ; ; get currentLeftPosition iMirror for currentRightPosition i ; If currentRightPosition i is within centerRightPosition R ; Attempt to expand palindrome centered at currentRightPosition i Here for odd positions , we compare characters and if match then increment LPS Length by ONE If even position , we just increment LPS by ONE without any character comparison ; Track maxLPSLength ; If palindrome centered at currentRightPosition i expand beyond centerRightPosition R , adjust centerPosition C based on expanded palindrome . ; Uncomment it to print LPS Length array printf ( \\\" % d ▁ \\\" , L [ i ] ) ; ; Driver program\\\"\\nSolution in Python:\",\"targets\":\"def findLongestPalindromicString ( text ) :\\n\\tN = len ( text )\\n\\tif N == 0 :\\n\\t\\treturn\\n\\tN = 2 * N + 1\\n\\tL = [ 0 ] * N\\n\\tL [ 0 ] = 0\\n\\tL [ 1 ] = 1\\n\\tC = 1\\n\\tR = 2\\n\\ti = 0\\n\\tiMirror = 0\\n\\tmaxLPSLength = 0\\n\\tmaxLPSCenterPosition = 0\\n\\tstart = - 1\\n\\tend = - 1\\n\\tdiff = - 1\\n\\tfor i in xrange ( 2 , N ) :\\n\\t\\tiMirror = 2 * C - i\\n\\t\\tL [ i ] = 0\\n\\t\\tdiff = R - i\\n\\t\\tif diff > 0 :\\n\\t\\t\\tL [ i ] = min ( L [ iMirror ] , diff )\\n\\t\\ttry :\\n\\t\\t\\twhile ( ( i + L [ i ] ) < N and ( i - L [ i ] ) > 0 ) and ( ( ( i + L [ i ] + 1 ) % 2 == 0 ) or ( text [ ( i + L [ i ] + 1 ) \\/ 2 ] == text [ ( i - L [ i ] - 1 ) \\/ 2 ] ) ) :\\n\\t\\t\\t\\tL [ i ] += 1\\n\\t\\texcept Exception as e :\\n\\t\\t\\tpass\\n\\t\\tif L [ i ] > maxLPSLength :\\n\\t\\t\\tmaxLPSLength = L [ i ]\\n\\t\\t\\tmaxLPSCenterPosition = i\\n\\t\\tif i + L [ i ] > R :\\n\\t\\t\\tC = i\\n\\t\\t\\tR = i + L [ i ]\\n\\tstart = ( maxLPSCenterPosition - maxLPSLength ) \\/ 2\\n\\tend = start + maxLPSLength - 1\\n\\tprint \\\" LPS ▁ of ▁ string ▁ is ▁ \\\" + text + \\\" ▁ : ▁ \\\" ,\\n\\tprint text [ start : end + 1 ] ,\\n\\tprint \\\"\\n\\\" ,\\ntext1 = \\\" babcbabcbaccba \\\"\\nfindLongestPalindromicString ( text1 )\\ntext2 = \\\" abaaba \\\"\\nfindLongestPalindromicString ( text2 )\\ntext3 = \\\" abababa \\\"\\nfindLongestPalindromicString ( text3 )\\ntext4 = \\\" abcbabcbabcba \\\"\\nfindLongestPalindromicString ( text4 )\\ntext5 = \\\" forgeeksskeegfor \\\"\\nfindLongestPalindromicString ( text5 )\\ntext6 = \\\" caba \\\"\\nfindLongestPalindromicString ( text6 )\\ntext7 = \\\" abacdfgdcaba \\\"\\nfindLongestPalindromicString ( text7 )\\ntext8 = \\\" abacdfgdcabba \\\"\\nfindLongestPalindromicString ( text8 )\\ntext9 = \\\" abacdedcaba \\\"\\nfindLongestPalindromicString ( text9 )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Size of the smallest subset with maximum Bitwise OR | Java Program for above approach ; Compute bitwise or of all elements in array of size sz ; Recursively calculating the size of minimum subset with maximum or ; If i is arr . length ; If curOr is equal to maxOr ; Return arr . length ; Try the current element in the subset ; Skip the current element ; Return minimum of take and notTake ; Driver Code ; Function Call\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; import java . util . * ; class Solution { private static int OR ( int [ ] arr ) { int mOR = 0 ; for ( int i = 0 ; i < arr . length ; ++ i ) { mOR |= arr [ i ] ; } return mOR ; } private static int maxSubset ( int [ ] arr , int i , int curOr , int curSize , int maxOr ) { if ( i == arr . length ) { if ( curOr == maxOr ) { return curSize ; } else { return arr . length ; } } int take = maxSubset ( arr , i + 1 , curOr arr [ i ] , curSize + 1 , maxOr ) ; int notTake = maxSubset ( arr , i + 1 , curOr , curSize , maxOr ) ; return Math . min ( take , notTake ) ; } public static void main ( String [ ] args ) { int [ ] data = { 5 , 1 , 3 , 4 , 2 } ; int maxOr = OR ( data ) ; int maxSubsetSize = maxSubset ( data , 0 , 0 , 0 , maxOr ) ; System . out . println ( maxSubsetSize ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count n digit numbers not having a particular digit | C ++ Implementation of above method ; Finding number of possible number with n digits excluding a particular digit ; Checking if number of digits is zero ; Checking if number of digits is one ; Checking if number of digits is odd ; Calling digitNumber function with ( digit - 1 ) \\/ 2 digits ; Calling digitNumber function with n \\/ 2 digits ; Calling digitNumber function Checking if excluding digit is zero or non - zero ; Driver function to run above program ; Initializing variables\\\"\\nSolution in C++:\",\"targets\":\"#include \\n#define mod 1000000007\\nusing namespace std ; long long digitNumber ( long long n ) { if ( n == 0 ) return 1 ; if ( n == 1 ) return 9 ; if ( n % 2 ) { long long temp = digitNumber ( ( n - 1 ) \\/ 2 ) % mod ; return ( 9 * ( temp * temp ) % mod ) % mod ; } else { long long temp = digitNumber ( n \\/ 2 ) % mod ; return ( temp * temp ) % mod ; } } int countExcluding ( int n , int d ) { if ( d == 0 ) return ( 9 * digitNumber ( n - 1 ) ) % mod ; else return ( 8 * digitNumber ( n - 1 ) ) % mod ; } int main ( ) { long long d = 9 ; int n = 3 ; cout << countExcluding ( n , d ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find the Kth position element of the given sequence | Function to return the kth number from the required sequence ; Count of odd integers in the sequence ; kth number is even ; It is odd ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def kthNum ( n , k ) :\\n\\ta = ( n + 1 ) \\/\\/ 2 ;\\n\\tif ( k > a ) :\\n\\t\\treturn ( 2 * ( k - a ) ) ;\\n\\treturn ( 2 * k - 1 ) ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tn = 7 ; k = 7 ;\\n\\tprint ( kthNum ( n , k ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to construct array with even product from given array such that absolute difference of same indexed elements is at most 1 | Java Program to implement the above approach ; Function to find count the ways to construct an array , B [ ] such that abs ( A [ i ] - B [ i ] ) <= 1 and product of elements of B [ ] is even ; Stores count of arrays B [ ] such that abs ( A [ i ] - B [ i ] ) <= 1 ; Stores count of arrays B [ ] whose product of elements is not even ; Traverse the array ; Update total ; If A [ i ] is an even number ; Update oddArray ; Print 3 ^ N - 2 ^ X ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static void cntWaysConsArray ( int A [ ] , int N ) { int total = 1 ; int oddArray = 1 ; for ( int i = 0 ; i < N ; i ++ ) { total = total * 3 ; if ( A [ i ] % 2 == 0 ) { oddArray *= 2 ; } } System . out . println ( total - oddArray ) ; } public static void main ( String [ ] args ) { int A [ ] = { 2 , 4 } ; int N = A . length ; cntWaysConsArray ( A , N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find the element in a linked list with frequency at least N \\/ 3 | C ++ program to find an element with frequency of at least N \\/ 3 in a linked list ; Structure of a node for the linked list ; Utility function to create a node ; Function to find and return the element with frequency of at least N \\/ 3 ; Candidates for being the required majority element ; Store the frequencies of the respective candidates ; Iterate all nodes ; Increase frequency of candidate s ; Increase frequency of candidate t ; Set the new sting as candidate for majority ; Set the new sting as second candidate for majority ; Decrease the frequency ; Check the frequency of two final selected candidate linklist ; Increase the frequency of first candidate ; Increase the frequency of second candidate ; Return the string with higher frequency ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; struct node { string i ; node * next = NULL ; } ; struct node * newnode ( string s ) { struct node * temp = ( struct node * ) malloc ( sizeof ( struct node ) ) ; temp -> i = s ; temp -> next = NULL ; return temp ; } string Majority_in_linklist ( node * head ) { string s = \\\" \\\" , t = \\\" \\\" ; int p = 0 , q = 0 ; node * ptr = NULL ; while ( head != NULL ) { if ( s . compare ( head -> i ) == 0 ) { p = p + 1 ; } else { if ( t . compare ( head -> i ) == 0 ) { q = q + 1 ; } else { if ( p == 0 ) { s = head -> i ; p = 1 ; } else { if ( q == 0 ) { t = head -> i ; q = 1 ; } else { p = p - 1 ; q = q - 1 ; } } } } head = head -> next ; } head = ptr ; p = 0 ; q = 0 ; while ( head != NULL ) { if ( s . compare ( head -> i ) == 0 ) { p = 1 ; } else { if ( t . compare ( head -> i ) == 0 ) { q = 1 ; } } head = head -> next ; } if ( p > q ) { return s ; } else { return t ; } } int main ( ) { node * ptr = NULL ; node * head = newnode ( \\\" geeks \\\" ) ; head -> next = newnode ( \\\" geeks \\\" ) ; head -> next -> next = newnode ( \\\" abcd \\\" ) ; head -> next -> next -> next = newnode ( \\\" game \\\" ) ; head -> next -> next -> next -> next = newnode ( \\\" game \\\" ) ; head -> next -> next -> next -> next -> next = newnode ( \\\" knight \\\" ) ; head -> next -> next -> next -> next -> next -> next = newnode ( \\\" harry \\\" ) ; head -> next -> next -> next -> next -> next -> next -> next = newnode ( \\\" geeks \\\" ) ; cout << Majority_in_linklist ( head ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Smallest character in a string having minimum sum of distances between consecutive repetitions | C # program for the above approach ; Function to find the character repeats with minimum distance ; Stores the first and last index ; Initialize with - 1 ; Get the values of last and first occurence ; Update the first index ; Update the last index ; Initialize min ; Get the minimum ; Values must not be same ; Update the minimum distance ; return ans ; Driver Code ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static char minDistChar ( char [ ] s ) { int n = s . Length ; int [ ] first = new int [ 26 ] ; int [ ] last = new int [ 26 ] ; for ( int i = 0 ; i < 26 ; i ++ ) { first [ i ] = - 1 ; last [ i ] = - 1 ; } for ( int i = 0 ; i < n ; i ++ ) { if ( first [ s [ i ] - ' a ' ] == - 1 ) { first [ s [ i ] - ' a ' ] = i ; } last [ s [ i ] - ' a ' ] = i ; } int min = int . MaxValue ; char ans = '1' ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( last [ i ] == first [ i ] ) continue ; if ( min > last [ i ] - first [ i ] ) { min = last [ i ] - first [ i ] ; ans = ( char ) ( i + ' a ' ) ; } } return ans ; } public static void Main ( string [ ] args ) { String str = \\\" geeksforgeeks \\\" ; Console . Write ( minDistChar ( str . ToCharArray ( ) ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Make largest palindrome by changing at most K | Java program to get largest palindrome changing atmost K digits ; Returns maximum possible palindrome using k changes ; Initialize l and r by leftmost and rightmost ends ; First try to make String palindrome ; Replace left and right character by maximum of both ; If k is negative then we can 't make String palindrome ; At mid character , if K > 0 then change it to 9 ; If character at lth ( same as rth ) is less than 9 ; If none of them is changed in the previous loop then subtract 2 from K and convert both to 9 ; If one of them is changed in the previous loop then subtract 1 from K ( 1 more is subtracted already ) and make them 9 ; Driver code to test above methods\\\"\\nSolution in Java:\",\"targets\":\"import java . text . ParseException ; class GFG { static String maximumPalinUsingKChanges ( String str , int k ) { char palin [ ] = str . toCharArray ( ) ; String ans = \\\" \\\" ; int l = 0 ; int r = str . length ( ) - 1 ; while ( l < r ) { if ( str . charAt ( l ) != str . charAt ( r ) ) { palin [ l ] = palin [ r ] = ( char ) Math . max ( str . charAt ( l ) , str . charAt ( r ) ) ; k -- ; } l ++ ; r -- ; } if ( k < 0 ) { return \\\" Not ▁ possible \\\" ; } l = 0 ; r = str . length ( ) - 1 ; while ( l <= r ) { if ( l == r ) { if ( k > 0 ) { palin [ l ] = '9' ; } } if ( palin [ l ] < '9' ) { if ( k >= 2 && palin [ l ] == str . charAt ( l ) && palin [ r ] == str . charAt ( r ) ) { k -= 2 ; palin [ l ] = palin [ r ] = '9' ; } else if ( k >= 1 && ( palin [ l ] != str . charAt ( l ) || palin [ r ] != str . charAt ( r ) ) ) { k -- ; palin [ l ] = palin [ r ] = '9' ; } } l ++ ; r -- ; } for ( int i = 0 ; i < palin . length ; i ++ ) ans += palin [ i ] ; return ans ; } public static void main ( String [ ] args ) throws ParseException { String str = \\\"43435\\\" ; int k = 3 ; System . out . println ( maximumPalinUsingKChanges ( str , k ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Efficiently check whether n is a multiple of 4 or not | function to check whether ' n ' is a multiple of 4 or not ; if true , then ' n ' is a multiple of 4 ; else ' n ' is not a multiple of 4 ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function isAMultipleOf4 ( $ n ) { if ( ( $ n & 3 ) == 0 ) return \\\" Yes \\\" ; return \\\" No \\\" ; } $ n = 16 ; echo isAMultipleOf4 ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Pell Number | calculate nth pell number ; Driver Code\\\"\\nSolution 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\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Pairs with GCD equal to one in the given range | Function to print all pairs ; check if even ; we can print all adjacent pairs for i in range ( l , r , 2 ) : print ( \\\" { \\\" , i , \\\" , \\\" , i + 1 , \\\" } , \\\" ) ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def checkPairs ( l , r ) :\\n\\tif ( l - r ) % 2 == 0 :\\n\\t\\treturn False\\n\\treturn True\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tl , r = 1 , 8\\n\\tif checkPairs ( l , r ) :\\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\":\"\\\"Calculate nCr using Pascal 's Triangle | C ++ implementation of the approach ; Initialize the matrix with 0 ; 0 C0 = 1 ; Set every nCr = 1 where r = 0 ; Value for the current cell of Pascal 's triangle ; Function to return the value of nCr ; Return nCr ; Driver code ; Build the Pascal 's triangle\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int l [ 1001 ] [ 1001 ] = { 0 } ; void initialize ( ) { l [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i < 1001 ; i ++ ) { l [ i ] [ 0 ] = 1 ; for ( int j = 1 ; j < i + 1 ; j ++ ) { l [ i ] [ j ] = ( l [ i - 1 ] [ j - 1 ] + l [ i - 1 ] [ j ] ) ; } } } int nCr ( int n , int r ) { return l [ n ] [ r ] ; } int main ( ) { initialize ( ) ; int n = 8 ; int r = 3 ; cout << nCr ( n , r ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Number of Asymmetric Relations on a set of N elements | Javascript program for the above approach ; Function to calculate x ^ y modulo ( 10 ^ 9 + 7 ) ; Stores the result of x ^ y ; Update x if it exceeds mod ; If x is divisible by mod ; If y is odd , then multiply x with result ; Divide y by 2 ; Update the value of x ; Return the final value of x ^ y ; Function to count the number of asymmetric relations in a set consisting of N elements ; Return the resultant count ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"var mod = 1000000007 ; function power ( x , y ) { var res = 1 ; x = x % mod ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } function asymmetricRelation ( N ) { return power ( 3 , ( N * N - N ) \\/ 2 ) ; } var N = 2 ; document . write ( asymmetricRelation ( N ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find maximum average subarray of k length | C ++ program to find maximum average subarray of given 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 program\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int findMaxAverage ( int arr [ ] , int n , int k ) { if ( k > n ) return -1 ; int sum = arr [ 0 ] ; for ( int i = 1 ; i < k ; i ++ ) sum += arr [ i ] ; int max_sum = sum , max_end = k - 1 ; for ( int i = k ; i < n ; i ++ ) { int sum = sum + arr [ i ] - arr [ i - k ] ; if ( sum > max_sum ) { max_sum = sum ; max_end = i ; } } return max_end - k + 1 ; } int main ( ) { int arr [ ] = { 1 , 12 , -5 , -6 , 50 , 3 } ; int k = 4 ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << \\\" The ▁ maximum ▁ average ▁ subarray ▁ of ▁ \\\" \\\" length ▁ \\\" << k << \\\" ▁ begins ▁ at ▁ index ▁ \\\" << findMaxAverage ( arr , n , k ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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 ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GFG { static void checkHV ( int [ , ] arr , int N , int M ) { bool horizontal = true ; bool 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 ] ) { horizontal = false ; break ; } } } if ( ! horizontal && ! vertical ) Console . WriteLine ( \\\" NO \\\" ) ; else if ( horizontal && ! vertical ) Console . WriteLine ( \\\" HORIZONTAL \\\" ) ; else if ( vertical && ! horizontal ) Console . WriteLine ( \\\" VERTICAL \\\" ) ; else Console . WriteLine ( \\\" BOTH \\\" ) ; } static public void Main ( ) { int [ , ] mat = { { 1 , 0 , 1 } , { 0 , 0 , 0 } , { 1 , 0 , 1 } } ; checkHV ( mat , 3 , 3 ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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\\\"\\nHow can the above be solved 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\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Subtract two numbers without using arithmetic operators | ; Driver program\\\"\\nSolution in C:\",\"targets\":\"#include \\nint subtract ( int x , int y ) { if ( y == 0 ) return x ; return subtract ( x ^ y , ( ~ x & y ) << 1 ) ; } int main ( ) { int x = 29 , y = 13 ; printf ( \\\" x ▁ - ▁ y ▁ is ▁ % d \\\" , subtract ( x , y ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Longest substring such that no three consecutive characters are same | 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 JS?\",\"targets\":\"function maxLenSubStr ( s ) { if ( s . length < 3 ) return s . length ; let temp = 2 ; let ans = 2 ; for ( let i = 2 ; i < s . length ; i ++ ) { if ( s [ i ] != s [ i - 1 ] s [ i ] != s [ i - 2 ] ) temp ++ ; else { ans = Math . max ( temp , ans ) ; temp = 2 ; } } ans = Math . max ( temp , ans ) ; return ans ; } let s = \\\" \\\" ; document . write ( maxLenSubStr ( s ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Longest Palindromic Subsequence | DP | Returns the length of the longest palindromic subsequence in seq ; Base Case 1 : If there is only 1 character ; Base Case 2 : If there are only 2 characters and both are same ; If the first and last characters match ; If the first and last characters do not match ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function lps ( $ seq , $ i , $ j ) { if ( $ i == $ j ) return 1 ; if ( $ seq [ $ i ] == $ seq [ $ j ] && $ i + 1 == $ j ) return 2 ; if ( $ seq [ $ i ] == $ seq [ $ j ] ) return lps ( $ seq , $ i + 1 , $ j - 1 ) + 2 ; return max ( lps ( $ seq , $ i , $ j - 1 ) , lps ( $ seq , $ i + 1 , $ j ) ) ; } $ seq = \\\" GEEKSFORGEEKS \\\" ; $ n = strlen ( $ seq ) ; echo \\\" The ▁ length ▁ of ▁ the ▁ LPS ▁ is ▁ \\\" . lps ( $ seq , 0 , $ n - 1 ) ; ? >\",\"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 | 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\\\"\\nSolution 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 ▁ minimum ▁ element ▁ is ▁ % d \\n \\\" , findMin ( arr1 , 0 , n1 - 1 ) ) ; int arr2 [ ] = { 1 , 2 , 3 , 4 } ; int n2 = sizeof ( arr2 ) \\/ sizeof ( arr2 [ 0 ] ) ; printf ( \\\" The ▁ minimum ▁ element ▁ is ▁ % d \\n \\\" , findMin ( arr2 , 0 , n2 - 1 ) ) ; int arr3 [ ] = { 1 } ; int n3 = sizeof ( arr3 ) \\/ sizeof ( arr3 [ 0 ] ) ; printf ( \\\" The ▁ minimum ▁ element ▁ is ▁ % d \\n \\\" , findMin ( arr3 , 0 , n3 - 1 ) ) ; int arr4 [ ] = { 1 , 2 } ; int n4 = sizeof ( arr4 ) \\/ sizeof ( arr4 [ 0 ] ) ; printf ( \\\" The ▁ minimum ▁ element ▁ is ▁ % d \\n \\\" , findMin ( arr4 , 0 , n4 - 1 ) ) ; int arr5 [ ] = { 2 , 1 } ; int n5 = sizeof ( arr5 ) \\/ sizeof ( arr5 [ 0 ] ) ; printf ( \\\" The ▁ minimum ▁ element ▁ is ▁ % 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 ▁ minimum ▁ element ▁ is ▁ % 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 ▁ minimum ▁ element ▁ is ▁ % 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 ▁ minimum ▁ element ▁ is ▁ % d \\n \\\" , findMin ( arr8 , 0 , n8 - 1 ) ) ; int arr9 [ ] = { 3 , 4 , 5 , 1 , 2 } ; int n9 = sizeof ( arr9 ) \\/ sizeof ( arr9 [ 0 ] ) ; printf ( \\\" The ▁ minimum ▁ element ▁ is ▁ % d \\n \\\" , findMin ( arr9 , 0 , n9 - 1 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to find Nth term of series 1 , 6 , 17 , 34 , 56 , 86 , 121 , 162 , ... ... . | C ++ program to find the N - th term of the series : 1 , 6 , 17 , 34 , 56 , 86 , 121 , 162 , ... . . ; calculate Nth term of series ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#include \\nusing namespace std ; int nthTerm ( int n ) { return 3 * pow ( n , 2 ) - 4 * n + 2 ; } int main ( ) { int N = 4 ; cout << nthTerm ( N ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Lexicographically smallest string with given string as prefix | Function to find the whether the string temp starts with str or not ; Base Case ; Check for the corresponding characters in temp & str ; Function to find lexicographic smallest string consisting of the string str as prefix ; Sort the given array string arr [ ] ; If the i - th string contains given string as a prefix , then print the result ; If no string exists then return \\\" - 1\\\" ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def is_prefix ( temp , str ) :\\n\\tif ( len ( temp ) < len ( str ) ) :\\n\\t\\treturn 0\\n\\telse :\\n\\t\\tfor i in range ( len ( str ) ) :\\n\\t\\t\\tif ( str [ i ] != temp [ i ] ) :\\n\\t\\t\\t\\treturn 0\\n\\t\\treturn 1\\ndef lexicographicallyString ( input , n , str ) :\\n\\tinput . sort ( )\\n\\tfor i in range ( n ) :\\n\\t\\ttemp = input [ i ]\\n\\t\\tif ( is_prefix ( temp , str ) ) :\\n\\t\\t\\treturn temp\\n\\treturn \\\" - 1\\\"\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ \\\" apple \\\" , \\\" appe \\\" , \\\" apl \\\" , \\\" aapl \\\" , \\\" appax \\\" ]\\n\\tS = \\\" app \\\"\\n\\tN = 5\\n\\tprint ( lexicographicallyString ( arr , N , S ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Insert minimum number in array so that sum of array becomes prime | Javascript program to find minimum number to insert in array so their sum is prime ; Array to store primes ; 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 program\\\"\\nHow can the above be solved in JS?\",\"targets\":\"let MAX = 100005 ; let isPrime = new Array ( MAX ) . fill ( 0 ) ; function sieveOfEratostheneses ( ) { isPrime [ 1 ] = true ; for ( let i = 2 ; i * i < MAX ; i ++ ) { if ( ! isPrime [ i ] ) { for ( let j = 2 * i ; j < MAX ; j += i ) isPrime [ j ] = true ; } } } function findPrime ( n ) { let num = n + 1 ; while ( num > 0 ) { if ( ! isPrime [ num ] ) return num ; num = num + 1 ; } return 0 ; } function minNumber ( arr , n ) { sieveOfEratostheneses ( ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( ! isPrime [ sum ] ) return 0 ; let num = findPrime ( sum ) ; return num - sum ; } let arr = [ 2 , 4 , 6 , 8 , 12 ] ; let n = arr . length ; document . write ( minNumber ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\":\"\\\"Count of subsequences in an array with sum less than or equal to X | Utility function to return the count of subsequence in an array with sum less than or equal to X ; Base condition ; Return if the sub - problem is already calculated ; Check if the current element is less than or equal to sum ; Count subsequences excluding the current element ; Count subsequences including the current element ; Exclude current element ; Return the result ; Function to return the count of subsequence in an array with sum less than or equal to X ; Initialize a DP array ; Return the result ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function countSubsequenceUtil ( ind , sum , A , N , dp ) { if ( ind == N ) return 1 ; if ( dp [ ind ] [ sum ] != - 1 ) return dp [ ind ] [ sum ] ; if ( A [ ind ] <= sum ) { dp [ ind ] [ sum ] = countSubsequenceUtil ( ind + 1 , sum , A , N , dp ) + countSubsequenceUtil ( ind + 1 , sum - A [ ind ] , A , N , dp ) ; } else { dp [ ind ] [ sum ] = countSubsequenceUtil ( ind + 1 , sum , A , N , dp ) ; } return dp [ ind ] [ sum ] ; } function countSubsequence ( A , N , X ) { let dp = new Array ( N ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < X + 1 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } return countSubsequenceUtil ( 0 , X , A , N , dp ) - 1 ; } let arr = [ 25 , 13 , 40 ] , X = 50 ; let N = arr . length ; document . write ( countSubsequence ( arr , N , X ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Number of paths with exactly k coins | A Naive Recursive PHP program to count paths with exactly ' k ' coins ; Recursive function to count paths with sum k from ( 0 , 0 ) to ( m , n ) ; Base cases ; ( m , n ) can be reached either through ( m - 1 , n ) or through ( m , n - 1 ) ; A wrapper over pathCountRec ( ) ; Driver program\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ R = 3 ; $ C = 3 ; function pathCountRec ( $ mat , $ m , $ n , $ k ) { if ( $ m < 0 or $ n < 0 ) return 0 ; if ( $ m == 0 and $ n == 0 ) return ( $ k == $ mat [ $ m ] [ $ n ] ) ; return pathCountRec ( $ mat , $ m - 1 , $ n , $ k - $ mat [ $ m ] [ $ n ] ) + pathCountRec ( $ mat , $ m , $ n - 1 , $ k - $ mat [ $ m ] [ $ n ] ) ; } function pathCount ( $ mat , $ k ) { global $ R , $ C ; return pathCountRec ( $ mat , $ R - 1 , $ C - 1 , $ k ) ; } $ k = 12 ; $ mat = array ( array ( 1 , 2 , 3 ) , array ( 4 , 6 , 5 ) , array ( 3 , 2 , 1 ) ) ; echo pathCount ( $ mat , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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 ▁ Number ▁ of ▁ A ' s ▁ with ▁ % d ▁ keystrokes ▁ is ▁ % d \\n \\\" , N , findoptimal ( N ) ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Convert given Strings into T by replacing characters in between strings any number of times | c # program for the above approach ; Function to check if it possible to make all the strings equal to the string T ; Stores the frequency of all the strings in the array arr [ ] ; Stores the frequency of the string T ; Iterate over the characters of the string T ; Iterate in the range [ 0 , N - 1 ] ; Iterate over the characters of the string arr [ i ] ; If freqT [ i ] is 0 and freqS [ i ] is not 0 ; If freqS [ i ] is 0 and freqT [ i ] is not 0 ; If freqS [ i ] is not freqT [ i ] * N ; Otherwise , return \\\" Yes \\\" ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GFG { static string checkIfPossible ( int N , string [ ] arr , string T ) { int [ ] freqS = new int [ 256 ] ; int [ ] freqT = new int [ 256 ] ; foreach ( char ch in T . ToCharArray ( ) ) { freqT [ ch - ' a ' ] ++ ; } for ( int i = 0 ; i < N ; i ++ ) { foreach ( char ch in arr [ i ] . ToCharArray ( ) ) { freqS [ ch - ' a ' ] ++ ; } } for ( int i = 0 ; i < 256 ; i ++ ) { if ( freqT [ i ] == 0 && freqS [ i ] != 0 ) { return \\\" No \\\" ; } else if ( freqS [ i ] == 0 && freqT [ i ] != 0 ) { return \\\" No \\\" ; } else if ( freqT [ i ] != 0 && freqS [ i ] != ( freqT [ i ] * N ) ) { return \\\" No \\\" ; } } return \\\" Yes \\\" ; } public static void Main ( string [ ] args ) { string [ ] arr = { \\\" abc \\\" , \\\" abb \\\" , \\\" acc \\\" } ; string T = \\\" abc \\\" ; int N = arr . Length ; Console . WriteLine ( checkIfPossible ( N , arr , T ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Tetranacci Numbers | A DP based C # program to print the nth tetranacci number ; Function to print the N - th tetranacci number ; base cases ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"class GFG { static void printTetra ( int n ) { int [ ] dp = new int [ n + 5 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = dp [ 2 ] = 1 ; dp [ 3 ] = 2 ; for ( int i = 4 ; i <= n ; i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + dp [ i - 3 ] + dp [ i - 4 ] ; System . Console . WriteLine ( dp [ n ] ) ; } 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\":\"\\\"Sum of Area of all possible square inside a rectangle | Function to calculate the sum of area of all possible squares that comes inside the rectangle ; Square with max size possible ; calculate total square of a given size ; calculate area of squares of a particular size ; total area ; increment size ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function calculateAreaSum ( $ l , $ b ) { $ size = 1 ; $ maxSize = min ( $ l , $ b ) ; $ totalArea = 0 ; for ( $ i = 1 ; $ i <= $ maxSize ; $ i ++ ) { $ totalSquares = ( $ l - $ size + 1 ) * ( $ b - $ size + 1 ) ; $ area = $ totalSquares * $ size * $ size ; $ totalArea += $ area ; $ size ++ ; } return $ totalArea ; } $ l = 4 ; $ b = 3 ; echo calculateAreaSum ( $ l , $ b ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Subtract two numbers without using arithmetic operators | javascript Program to subtract two Number without using arithmetic operator Recursive implementation . ; Driver program\\\"\\nSolution in Javascript:\",\"targets\":\"function subtract ( x , y ) { if ( y == 0 ) return x ; return subtract ( x ^ y , ( ~ x & y ) << 1 ) ; } var x = 29 , y = 13 ; document . write ( \\\" \\\" + subtract ( x , y ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"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\\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 ▁ \\\" , i ) ; } if ( i - ( n \\/ i ) == 1 ) { i -- ; } for ( ; i >= 1 ; i -- ) { if ( n % i == 0 ) printf ( \\\" % d ▁ \\\" , n \\/ i ) ; } } int main ( ) { printf ( \\\" The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ \\n \\\" ) ; printDivisors ( 100 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-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\\\"\\nSolution in php:\",\"targets\":\"< ? php function minOperations ( $ arr , $ n ) { $ result = 0 ; $ freq = array ( ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ freq [ $ arr [ $ i ] ] = 0 ; } for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ x = $ arr [ $ i ] ; $ freq [ $ x ] ++ ; } $ maxi = max ( $ arr ) ; for ( $ i = 1 ; $ i <= $ maxi ; $ i ++ ) { if ( $ freq [ $ i ] != 0 ) { for ( $ j = $ i * 2 ; $ j <= $ maxi ; $ j = $ j + $ i ) { $ freq [ $ j ] = 0 ; } $ result ++ ; } } return $ result ; } $ arr = array ( 2 , 4 , 2 , 4 , 4 , 4 ) ; $ n = count ( $ arr ) ; echo minOperations ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Longest substring such that no three consecutive characters are same | 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\\\"\\nSolution in Python:\",\"targets\":\"def maxLenSubStr ( s ) :\\n\\tif ( len ( s ) < 3 ) :\\n\\t\\treturn len ( s )\\n\\ttemp = 2\\n\\tans = 2\\n\\tfor i in range ( 2 , len ( s ) ) :\\n\\t\\tif ( s [ i ] != s [ i - 1 ] or s [ i ] != s [ i - 2 ] ) :\\n\\t\\t\\ttemp += 1\\n\\t\\telse :\\n\\t\\t\\tans = max ( temp , ans )\\n\\t\\t\\ttemp = 2\\n\\tans = max ( temp , ans )\\n\\treturn ans\\ns = \\\" baaabbabbb \\\"\\nprint ( maxLenSubStr ( s ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"Doubly Linked List | Set 1 ( Introduction and Insertion ) | Given a reference ( pointer to pointer ) to the head of a DLL and an int , appends a new node at the end ; 1. allocate node 2. put in the data ; 3. This new node is going to be the last node , so make next of it as NULL ; 4. If the Linked List is empty , then make the new node as head ; 5. Else traverse till the last node ; 6. Change the next of last node ; 7. Make last node as previous of new node\\nHow can the above be solved in C?\",\"targets\":\"void append ( struct Node * * head_ref , int new_data ) { struct Node * new_node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; struct Node * last = * head_ref ; new_node -> data = new_data ; new_node -> next = NULL ; if ( * head_ref == NULL ) { new_node -> prev = NULL ; * head_ref = new_node ; return ; } while ( last -> next != NULL ) last = last -> next ; last -> next = new_node ; new_node -> prev = last ; return ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Multiply two integers without using multiplication , division and bitwise operators , and no loops | 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-Sharp?\",\"targets\":\"using System ; class GFG { static int 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 ) ; return - 1 ; } public static void Main ( ) { Console . WriteLine ( multiply ( 5 , - 11 ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find the Kth pair in ordered list of all possible sorted pairs of the Array | Function to find the k - th pair ; Sorting the array ; Iterating through the array ; Finding the number of same elements ; Checking if N * T is less than the remaining K . If it is , then arr [ i ] is the first element in the required pair ; Printing the K - th pair ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function kthpair ( n , k , arr ) { let i , t = 0 ; arr . sort ( ) ; -- k ; for ( i = 0 ; i < n ; i += t ) { for ( t = 1 ; arr [ i ] == arr [ i + t ] ; ++ t ) ; if ( t * n > k ) break ; k = k - t * n ; } document . write ( arr [ i ] + \\\" \\\" + arr [ k \\/ t ] ) ; } let n = 3 , k = 2 ; let arr = [ 3 , 1 , 5 ] ; kthpair ( n , k , arr ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find average of two numbers using bit operation | Function to return the average of x and y using bit operations ; Calculate the average Floor value of ( x + y ) \\/ 2 ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function getAverage ( $ x , $ y ) { $ avg = ( $ x & $ y ) + ( ( $ x ^ $ y ) >> 1 ) ; return $ avg ; } $ x = 10 ; $ y = 9 ; echo getAverage ( $ x , $ y ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum value of K such that sum of cubes of first K natural number is greater than equal to N | C ++ program to determine the minimum value of K such that the sum of cubes of first K natural number is greater than or equal to N ; Function to determine the minimum value of K such that the sum of cubes of first K natural number is greater than or equal to N ; Left bound ; Right bound ; Variable to store the answer ; Applying binary search ; Calculating mid value of the range ; If the sum of cubes of first mid natural numbers is greater than equal to N iterate the left half ; Sum of cubes of first mid natural numbers is less than N , then move to the right segment ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int binary_searched_find_x ( int k ) { int l = 0 ; int r = k ; int ans = 0 ; while ( l <= r ) { int mid = l + ( r - l ) \\/ 2 ; if ( pow ( ( ( mid * ( mid + 1 ) ) \\/ 2 ) , 2 ) >= k ) { ans = mid ; r = mid - 1 ; } else { l = mid + 1 ; } } return ans ; } int main ( ) { int N = 100 ; cout << binary_searched_find_x ( N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Make all array elements even by replacing adjacent pair of array elements with their sum | Function to find minimum count of operations required to make all array elements even ; Stores minimum count of replacements to make all array elements even ; Stores the count of odd continuous numbers ; Traverse the array ; If arr [ i ] is an odd number ; Update odd_cont_seg ; If odd_cont_seg is even ; Update res ; Update res ; Reset odd_cont_seg = 0 ; If odd_cont_seg exceeds 0 ; If odd_cont_seg is even ; Update res ; Update res ; Print the result ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function make_array_element_even ( arr , N ) { let res = 0 ; let odd_cont_seg = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { odd_cont_seg ++ ; } else { if ( odd_cont_seg > 0 ) { if ( odd_cont_seg % 2 == 0 ) { res += odd_cont_seg \\/ 2 ; } else { res += ( odd_cont_seg \\/ 2 ) + 2 ; } odd_cont_seg = 0 ; } } } if ( odd_cont_seg > 0 ) { if ( odd_cont_seg % 2 == 0 ) { res += odd_cont_seg \\/ 2 ; } else { res += odd_cont_seg \\/ 2 + 2 ; } } return res ; } let arr = [ 2 , 4 , 5 , 11 , 6 ] ; let N = arr . length ; document . write ( make_array_element_even ( arr , N ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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 ; 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 ; Driver code ; Function call\\nHow can the above be solved in C?\",\"targets\":\"#include \\nbool 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 [ 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 ] || part [ i - arr [ j - 1 ] ] [ j - 1 ] ; } } return part [ sum \\/ 2 ] [ n ] ; } int main ( ) { int arr [ ] = { 3 , 1 , 1 , 2 , 2 , 1 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; if ( findPartiion ( arr , n ) == true ) printf ( \\\" Can ▁ be ▁ divided ▁ into ▁ two ▁ subsets ▁ of ▁ equal ▁ sum \\\" ) ; else printf ( \\\" Can ▁ not ▁ be ▁ divided ▁ into ▁ two ▁ subsets ▁ of ▁ \\\" \\\" equal ▁ sum \\\" ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count frequencies of all elements in array in O ( 1 ) extra space and O ( n ) time | Java program to print frequencies of all array elements in O ( 1 ) extra space and O ( n ) time ; Function to find counts of all elements present in arr [ 0. . n - 1 ] . The array elements must be range from 1 to n ; Traverse all array elements ; If this element is already processed , then nothing to do ; Find index corresponding to this element For example , index for 5 is 4 ; If the elementIndex has an element that is not processed yet , then first store that element to arr [ i ] so that we don 't lose anything. ; After storing arr [ elementIndex ] , change it to store initial count of ' arr [ i ] ' ; If this is NOT first occurrence of arr [ i ] , then decrement its count . ; And initialize arr [ i ] as 0 means the element ' i + 1' is not seen so far ; Driver program to test above functions\\\"\\nSolution in Java:\",\"targets\":\"class CountFrequencies { void findCounts ( int arr [ ] , int n ) { int i = 0 ; while ( i < n ) { if ( arr [ i ] <= 0 ) { i ++ ; continue ; } int elementIndex = arr [ i ] - 1 ; if ( arr [ elementIndex ] > 0 ) { arr [ i ] = arr [ elementIndex ] ; arr [ elementIndex ] = - 1 ; } else { arr [ elementIndex ] -- ; arr [ i ] = 0 ; i ++ ; } } System . out . println ( \\\" Below ▁ are ▁ counts ▁ of ▁ all ▁ elements \\\" ) ; for ( int j = 0 ; j < n ; j ++ ) System . out . println ( j + 1 + \\\" - > \\\" + Math . abs ( arr [ j ] ) ) ; } public static void main ( String [ ] args ) { CountFrequencies count = new CountFrequencies ( ) ; int arr [ ] = { 2 , 3 , 3 , 2 , 5 } ; count . findCounts ( arr , arr . length ) ; int arr1 [ ] = { 1 } ; count . findCounts ( arr1 , arr1 . length ) ; int arr3 [ ] = { 4 , 4 , 4 , 4 } ; count . findCounts ( arr3 , arr3 . length ) ; int arr2 [ ] = { 1 , 3 , 5 , 7 , 9 , 1 , 3 , 5 , 7 , 9 , 1 } ; count . findCounts ( arr2 , arr2 . length ) ; int arr4 [ ] = { 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 } ; count . findCounts ( arr4 , arr4 . length ) ; int arr5 [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 } ; count . findCounts ( arr5 , arr5 . length ) ; int arr6 [ ] = { 11 , 10 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 } ; count . findCounts ( arr6 , arr6 . length ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximum product of subsequence of size k | Required function ; sorting given input array ; variable to store final product of all element of sub - sequence of size k ; CASE I If max element is 0 and k is odd then max product will be 0 ; CASE II If all elements are negative and k is odd then max product will be product of rightmost - subarray of size k ; else i is current left pointer index ; j is current right pointer index ; CASE III if k is odd and rightmost element in sorted array is positive then it must come in subsequence Multiplying A [ j ] with product and correspondingly changing j ; CASE IV Now k is even . So , Now we deal with pairs Each time a pair is multiplied to product ie . . two elements are added to subsequence each time . Effectively k becomes half Hence , k >>= 1 means k \\/= 2 ; Now finding k corresponding pairs to get maximum possible value of product ; product from left pointers ; product from right pointers ; Taking the max product from two choices . Correspondingly changing the pointer 's position ; Finally return product ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def maxProductSubarrayOfSizeK ( A , n , k ) :\\n\\tA . sort ( )\\n\\tproduct = 1\\n\\tif ( A [ n - 1 ] == 0 and ( k & 1 ) ) :\\n\\t\\treturn 0\\n\\tif ( A [ n - 1 ] <= 0 and ( k & 1 ) ) :\\n\\t\\tfor i in range ( n - 1 , n - k + 1 , - 1 ) :\\n\\t\\t\\tproduct *= A [ i ]\\n\\t\\treturn product\\n\\ti = 0\\n\\tj = n - 1\\n\\tif ( k & 1 ) :\\n\\t\\tproduct *= A [ j ]\\n\\t\\tj -= 1\\n\\t\\tk -= 1\\n\\tk >>= 1\\n\\tfor itr in range ( k ) :\\n\\t\\tleft_product = A [ i ] * A [ i + 1 ]\\n\\t\\tright_product = A [ j ] * A [ j - 1 ]\\n\\t\\tif ( left_product > right_product ) :\\n\\t\\t\\tproduct *= left_product\\n\\t\\t\\ti += 2\\n\\t\\telse :\\n\\t\\t\\tproduct *= right_product\\n\\t\\t\\tj -= 2\\n\\treturn product\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tA = [ 1 , 2 , - 1 , - 3 , - 6 , 4 ]\\n\\tn = len ( A )\\n\\tk = 4\\n\\tprint ( maxProductSubarrayOfSizeK ( A , n , k ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimum count of numbers required ending with 7 to sum as a given number | C ++ implementation of the approach ; Function to return the count of minimum numbers ending with 7 required such that the sum of these numbers is n ; hasharr [ i ] will store the minimum numbers ending with 7 so that it sums to number ending with digit i ; Its always possible to write numbers > 69 to write as numbers ending with 7 ; If the number is atleast equal to the sum of minimum numbers ending with 7 ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; const int TEN = 10 ; int minCount ( int n ) { int hasharr [ TEN ] = { 10 , 3 , 6 , 9 , 2 , 5 , 8 , 1 , 4 , 7 } ; if ( n > 69 ) return hasharr [ n % TEN ] ; else { if ( n >= hasharr [ n % TEN ] * 7 ) return ( hasharr [ n % TEN ] ) ; else return -1 ; } } int main ( ) { int n = 38 ; cout << minCount ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimize cost of removals required to make all remaining characters of the string unique | Java program for the above approach ; Function to find the minimum cost of removing characters to make the string unique ; Store the minimum cost required ; Create a dictionary to store the maximum cost of removal a character ; Create a dictionary to store the total deletion cost of a character ; Traverse the string , S ; Keep track of maximum cost of each character ; Update the maximum deletion cost ; Keep track of the total cost of each character ; Update the total deletion cost ; Traverse through all the unique characters ; Keep the maximum cost character and delete the rest ; Return the answer ; Driver code ; Given string ; Given cost array ; Function Call\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; public class GFG { static int delCost ( String s , int [ ] cost ) { int ans = 0 ; HashMap < Character , Integer > forMax = new HashMap < > ( ) ; HashMap < Character , Integer > forTot = new HashMap < > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( ! forMax . containsKey ( s . charAt ( i ) ) ) { forMax . put ( s . charAt ( i ) , cost [ i ] ) ; } else { forMax . put ( s . charAt ( i ) , Math . max ( cost [ i ] , forMax . get ( s . charAt ( i ) ) ) ) ; } if ( ! forTot . containsKey ( s . charAt ( i ) ) ) { forTot . put ( s . charAt ( i ) , cost [ i ] ) ; } else { forTot . put ( s . charAt ( i ) , forTot . get ( s . charAt ( i ) ) + cost [ i ] ) ; } } for ( Map . Entry < Character , Integer > i : forMax . entrySet ( ) ) { ans += forTot . get ( i . getKey ( ) ) - i . getValue ( ) ; } return ans ; } public static void main ( String [ ] args ) { String s = \\\" AAABBB \\\" ; int [ ] cost = { 1 , 2 , 3 , 4 , 5 , 6 } ; System . out . println ( delCost ( s , cost ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Calculate depth of a full Binary tree from Preorder | C # program to find height of full binary tree using preorder ; function to return max of left subtree height or right subtree height ; calc height of left subtree ( In preorder left subtree is processed before right ) ; calc height of right subtree ; Wrapper over findDepthRec ( ) ; Driver program\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int findDepthRec ( char [ ] tree , int n , int index ) { if ( index >= n tree [ index ] == ' l ' ) return 0 ; index ++ ; int left = findDepthRec ( tree , n , index ) ; index ++ ; int right = findDepthRec ( tree , n , index ) ; return Math . Max ( left , right ) + 1 ; } static int findDepth ( char [ ] tree , int n ) { int index = 0 ; return ( findDepthRec ( tree , n , index ) ) ; } static public void Main ( ) { char [ ] tree = \\\" nlnnlll \\\" . ToCharArray ( ) ; int n = tree . Length ; Console . WriteLine ( findDepth ( tree , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count Negative Numbers in a Column | Python implementation of Naive method to count of negative numbers in M [ n ] [ m ] ; Follow the path shown using arrows above ; no more negative numbers in this row ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def countNegative ( M , n , m ) :\\n\\tcount = 0\\n\\tfor i in range ( n ) :\\n\\t\\tfor j in range ( m ) :\\n\\t\\t\\tif M [ i ] [ j ] < 0 :\\n\\t\\t\\t\\tcount += 1\\n\\t\\t\\telse :\\n\\t\\t\\t\\tbreak\\n\\treturn count\\nM = [ [ - 3 , - 2 , - 1 , 1 ] , [ - 2 , 2 , 3 , 4 ] , [ 4 , 5 , 7 , 8 ] ]\\nprint ( countNegative ( M , 3 , 4 ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Third last digit in 5 ^ N for given N | Function to find the element ; if n < 3 ; If n is even return 6 If n is odd return 1 ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function findThirdDigit ( $ n ) { if ( $ n < 3 ) return 0 ; return $ n & 1 ? 1 : 6 ; } $ n = 7 ; echo findThirdDigit ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count occurrences of a word in string | Javascript program to count the number of occurrence of a word in the given string ; split the string by spaces in a ; search for pattern in a ; if match found increase count ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function countOccurrences ( str , word ) { let a = str . split ( \\\" \\\" ) ; let count = 0 ; for ( let i = 0 ; i < a . length ; i ++ ) { if ( word == ( a [ i ] ) ) count ++ ; } return count ; } let str = \\\" \\\" ; let word = \\\" \\\" ; document . write ( countOccurrences ( str , word ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\":\"\\\"Find the vertex diagonally opposite to the vertex M from an N | Function to return the required vertex ; Case 1 : ; Case 2 : ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def getPosition ( N , M ) :\\n\\tif ( M > ( N \\/\\/ 2 ) ) :\\n\\t\\treturn ( M - ( N \\/\\/ 2 ) )\\n\\treturn ( M + ( N \\/\\/ 2 ) )\\nN = 8\\nM = 5\\nprint ( getPosition ( N , M ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; #define bool int\\nbool isPowerOfTwo ( int x ) { return x && ( ! ( x & ( x - 1 ) ) ) ; } int main ( ) { isPowerOfTwo ( 31 ) ? cout << \\\" Yes \\n \\\" : cout << \\\" No \\n \\\" ; isPowerOfTwo ( 64 ) ? cout << \\\" Yes \\n \\\" : cout << \\\" No \\n \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"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 ▁ \\\" , 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\":\"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 != ' ▁ ' ) ) { word_begin = temp ; } if ( word_begin && ( ( * ( temp + 1 ) == ' ▁ ' ) || ( * ( 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\":\"\\\"Occurrences of a pattern in binary representation of a number | C ++ program to find the number of times pattern p occurred in binary representation on n . ; Function to return the count of occurrence of pat in binary representation of n ; To store decimal value of the pattern ; To store a number that has all ones in its binary representation and length of ones equal to length of the pattern ; Find values of pattern_int and all_ones ; If the pattern occurs in the last digits of n ; Right shift n by 1 bit ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int countPattern ( int n , string pat ) { int pattern_int = 0 ; int power_two = 1 ; int all_ones = 0 ; for ( int i = pat . length ( ) - 1 ; i >= 0 ; i -- ) { int current_bit = pat [ i ] - '0' ; pattern_int += ( power_two * current_bit ) ; all_ones = all_ones + power_two ; power_two = power_two * 2 ; } int count = 0 ; while ( n && n >= pattern_int ) { if ( ( n & all_ones ) == pattern_int ) { count ++ ; } n = n >> 1 ; } return count ; } int main ( ) { int n = 500 ; string pat = \\\"10\\\" ; cout << countPattern ( n , pat ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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 encode given string ; for each character in given string ; If the character is occurring for the first time , assign next unique number to that char ; append the number associated with current character into the output string ; 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 ; encode the string ; for each word in the dictionary array ; If size of pattern is same as size of current dictionary word and both pattern and the word has same hash , print the word ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; public class GFG { static String encodeString ( String str ) { Dictionary < char , int > map = new Dictionary < char , int > ( ) ; String res = \\\" \\\" ; int i = 0 ; char ch ; for ( int j = 0 ; j < str . Length ; j ++ ) { ch = str [ j ] ; if ( ! map . ContainsKey ( ch ) ) map . Add ( ch , i ++ ) ; res += map [ ch ] ; } return res ; } static void findMatchedWords ( String [ ] dict , String pattern ) { int len = pattern . Length ; String hash = encodeString ( pattern ) ; foreach ( String word in dict ) { if ( word . Length == len && encodeString ( word ) . Equals ( hash ) ) Console . Write ( word + \\\" ▁ \\\" ) ; } } public static void Main ( String [ ] args ) { String [ ] dict = { \\\" 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\":\"\\\"Lexicographically smallest permutation number up to K having given array as a subsequence | Java program for the above approach ; Function to find the lexicographically smallest permutation such that the given array is a subsequence of it ; Stores the missing elements in arr in the range [ 1 , K ] ; Stores if the ith element is present in arr or not ; Loop to mark all integers present in the array as visited ; Loop to insert all the integers not visited into missing ; Append Integer . MAX_VALUE at end in order to prevent going out of bounds ; Pointer to the current element ; Pointer to the missing element ; Stores the required permutation ; Loop to conthe permutation using greedy approach ; If missing element is smaller that the current element insert missing element ; Insert current element ; Print the required Permutation ; Driver Code ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static void findPermutation ( int K , Vector < Integer > arr ) { Vector < Integer > missing = new Vector < Integer > ( ) ; boolean visited [ ] = new boolean [ K + 1 ] ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { visited [ arr . get ( i ) ] = true ; } for ( int i = 1 ; i <= K ; i ++ ) { if ( ! visited [ i ] ) { missing . add ( i ) ; } } arr . add ( Integer . MAX_VALUE ) ; missing . add ( Integer . MAX_VALUE ) ; int p1 = 0 ; int p2 = 0 ; Vector < Integer > ans = new Vector < Integer > ( ) ; while ( ans . size ( ) < K ) { if ( arr . get ( p1 ) < missing . get ( p2 ) ) { ans . add ( arr . get ( p1 ) ) ; p1 ++ ; } else { ans . add ( missing . get ( p2 ) ) ; p2 ++ ; } } for ( int i = 0 ; i < K ; i ++ ) { System . out . print ( ans . get ( i ) + \\\" ▁ \\\" ) ; } } public static void main ( String [ ] args ) { int K = 7 ; Integer [ ] a = { 6 , 4 , 2 , 1 } ; Vector < Integer > arr = new Vector < > ( Arrays . asList ( a ) ) ; findPermutation ( K , arr ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Sum of all odd length palindromic numbers within the range [ L , R ] | C program to find the sum of all odd length palindromic numbers within the given range ; Function that returns true if the given number is a palindrome ; Here we are generating a new number ( reverse_num ) * by reversing the digits of original input number ; If the original input number ( num ) is equal to * to its reverse ( reverse_num ) then its palindrome * else it is not . ; Function that returns true if the given number is of odd length ; Function to return the sum of all odd length palindromic numbers within the given range ; if number is palindrome and of odd length ; Driver code\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nbool isPalindrome ( int num ) { int reverse_num = 0 , remainder , temp ; temp = num ; while ( temp != 0 ) { remainder = temp % 10 ; reverse_num = reverse_num * 10 + remainder ; temp \\/= 10 ; } if ( reverse_num == num ) { return true ; } return false ; } bool isOddLength ( int num ) { int count = 0 ; while ( num > 0 ) { num \\/= 10 ; count ++ ; } if ( count % 2 != 0 ) { return true ; } return false ; } long sumOfAllPalindrome ( int L , int R ) { long sum = 0 ; if ( L <= R ) for ( int i = L ; i <= R ; i ++ ) { if ( isPalindrome ( i ) && isOddLength ( i ) ) { sum += i ; } } return sum ; } int main ( ) { int L = 110 , R = 1130 ; printf ( \\\" % ld \\\" , sumOfAllPalindrome ( L , R ) ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Queries to check if substring [ L ... R ] is palindrome or not | Python3 implementation of the approach ; Pre - processing function ; Get the size of the string ; Initially mark every position as false ; For the length ; Iterate for every index with length j ; If the length is less than 2 ; If characters are equal ; Check for equal ; Function to answer every query in O ( 1 ) ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"N = 100\\ndef pre_process ( dp , s ) :\\n\\tn = len ( s )\\n\\tfor i in range ( n ) :\\n\\t\\tfor j in range ( n ) :\\n\\t\\t\\tdp [ i ] [ j ] = False\\n\\tfor j in range ( 1 , n + 1 ) :\\n\\t\\tfor i in range ( n - j + 1 ) :\\n\\t\\t\\tif ( j <= 2 ) :\\n\\t\\t\\t\\tif ( s [ i ] == s [ i + j - 1 ] ) :\\n\\t\\t\\t\\t\\tdp [ i ] [ i + j - 1 ] = True\\n\\t\\t\\telif ( s [ i ] == s [ i + j - 1 ] ) :\\n\\t\\t\\t\\tdp [ i ] [ i + j - 1 ] = dp [ i + 1 ] [ i + j - 2 ]\\ndef answerQuery ( l , r , dp ) :\\n\\tif ( dp [ l ] [ r ] ) :\\n\\t\\tprint ( \\\" Yes \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\\ns = \\\" abaaab \\\"\\ndp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\\npre_process ( dp , s )\\nqueries = [ [ 0 , 1 ] , [ 1 , 5 ] ]\\nq = len ( queries )\\nfor i in range ( q ) :\\n\\tanswerQuery ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , dp )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Print characters having prime frequencies in order of occurrence | Java code for the above approach ; Function to check primes ; Counting the frequency of all character using Counter function ; Traversing string ; Driver code ; Passing string to checkString function\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { static boolean prime ( int n ) { if ( n <= 1 ) return false ; int max_div = ( int ) Math . floor ( Math . sqrt ( n ) ) ; for ( int i = 2 ; i < 1 + max_div ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } static void checkString ( String s ) { Map < Character , Integer > freq = new HashMap < Character , Integer > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( ! freq . containsKey ( s . charAt ( i ) ) ) freq . put ( s . charAt ( i ) , 0 ) ; freq . put ( s . charAt ( i ) , freq . get ( s . charAt ( i ) ) + 1 ) ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( prime ( freq . get ( s . charAt ( i ) ) ) ) System . out . print ( s . charAt ( i ) ) ; } } public static void main ( String [ ] args ) { String s = \\\" geeksforgeeks \\\" ; checkString ( s ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Bitwise OR of bitwise AND of all possible non | Function to find the Bitwise OR of Bitwise AND of all possible subarrays after performing the every query ; Traversing each pair of the query ; Stores the Bitwise OR ; Updating the array ; Find the Bitwise OR of new updated array ; Print the ans ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def performQuery ( arr , Q ) :\\n\\tfor i in range ( 0 , len ( Q ) ) :\\n\\t\\torr = 0\\n\\t\\tx = Q [ i ] [ 0 ]\\n\\t\\tarr [ x - 1 ] = Q [ i ] [ 1 ]\\n\\t\\tfor j in range ( 0 , len ( arr ) ) :\\n\\t\\t\\torr = orr | arr [ j ]\\n\\t\\tprint ( orr , end = \\\" ▁ \\\" )\\narr = [ 1 , 2 , 3 ]\\nQ = [ [ 1 , 4 ] , [ 3 , 0 ] ]\\nperformQuery ( arr , Q )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\\"\\nSolution 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\":\"solc\",\"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 ; 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\":\"\\\"Find sum of divisors of all the divisors of a natural number | Python3 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\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import math as mt\\ndef sumDivisorsOfDivisors ( n ) :\\n\\tmp = dict ( )\\n\\tfor j in range ( 2 , mt . ceil ( mt . sqrt ( n ) ) ) :\\n\\t\\tcount = 0\\n\\t\\twhile ( n % j == 0 ) :\\n\\t\\t\\tn \\/\\/= j\\n\\t\\t\\tcount += 1\\n\\t\\tif ( count ) :\\n\\t\\t\\tmp [ j ] = count\\n\\tif ( n != 1 ) :\\n\\t\\tmp [ n ] = 1\\n\\tans = 1\\n\\tfor it in mp :\\n\\t\\tpw = 1\\n\\t\\tsumm = 0\\n\\t\\tfor i in range ( mp [ it ] + 1 , 0 , - 1 ) :\\n\\t\\t\\tsumm += ( i * pw )\\n\\t\\t\\tpw *= it\\n\\t\\tans *= summ\\n\\treturn ans\\nn = 10\\nprint ( sumDivisorsOfDivisors ( n ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Search an element in a Doubly Linked List | C # program to implement the above approach ; Structure of a node of the doubly linked list ; Stores data value of a node ; Stores pointer to next node ; Stores pointer to previous node ; Function to insert a node at the beginning of the Doubly Linked List ; Allocate memory for new node ; Insert the data ; Since node is added at the beginning , prev is always null ; Link the old list to the new node ; If pointer to head is not null ; Change the prev of head node to new node ; Move the head to point to the new node ; Function to find the position of an integer in doubly linked list ; Stores head Node ; Stores position of the integer in the doubly linked list ; Traverse the doubly linked list ; Update pos ; Update temp ; If the integer not present in the doubly linked list ; If the integer present in the doubly linked list ; Driver Code ; Create the doubly linked list 18 < -> 15 < -> 8 < -> 9 < -> 14\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { public class Node { public int data ; public Node next ; public Node prev ; } ; static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . prev = null ; new_node . next = head_ref ; if ( head_ref != null ) { head_ref . prev = new_node ; } head_ref = new_node ; return head_ref ; } static int search ( Node head_ref , int x ) { Node temp = head_ref ; int pos = 0 ; while ( temp . data != x && temp . next != null ) { pos ++ ; temp = temp . next ; } if ( temp . data != x ) return - 1 ; return ( pos + 1 ) ; } public static void Main ( String [ ] args ) { Node head = null ; int X = 8 ; head = push ( head , 14 ) ; head = push ( head , 9 ) ; head = push ( head , 8 ) ; head = push ( head , 15 ) ; head = push ( head , 18 ) ; Console . Write ( search ( head , X ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Difference between sums of odd level and even level nodes of a Binary Tree | CPP program to find difference between sums of odd level and even level nodes of binary tree ; tree node ; returns a new tree Node ; return difference of sums of odd level and even level ; create a queue for level order traversal ; traverse until the queue is empty ; traverse for complete level ; check if level no . is even or odd and accordingly update the evenSum or oddSum ; check for left child ; check for right child ; driver program ; construct a tree\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ( ) ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int evenOddLevelDifference ( Node * root ) { if ( ! root ) return 0 ; queue < Node * > q ; q . push ( root ) ; int level = 0 ; int evenSum = 0 , oddSum = 0 ; while ( ! q . empty ( ) ) { int size = q . size ( ) ; level += 1 ; while ( size > 0 ) { Node * temp = q . front ( ) ; q . pop ( ) ; if ( level % 2 == 0 ) evenSum += temp -> data ; else oddSum += temp -> data ; if ( temp -> left ) { q . push ( temp -> left ) ; } if ( temp -> right ) { q . push ( temp -> right ) ; } size -= 1 ; } } return ( oddSum - evenSum ) ; } int main ( ) { Node * root = newNode ( 5 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 6 ) ; root -> left -> left = newNode ( 1 ) ; root -> left -> right = newNode ( 4 ) ; root -> left -> right -> left = newNode ( 3 ) ; root -> right -> right = newNode ( 8 ) ; root -> right -> right -> right = newNode ( 9 ) ; root -> right -> right -> left = newNode ( 7 ) ; int result = evenOddLevelDifference ( root ) ; cout << \\\" diffence ▁ between ▁ sums ▁ is ▁ : : ▁ \\\" ; cout << result << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Binomial Coefficient | DP | C # Code for Dynamic Programming | Set 9 ( Binomial Coefficient ) ; Returns value of Binomial Coefficient C ( n , k ) ; Base Cases ; Recur ; Driver program to test above function\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int binomialCoeff ( int n , int k ) { if ( k > n ) return 0 ; if ( k == 0 k == n ) return 1 ; return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ; } public static void Main ( ) { int n = 5 , k = 2 ; Console . Write ( \\\" Value ▁ of ▁ C ( \\\" + n + \\\" , \\\" + k + \\\" ) ▁ is ▁ \\\" + binomialCoeff ( n , k ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimum swaps of same | C # program to implement the above approach ; Function to count the minimum swaps of same - indexed elements from arrays arr1 [ ] and arr2 [ ] required to make the sum of both the arrays even ; Store the sum of elements of the array arr1 and arr2 respectively ; Store the array sum of both the arrays ; If both sumArr1 and sumArr2 are even , print 0 and return ; If both sumArr1 and sumArr2 are odd and check for a pair with sum odd sum ; Stores if a pair with odd sum exists or not ; Traverse the array ; If a pair exists with odd sum , set flag = 1 ; Print the answer and return ; For all other cases , print - 1 ; Driver code ; Function Call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void minimumSwaps ( int [ ] arr1 , int [ ] arr2 , int n ) { int sumArr1 = 0 , sumArr2 = 0 ; for ( int i = 0 ; i < n ; ++ i ) { sumArr1 += arr1 [ i ] ; sumArr2 += arr2 [ i ] ; } if ( sumArr1 % 2 == 0 && sumArr2 % 2 == 0 ) { Console . Write ( 0 ) ; return ; } if ( sumArr1 % 2 != 0 && sumArr2 % 2 != 0 ) { int flag = - 1 ; for ( int i = 0 ; i < n ; ++ i ) { if ( ( arr1 [ i ] + arr2 [ i ] ) % 2 == 1 ) { flag = 1 ; break ; } } Console . Write ( flag ) ; return ; } Console . Write ( - 1 ) ; } public static void Main ( ) { int [ ] arr1 = { 11 , 14 , 20 , 2 } ; int [ ] arr2 = { 5 , 9 , 6 , 3 } ; int N = arr1 . Length ; minimumSwaps ( arr1 , arr2 , N ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Program to print ASCII Value of all digits of a given number | C ++ program to convert the digits of a number to its ASCII values ; Function to convert digits of N to respective ASCII values ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int convertToASCII ( int N ) { string num = to_string ( N ) ; for ( char ch : num ) { cout << ch << \\\" ▁ ( \\\" << ( int ) ch << \\\" ) \\n \\\" ; } } int main ( ) { int N = 36 ; convertToASCII ( N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check if product of digits of a number at even and odd places is equal | Java implementation of the approach ; To store the respective product ; Converting integer to String ; Traversing the String ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void getResult ( int n ) { int proOdd = 1 ; int proEven = 1 ; String num = String . valueOf ( n ) ; for ( int i = 0 ; i < num . length ( ) ; i ++ ) if ( i % 2 == 0 ) proOdd = proOdd * ( num . charAt ( i ) - '0' ) ; else proEven = proEven * ( num . charAt ( i ) - '0' ) ; if ( proOdd == proEven ) System . out . print ( \\\" Yes \\\" ) ; else System . out . print ( \\\" No \\\" ) ; } public static void main ( String [ ] args ) { int n = 4324 ; getResult ( n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Arrange consonants and vowels nodes in a linked list | A linked list node ; Utility function to print the linked list ; Utility function for checking vowel ; function to arrange consonants and vowels nodes ; for keep track of vowel ; list is empty ; We need to discover the first vowel in the list . It is going to be the returned head , and also the initial latestVowel . ; first element is a vowel . It will also be the new head and the initial latestVowel ; First element is not a vowel . Iterate through the list until we find a vowel . Note that curr points to the element * before * the element with the vowel . ; This is an edge case where there are only consonants in the list . ; Set the initial latestVowel and the new head to the vowel item that we found . Relink the chain of consonants after that vowel item : old_head_consonant . consonant1 . consonant2 . vowel . rest_of_list becomes vowel . old_head_consonant . consonant1 . consonant2 . rest_of_list ; Now traverse the list . Curr is always the item * before * the one we are checking , so that we can use it to re - link . ; The next discovered item is a vowel ; If it comes directly after the previous vowel , we don 't need to move items around, just mark the new latestVowel and advance curr. ; But if it comes after an intervening chain of consonants , we need to chain the newly discovered vowel right after the old vowel . Curr is not changed as after the re - linking it will have a new next , that has not been checked yet , and we always keep curr at one before the next to check . ; Chain in new vowel ; Advance latestVowel ; Remove found vowel from previous place ; Re - link chain of consonants after latestVowel ; No vowel in the next element , advance curr . ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"class Node :\\n\\tdef __init__ ( self , x ) :\\n\\t\\tself . data = x\\n\\t\\tself . next = None\\ndef printlist ( head ) :\\n\\tif ( not head ) :\\n\\t\\tprint ( \\\" Empty ▁ List \\\" )\\n\\t\\treturn\\n\\twhile ( head != None ) :\\n\\t\\tprint ( head . data , end = \\\" ▁ \\\" )\\n\\t\\tif ( head . next ) :\\n\\t\\t\\tprint ( end = \\\" - > ▁ \\\" )\\n\\t\\thead = head . next\\n\\tprint ( )\\ndef isVowel ( x ) :\\n\\treturn ( x == ' a ' or x == ' e ' or x == ' i ' or x == ' o ' or x == ' u ' or x == ' A ' or x == ' E ' or x == ' I ' or x == ' O ' or x == ' U ' )\\ndef arrange ( head ) :\\n\\tnewHead = head\\n\\tlatestVowel = None\\n\\tcurr = head\\n\\tif ( head == None ) :\\n\\t\\treturn None\\n\\tif ( isVowel ( head . data ) ) :\\n\\t\\tlatestVowel = head\\n\\telse :\\n\\t\\twhile ( curr . next != None and not isVowel ( curr . next . data ) ) :\\n\\t\\t\\tcurr = curr . next\\n\\t\\tif ( curr . next == None ) :\\n\\t\\t\\treturn head\\n\\t\\tlatestVowel = newHead = curr . next\\n\\t\\tcurr . next = curr . next . next\\n\\t\\tlatestVowel . next = head\\n\\twhile ( curr != None and curr . next != None ) :\\n\\t\\tif ( isVowel ( curr . next . data ) ) :\\n\\t\\t\\tif ( curr == latestVowel ) :\\n\\t\\t\\t\\tlatestVowel = curr = curr . next\\n\\t\\t\\telse :\\n\\t\\t\\t\\ttemp = latestVowel . next\\n\\t\\t\\t\\tlatestVowel . next = curr . next\\n\\t\\t\\t\\tlatestVowel = latestVowel . next\\n\\t\\t\\t\\tcurr . next = curr . next . next\\n\\t\\t\\t\\tlatestVowel . next = temp\\n\\t\\telse :\\n\\t\\t\\tcurr = curr . next\\n\\treturn newHead\\nif __name__ == ' _ _ main _ _ ' :\\n\\thead = Node ( ' a ' )\\n\\thead . next = Node ( ' b ' )\\n\\thead . next . next = Node ( ' c ' )\\n\\thead . next . next . next = Node ( ' e ' )\\n\\thead . next . next . next . next = Node ( ' d ' )\\n\\thead . next . next . next . next . next = Node ( ' o ' )\\n\\thead . next . next . next . next . next . next = Node ( ' x ' )\\n\\thead . next . next . next . next . next . next . next = Node ( ' i ' )\\n\\tprint ( \\\" Linked ▁ list ▁ before ▁ : \\\" )\\n\\tprintlist ( head )\\n\\thead = arrange ( head )\\n\\tprint ( \\\" Linked ▁ list ▁ after ▁ : \\\" )\\n\\tprintlist ( head )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find if a point lies inside a Circle | PHP program to check if a point lies inside a circle or not ; Compare radius of circle with distance of its center from given point ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function isInside ( $ circle_x , $ circle_y , $ rad , $ x , $ y ) { if ( ( $ x - $ circle_x ) * ( $ x - $ circle_x ) + ( $ y - $ circle_y ) * ( $ y - $ circle_y ) <= $ rad * $ rad ) return true ; else return false ; } $ x = 1 ; $ y = 1 ; $ circle_x = 0 ; $ circle_y = 1 ; $ rad = 2 ; if ( isInside ( $ circle_x , $ circle_y , $ rad , $ x , $ y ) ) echo \\\" Inside \\\" ; else echo \\\" Outside \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Print Longest Palindromic Subsequence | CPP program to print longest palindromic subsequence ; Returns LCS X and Y ; 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 ] ; Following code is used to print LCS ; Create a string length index + 1 and fill it with \\\\ 0 ; Start from the right - most - bottom - most corner and one by one store characters in lcs [ ] ; If current character in X [ ] and Y are same , then current character is part of LCS ; Put current character in result ; reduce values of i , j and index ; If not same , then find the larger of two and go in the direction of larger value ; Returns longest palindromic subsequence of str ; Find reverse of str ; Return LCS of str and its reverse ; Driver program to test above function\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; string lcs ( string & X , string & Y ) { int m = X . length ( ) ; int n = Y . length ( ) ; int L [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int 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 ] ) ; } } int index = L [ m ] [ n ] ; string lcs ( index + 1 , ' \\\\0' ) ; int i = m , j = n ; while ( i > 0 && j > 0 ) { if ( X [ i - 1 ] == Y [ j - 1 ] ) { lcs [ index - 1 ] = X [ i - 1 ] ; i -- ; j -- ; index -- ; } else if ( L [ i - 1 ] [ j ] > L [ i ] [ j - 1 ] ) i -- ; else j -- ; } return lcs ; } string longestPalSubseq ( string & str ) { string rev = str ; reverse ( rev . begin ( ) , rev . end ( ) ) ; return lcs ( str , rev ) ; } int main ( ) { string str = \\\" GEEKSFORGEEKS \\\" ; cout << longestPalSubseq ( str ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Construct a Matrix such that each cell consists of sum of adjacent elements of respective cells in given Matrix | Initialize rows and columns ; Store all 8 directions ; Function to check if a cell ( i , j ) is valid or not ; Function to find sum of adjacent cells for cell ( i , j ) ; Initialize sum ; Visit all 8 directions ; Check if cell is valid ; Return sum ; Function to print sum of adjacent elements ; Stores the resultant matrix ; Iterate each elements of matrix ; Find adjacent sum ; Given matrix ; Size of matrix ; Function call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"let r , c ; let dir = [ [ 1 , 0 ] , [ - 1 , 0 ] , [ 0 , 1 ] , [ 0 , - 1 ] , [ - 1 , - 1 ] , [ - 1 , 1 ] , [ 1 , 1 ] , [ 1 , - 1 ] ] ; function valid ( i , j ) { if ( i >= 0 && j >= 0 && i < r && j < c ) return true ; return false ; } function find ( i , j , v ) { let s = 0 ; for ( let k = 0 ; k < 8 ; k ++ ) { let ni = i + dir [ k ] [ 0 ] , nj = j + dir [ k ] [ 1 ] ; if ( valid ( ni , nj ) ) s += v [ ni ] [ nj ] ; } return s ; } function findsumofneighbors ( M ) { let v = new Array ( r ) ; for ( var i = 0 ; i < v . length ; i ++ ) { v [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < r ; i ++ ) { for ( let j = 0 ; j < c ; j ++ ) { v [ i ] [ j ] = find ( i , j , M ) ; document . write ( v [ i ] [ j ] + \\\" \\\" ) ; } document . write ( \\\" \\\" ) ; } } let M = [ [ 1 , 4 , 1 ] , [ 2 , 4 , 5 ] , [ 3 , 1 , 2 ] ] ; r = M . length ; c = M [ 0 ] . length ; findsumofneighbors ( M ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximum time such that absolute difference between hour and minute lies in given range | C ++ program for the above approach ; Function checks whether given time is correct ; To check minute value of time ; To check hour value of time ; Changes in value is not allowed at position where ' ? ' is not present ; Function checks whether the absolute difference between hour and minute value is within [ L , R ] ; Checks if the difference is outside the give range ; Displays time in proper 24 - hour format ; Function find the desired value of time whose difference lies in the range [ L , R ] ; Decrease hour value from 23 to 0 ; Check if the hour value is valid if not valid then no need to change minute value , since time will still remain in valid , to check hour value flag is set to 1. ; Decrease minute value from 59 to 0 ; Check if the minute value is valid , if not valid then skip the current iteration , to check ' minute ' value flag is set to 0. ; Driver code ; Input time ; Difference range\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool isValid ( char a1 , char a2 , string str , int flag ) { char v1 , v2 ; if ( flag == 0 ) { v1 = str [ 4 ] ; v2 = str [ 3 ] ; } else { v1 = str [ 1 ] ; v2 = str [ 0 ] ; } if ( v1 != a1 && v1 != ' ? ' ) return false ; if ( v2 != a2 && v2 != ' ? ' ) return false ; return true ; } bool inRange ( int hh , int mm , int L , int R ) { int a = abs ( hh - mm ) ; if ( a < L a > R ) return false ; return true ; } void displayTime ( int hh , int mm ) { if ( hh > 10 ) cout << hh << \\\" : \\\" ; else if ( hh < 10 ) cout << \\\"0\\\" << hh << \\\" : \\\" ; if ( mm > 10 ) cout << mm << endl ; else if ( mm < 10 ) cout << \\\"0\\\" << mm << endl ; } void maximumTimeWithDifferenceInRange ( string str , int L , int R ) { int i , j ; int h1 , h2 , m1 , m2 ; for ( i = 23 ; i >= 0 ; i -- ) { h1 = i % 10 ; h2 = i \\/ 10 ; if ( ! isValid ( h1 + '0' , h2 + '0' , str , 1 ) ) { continue ; } for ( j = 59 ; j >= 0 ; j -- ) { m1 = j % 10 ; m2 = j \\/ 10 ; if ( ! isValid ( m1 + '0' , m2 + '0' , str , 0 ) ) { continue ; } if ( inRange ( i , j , L , R ) ) { displayTime ( i , j ) ; return ; } } } if ( inRange ( i , j , L , R ) ) displayTime ( i , j ) ; else cout << \\\" - 1\\\" << endl ; } int main ( ) { string timeValue = \\\" ? ? : ? ? \\\" ; int L = 20 , R = 39 ; maximumTimeWithDifferenceInRange ( timeValue , L , R ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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 ▁ = \\\" , A \\/ 3 , \\\" , ▁ B ▁ = \\\" , B , \\\" , ▁ \\\\ ▁ C ▁ = \\\" , C , sep = \\\" ▁ \\\" )\\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\":\"\\\"Minimum count of increment of K size subarrays required to form a given Array | Java implementation to find the minimum number of operations required to change an array of all zeros such that every element is greater than the given array ; Function to find the minimum number of operations required to change all the array of zeros such that every element is greater than the given array ; Declaring the difference array of size N ; Number of operations ; First update the D [ i ] value with the previous value ; The index i has to be incremented ; We have to perform ( b [ i ] - d [ i ] ) operations more ; Increment the range i to i + k by need ; Check if i + k is valid index ; Driver Code ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static void find_minimum_operations ( int n , int b [ ] , int k ) { int d [ ] = new int [ n + 1 ] ; int i , operations = 0 , need ; for ( i = 0 ; i < n ; i ++ ) { if ( i > 0 ) { d [ i ] += d [ i - 1 ] ; } if ( b [ i ] > d [ i ] ) { operations += b [ i ] - d [ i ] ; need = b [ i ] - d [ i ] ; d [ i ] += need ; if ( i + k <= n ) { d [ i + k ] -= need ; } } } System . out . println ( operations ) ; } public static void main ( String [ ] args ) { int n = 5 ; int b [ ] = { 1 , 2 , 3 , 4 , 5 } ; int k = 2 ; find_minimum_operations ( n , b , k ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum LCM and GCD possible among all possible sub | 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 PHP?\",\"targets\":\"< ? php function __gcd ( $ a , $ b ) { if ( $ a == 0 ) return $ b ; return __gcd ( $ b % $ a , $ a ) ; } function minGCD ( $ arr , $ n ) { $ minGCD = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ minGCD = __gcd ( $ minGCD , $ arr [ $ i ] ) ; return $ minGCD ; } function minLCM ( $ arr , $ n ) { $ minLCM = $ arr [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) $ minLCM = min ( $ minLCM , $ arr [ $ i ] ) ; return $ minLCM ; } $ arr = array ( 2 , 66 , 14 , 521 ) ; $ n = sizeof ( $ arr ) ; echo \\\" LCM = \\\" ▁ . ▁ minLCM ( $ arr , ▁ $ n ) ▁ . ▁ \\\" , \\\" echo \\\" GCD ▁ = ▁ \\\" . minGCD ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Search , insert and delete in a sorted array | C program to implement insert operation in an sorted 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 program to test above function ; Inserting key\\\"\\nSolution in C:\",\"targets\":\"#include \\nint insertSorted ( int arr [ ] , int n , int key , int capacity ) { if ( n >= capacity ) return n ; int i ; for ( i = n - 1 ; ( i >= 0 && arr [ i ] > key ) ; i -- ) arr [ i + 1 ] = arr [ i ] ; arr [ i + 1 ] = key ; return ( n + 1 ) ; } int main ( ) { int arr [ 20 ] = { 12 , 16 , 20 , 40 , 50 , 70 } ; int capacity = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int n = 6 ; int i , key = 26 ; printf ( \\\" Before Insertion : \\\" for ( i = 0 ; i < n ; i ++ ) printf ( \\\" % d ▁ \\\" , arr [ i ] ) ; n = insertSorted ( arr , n , key , capacity ) ; printf ( \\\" After Insertion : \\\" for ( i = 0 ; i < n ; i ++ ) printf ( \\\" % d ▁ \\\" , arr [ i ] ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"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 ▁ 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\":\"\\\"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\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; 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 ) ; } static public void Main ( ) { int n = 5 ; Console . WriteLine ( CountWays ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Remove minimum number of characters so that two strings become anagram | Python 3 program to find minimum number of characters to be removed to make two strings anagram . ; function to calculate minimum numbers of characters to be removed to make two strings anagram ; make hash array for both string and calculate frequency of each character ; count frequency of each character in first string ; count frequency of each character in second string ; traverse count arrays to find number of characters to be removed ; Driver program to run the case\\\"\\nHow can the above be solved in Python?\",\"targets\":\"CHARS = 26\\ndef remAnagram ( str1 , str2 ) :\\n\\tcount1 = [ 0 ] * CHARS\\n\\tcount2 = [ 0 ] * CHARS\\n\\ti = 0\\n\\twhile i < len ( str1 ) :\\n\\t\\tcount1 [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] += 1\\n\\t\\ti += 1\\n\\ti = 0\\n\\twhile i < len ( str2 ) :\\n\\t\\tcount2 [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] += 1\\n\\t\\ti += 1\\n\\tresult = 0\\n\\tfor i in range ( 26 ) :\\n\\t\\tresult += abs ( count1 [ i ] - count2 [ i ] )\\n\\treturn result\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tstr1 = \\\" bcadeh \\\"\\n\\tstr2 = \\\" hea \\\"\\n\\tprint ( remAnagram ( str1 , str2 ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"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\":\"\\\"Smallest of three integers without comparison operators | JavaScript program to find Smallest of three integers without comparison operators ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function smallest ( x , y , z ) { let c = 0 ; while ( x && y && z ) { x -- ; y -- ; z -- ; c ++ ; } return c ; } let x = 12 , y = 15 , z = 5 ; document . write ( \\\" \\\" + smallest ( x , y , z ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Alternate Odd and Even Nodes in a Singly Linked List | Java program to rearrange nodes as alternate odd even nodes in a Singly Linked List ; class node ; A utility function to print linked list ; Function to create newNode in a linkedlist ; Function to insert at beginning ; Function to rearrange the odd and even nodes ; Odd Value in Even Position Add pointer to current node in odd stack ; Even Value in Odd Position Add pointer to current node in even stack ; Swap Data at the top of two stacks ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static class Node { int data ; Node next ; } static void printList ( Node node ) { while ( node != null ) { System . out . print ( node . data + \\\" ▁ \\\" ) ; node = node . next ; } System . out . println ( ) ; } static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . data = key ; temp . next = null ; return temp ; } static Node insertBeg ( Node head , int val ) { Node temp = newNode ( val ) ; temp . next = head ; head = temp ; return head ; } static void rearrangeOddEven ( Node head ) { Stack < Node > odd = new Stack < Node > ( ) ; Stack < Node > even = new Stack < Node > ( ) ; int i = 1 ; while ( head != null ) { if ( head . data % 2 != 0 && i % 2 == 0 ) { odd . push ( head ) ; } else if ( head . data % 2 == 0 && i % 2 != 0 ) { even . push ( head ) ; } head = head . next ; i ++ ; } while ( odd . size ( ) > 0 && even . size ( ) > 0 ) { int k = odd . peek ( ) . data ; odd . peek ( ) . data = even . peek ( ) . data ; even . peek ( ) . data = k ; odd . pop ( ) ; even . pop ( ) ; } } public static void main ( String args [ ] ) { Node head = newNode ( 8 ) ; head = insertBeg ( head , 7 ) ; head = insertBeg ( head , 6 ) ; head = insertBeg ( head , 5 ) ; head = insertBeg ( head , 3 ) ; head = insertBeg ( head , 2 ) ; head = insertBeg ( head , 1 ) ; System . out . println ( \\\" Linked ▁ List : \\\" ) ; printList ( head ) ; rearrangeOddEven ( head ) ; System . out . println ( \\\" Linked ▁ List ▁ after ▁ \\\" + \\\" Rearranging : \\\" ) ; printList ( head ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 ; First n in the below condition is for the case where n is 0 ; Driver Code\\\"\\nSolution 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\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if count of divisors is even or odd | Function to count the divisors ; Initialize count of divisors ; Note that this loop runs till square root ; If divisors are equal increment count by one Otherwise increment count by 2 ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function countDivisors ( $ n ) { $ count = 0 ; for ( $ i = 1 ; $ i <= sqrt ( $ n ) + 1 ; $ i ++ ) { if ( $ n % $ i == 0 ) $ count += ( $ n \\/ $ i == $ i ) ? 1 : 2 ; } if ( $ count % 2 == 0 ) echo \\\" Even \\n \\\" ; else echo \\\" Odd \\n \\\" ; } echo \\\" The ▁ count ▁ of ▁ divisor : ▁ \\\" ; countDivisors ( 10 ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to find whether a given number is power of 2 | Java program of the above approach ; Function to check if x is power of 2 ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static boolean isPowerofTwo ( int n ) { if ( n == 0 ) return false ; if ( ( n & ( ~ ( n - 1 ) ) ) == n ) return true ; return false ; } public static void main ( String [ ] args ) { if ( isPowerofTwo ( 30 ) == true ) System . out . println ( \\\" Yes \\\" ) ; else System . out . println ( \\\" No \\\" ) ; if ( isPowerofTwo ( 128 ) == true ) 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\":\"\\\"Count Odd and Even numbers in a range from L to R | Return the number of odd numbers in the range [ L , R ] ; if either R or L is odd ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function countOdd ( $ L , $ R ) { $ N = ( $ R - $ L ) \\/ 2 ; if ( $ R % 2 != 0 $ L % 2 != 0 ) $ N ++ ; return $ N ; } $ L = 3 ; $ R = 7 ; $ odds = countOdd ( $ L , $ R ) ; $ evens = ( $ R - $ L + 1 ) - $ odds ; echo \\\" Count ▁ of ▁ odd ▁ numbers ▁ is ▁ \\\" . $ odds . \\\" \\n \\\" ; echo \\\" Count ▁ of ▁ even ▁ numbers ▁ is ▁ \\\" . $ evens ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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\":\"\\\"Minimum value of \\\" max ▁ + ▁ min \\\" in a subarray | PHP program to find sum of maximum and minimum in any subarray of an array of positive numbers . ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function maxSum ( $ arr , $ n ) { if ( $ n < 2 ) return -1 ; $ ans = $ arr [ 0 ] + $ arr [ 1 ] ; for ( $ i = 1 ; $ i + 1 < $ n ; $ i ++ ) $ ans = min ( $ ans , ( $ arr [ $ i ] + $ arr [ $ i + 1 ] ) ) ; return $ ans ; } $ arr = array ( 1 , 12 , 2 , 2 ) ; $ n = count ( $ arr ) ; echo maxSum ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Shortest path with exactly k edges in a directed and weighted graph | C ++ program to find shortest path with exactly k edges ; Define number of vertices in the graph and inifinite value ; A naive recursive function to count walks from u to v with k edges ; Base cases ; Initialize result ; Go to all adjacents of u and recur ; driver program to test above function ; Let us create the graph shown in above diagram\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; #define V 4\\n#define INF INT_MAX\\nint shortestPath ( int graph [ ] [ V ] , int u , int v , int k ) { if ( k == 0 && u == v ) return 0 ; if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ; if ( k <= 0 ) return INF ; int res = INF ; for ( int i = 0 ; i < V ; i ++ ) { if ( graph [ u ] [ i ] != INF && u != i && v != i ) { int rec_res = shortestPath ( graph , i , v , k - 1 ) ; if ( rec_res != INF ) res = min ( res , graph [ u ] [ i ] + rec_res ) ; } } return res ; } int main ( ) { int graph [ V ] [ V ] = { { 0 , 10 , 3 , 2 } , { INF , 0 , INF , 7 } , { INF , INF , 0 , 6 } , { INF , INF , INF , 0 } } ; int u = 0 , v = 3 , k = 2 ; cout << \\\" Weight ▁ of ▁ the ▁ shortest ▁ path ▁ is ▁ \\\" << shortestPath ( graph , u , v , k ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to express a number as sum of consecutive numbers | Utility method to compute number of ways in which N can be represented as sum of consecutive number ; constraint on values of L gives us the time Complexity as O ( N ^ 0.5 ) ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function countConsecutive ( $ N ) { $ count = 0 ; for ( $ L = 1 ; $ L * ( $ L + 1 ) < 2 * $ N ; $ L ++ ) { $ a = ( int ) ( 1.0 * $ N - ( $ L * ( int ) ( $ L + 1 ) ) \\/ 2 ) \\/ ( $ L + 1 ) ; if ( $ a - ( int ) $ a == 0.0 ) $ count ++ ; } return $ count ; } $ N = 15 ; echo countConsecutive ( $ N ) , \\\" \\n \\\" ; $ N = 10 ; echo countConsecutive ( $ N ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to construct DFA for Regular Expression C ( A + B ) + | Function to find whether the given is Accepted by the DFA ; If n <= 1 , then prNo ; To count the matched characters ; Check if the first character is C ; Traverse the rest of string ; If character is A or B , increment count by 1 ; If the first character is not C , pr - 1 ; If all characters matches ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def DFA ( str , N ) :\\n\\tif ( N <= 1 ) :\\n\\t\\tprint ( \\\" No \\\" )\\n\\t\\treturn\\n\\tcount = 0\\n\\tif ( str [ 0 ] == ' C ' ) :\\n\\t\\tcount += 1\\n\\t\\tfor i in range ( 1 , N ) :\\n\\t\\t\\tif ( str [ i ] == ' A ' or str [ i ] == ' B ' ) :\\n\\t\\t\\t\\tcount += 1\\n\\t\\t\\telse :\\n\\t\\t\\t\\tbreak\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\\n\\t\\treturn\\n\\tif ( count == N ) :\\n\\t\\tprint ( \\\" Yes \\\" )\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tstr = \\\" CAABBAAB \\\"\\n\\tN = len ( str )\\n\\tDFA ( str , N )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Binomial Coefficient | DP | ; function to find gcd of two numbers in O ( log ( min ( a , b ) ) ) ; base case ; better time complexity for lesser r value ; array of elements from n - r + 1 to n ; for numbers from 1 to r find arr [ j ] such that gcd ( i , arr [ j ] ) > 1 ; if gcd > 1 , divide both by gcd ; if i becomes 1 , no need to search arr ; for ( int i : arr ) single pass to multiply the numerator ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static int nCr ( int n , int r ) { if ( r > n ) return 0 ; if ( r > n - r ) C ( n , r ) = C ( n , n - r ) r = n - r ; int mod = 1000000007 ; int [ ] arr = new int [ r ] ; for ( int i = n - r + 1 ; i <= n ; i ++ ) { arr [ i + r - n - 1 ] = i ; } long ans = 1 ; for ( int k = 1 ; k < r + 1 ; k ++ ) { int j = 0 , i = k ; while ( j < arr . length ) { int x = gcd ( i , arr [ j ] ) ; if ( x > 1 ) { arr [ j ] \\/= x ; i \\/= x ; } if ( i == 1 ) break ; j += 1 ; } } ans = ( ans * i ) % mod ; return ( int ) ans ; } public static void main ( String [ ] args ) { int n = 5 , r = 2 ; System . out . print ( \\\" Value ▁ of ▁ C ( \\\" + n + \\\" , ▁ \\\" + r + \\\" ) ▁ is ▁ \\\" + nCr ( n , r ) + \\\"\\n\\\"); } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Smallest integer greater than n such that it consists of digit m exactly k times | Java implementation of the approach ; Function that returns true if n contains digit m exactly k times ; Function to return the smallest integer > n with digit m occurring exactly k times ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static boolean digitWell ( int n , int m , int k ) { int cnt = 0 ; while ( n > 0 ) { if ( n % 10 == m ) ++ cnt ; n \\/= 10 ; } return cnt == k ; } static int findInt ( int n , int m , int k ) { int i = n + 1 ; while ( true ) { if ( digitWell ( i , m , k ) ) return i ; i ++ ; } } public static void main ( String [ ] args ) { int n = 111 , m = 2 , k = 2 ; System . out . println ( findInt ( n , m , k ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Flatten a multilevel linked list |\\\"\\nSolution in C:\",\"targets\":\"struct List { int data ; struct List * next ; struct List * child ; } ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find maximum height to cut all chocolates horizontally such that at least K amount remains | Function to find the sum of remaining chocolate after making the horizontal cut at height mid ; Stores the sum of chocolates ; Traverse the array arr [ ] ; If the height is at least mid ; Return the possible sum ; Function to find the maximum horizontal cut made to all the chocolates such that the sum of the remaining element is at least K ; Ranges of Binary Search ; Perform the Binary Search ; Find the sum of removed after making cut at height mid ; If the chocolate removed is same as the chocolate needed then return the height ; If the chocolate removed is less than chocolate needed then shift to the left range ; Otherwise , shift to the right range ; Return the possible cut ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function cal ( arr , mid ) { let chocolate = 0 for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] >= mid ) chocolate += arr [ i ] - mid } return chocolate } function maximumCut ( arr , K ) { let low = 0 let high = arr [ 0 ] ; for ( let i = 1 ; i < arr . length ; i ++ ) { high = Math . max ( high , arr [ i ] ) ; } while ( low <= high ) { mid = Math . floor ( ( low + high ) \\/ 2 ) ; chocolate = cal ( arr , mid ) if ( chocolate == K ) { return mid } else if ( chocolate < K ) { high = mid - 1 } else { low = mid + 1 if ( mid > high ) high = mid } } return high } let N = 4 ; let K = 7 ; let arr = [ 15 , 20 , 8 , 17 ] ; document . write ( maximumCut ( arr , K ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Area of a circle inscribed in a rectangle which is inscribed in a semicircle | Function to find the area of the circle ; radius cannot be negative ; area of the circle ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function area ( $ r ) { if ( $ r < 0 ) return -1 ; $ area = 3.14 * pow ( $ r \\/ ( 2 * sqrt ( 2 ) ) , 2 ) ; return $ area ; } $ a = 5 ; echo area ( $ a ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the player to reach at least N by multiplying with any value from given range | Java program for the above approach ; Function to find the winner ; Backtrack from N to 1 ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static char Winner ( int N ) { boolean player = true ; while ( N > 1 ) { int den = ( player ) ? 9 : 2 ; int X = N \\/ den ; int Y = N % den ; N = ( Y > 0 ) ? X + 1 : X ; player = ! player ; } if ( player ) return ' B ' ; else return ' A ' ; } public static void main ( String [ ] args ) { int N = 10 ; System . out . print ( Winner ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Program to find whether a given number is power of 2 | Function to check if x is power of 2 ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function isPowerofTwo ( n ) { if ( n == 0 ) return false ; if ( ( n & ( ~ ( n - 1 ) ) ) == n ) return true ; return false ; } if ( isPowerofTwo ( 30 ) == true ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ; if ( isPowerofTwo ( 128 ) == true ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"Largest Independent Set Problem | DP | A naive recursive implementation of Largest Independent Set problem ; A utility function to find max of two integers ; A binary tree node has data , pointer to left child and a pointer to right child ; The function returns size of the largest independent set in a given binary tree ; Calculate size excluding the current node ; Calculate size including the current node ; Return the maximum of two sizes ; A utility function to create a node ; Driver program to test above functions ; Let us construct the tree given in the above diagram\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nint max ( int x , int y ) { return ( x > y ) ? x : y ; } struct node { int data ; struct node * left , * right ; } ; int LISS ( struct node * root ) { if ( root == NULL ) return 0 ; int size_excl = LISS ( root -> left ) + LISS ( root -> right ) ; int size_incl = 1 ; if ( root -> left ) size_incl += LISS ( root -> left -> left ) + LISS ( root -> left -> right ) ; if ( root -> right ) size_incl += LISS ( root -> right -> left ) + LISS ( root -> right -> right ) ; return max ( size_incl , size_excl ) ; } struct node * newNode ( int data ) { struct node * temp = ( struct node * ) malloc ( sizeof ( struct node ) ) ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int main ( ) { struct node * root = newNode ( 20 ) ; root -> left = newNode ( 8 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 12 ) ; root -> left -> right -> left = newNode ( 10 ) ; root -> left -> right -> right = newNode ( 14 ) ; root -> right = newNode ( 22 ) ; root -> right -> right = newNode ( 25 ) ; printf ( \\\" Size ▁ of ▁ the ▁ Largest ▁ Independent ▁ Set ▁ is ▁ % d ▁ \\\" , LISS ( root ) ) ; 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 to reverse a string s = input ( )\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int main ( ) { string s [ ] = { \\\" i \\\" , \\\" like \\\" , \\\" this \\\" , \\\" program \\\" , \\\" very \\\" , \\\" much \\\" } ; string ans = \\\" \\\" ; for ( int i = 5 ; i >= 0 ; i -- ) { ans += s [ i ] + \\\" ▁ \\\" ; } cout << ( \\\" Reversed ▁ String : \\\" ) << endl ; cout << ( ans . substr ( 0 , ans . length ( ) - 1 ) ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"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\\\"\\nHow can the above be solved 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\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to find Nth term of series 1 , 6 , 17 , 34 , 56 , 86 , 121 , 162 , ... ... . | calculate Nth term of series ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def nthTerm ( n ) :\\n\\treturn 3 * pow ( n , 2 ) - 4 * n + 2\\nN = 4\\nprint ( nthTerm ( N ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint averageOdd ( int n ) { if ( n % 2 == 0 ) { printf ( \\\" Invalid ▁ Input \\\" ) ; return -1 ; } return ( n + 1 ) \\/ 2 ; } int main ( ) { int n = 15 ; printf ( \\\" % d \\\" , averageOdd ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"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 Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function insertionSort ( & $ arr , $ n ) { 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 ; } } function printArray ( & $ arr , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo $ arr [ $ i ] . \\\" ▁ \\\" ; echo \\\" \\n \\\" ; } $ arr = array ( 12 , 11 , 13 , 5 , 6 ) ; $ n = sizeof ( $ arr ) ; insertionSort ( $ arr , $ n ) ; printArray ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to duplicate Vowels in String | C ++ 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\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool isVowel ( char ch ) { ch = toupper ( ch ) ; return ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) ; } string duplicateVowels ( string str ) { int t = str . length ( ) ; string res = \\\" \\\" ; for ( int i = 0 ; i < t ; i ++ ) { if ( isVowel ( str [ i ] ) ) { res += str [ i ] ; } res += str [ i ] ; } return res ; } int main ( ) { string str = \\\" helloworld \\\" ; cout << \\\" Original ▁ String : ▁ \\\" << str << endl ; string res = duplicateVowels ( str ) ; cout << \\\" String ▁ with ▁ Vowels ▁ duplicated : ▁ \\\" << res << endl ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Search , insert and delete in a sorted array | C program to implement delete operation in a sorted array ; To search a ley to be deleted ; Function to delete an element ; Find position of element to be deleted ; Deleting element ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\nint binarySearch ( int arr [ ] , int low , int high , int key ) ; int binarySearch ( int arr [ ] , int low , int high , int key ) { if ( high < low ) return -1 ; int mid = ( low + high ) \\/ 2 ; if ( key == arr [ mid ] ) return mid ; if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ; return binarySearch ( arr , low , ( mid - 1 ) , key ) ; } int deleteElement ( int arr [ ] , int n , int key ) { int pos = binarySearch ( arr , 0 , n - 1 , key ) ; if ( pos == -1 ) { printf ( \\\" Element ▁ not ▁ 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 , 20 , 30 , 40 , 50 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int key = 30 ; printf ( \\\" Array ▁ before ▁ deletion \\n \\\" ) ; for ( i = 0 ; i < n ; i ++ ) printf ( \\\" % d ▁ \\\" , arr [ i ] ) ; n = deleteElement ( arr , n , key ) ; printf ( \\\" Array after deletion \\\" for ( i = 0 ; i < n ; i ++ ) printf ( \\\" % d ▁ \\\" , arr [ i ] ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of n digit stepping numbers | Space optimized solution | Java program to calculate the number of n digit stepping numbers . ; 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 code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static long answer ( int n ) { int [ ] dp = new int [ 10 ] ; int [ ] prev = new int [ 10 ] ; if ( n == 1 ) return 10 ; for ( int j = 0 ; j <= 9 ; j ++ ) dp [ j ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= 9 ; j ++ ) { prev [ j ] = dp [ j ] ; } for ( int 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 ] ; } } long sum = 0 ; for ( int j = 1 ; j <= 9 ; j ++ ) sum += dp [ j ] ; return sum ; } public static void main ( String [ ] args ) { int n = 2 ; System . out . println ( answer ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Given an n x n square matrix , find sum of all sub | An efficient Java program to find sum of all subsquares of size k x k ; Size of given matrix ; A O ( n ^ 2 ) function to find sum of all sub - squares of size k x k in a given square matrix of size n x n ; k must be smaller than or equal to n ; 1 : PREPROCESSING To store sums of all strips of size k x 1 ; Go column by column ; Calculate sum of first k x 1 rectangle in this column ; Calculate sum of remaining rectangles ; 2 : CALCULATE SUM of Sub - Squares using stripSum [ ] [ ] ; Calculate and print sum of first subsquare in this row ; Calculate sum of remaining squares in current row by removing the leftmost strip of previous sub - square and adding a new strip ; Driver program to test above function\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static int n = 5 ; static void printSumTricky ( int mat [ ] [ ] , int k ) { if ( k > n ) return ; int stripSum [ ] [ ] = new int [ n ] [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { int sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) sum += mat [ i ] [ j ] ; stripSum [ 0 ] [ j ] = sum ; for ( int i = 1 ; i < n - k + 1 ; i ++ ) { sum += ( mat [ i + k - 1 ] [ j ] - mat [ i - 1 ] [ j ] ) ; stripSum [ i ] [ j ] = sum ; } } for ( int i = 0 ; i < n - k + 1 ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < k ; j ++ ) sum += stripSum [ i ] [ j ] ; System . out . print ( sum + \\\" ▁ \\\" ) ; for ( int j = 1 ; j < n - k + 1 ; j ++ ) { sum += ( stripSum [ i ] [ j + k - 1 ] - stripSum [ i ] [ j - 1 ] ) ; System . out . print ( sum + \\\" ▁ \\\" ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { 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 } , } ; int k = 3 ; printSumTricky ( mat , k ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 ; finding maximum and minimum of an array ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\n#include \\nint solve ( int a [ ] , int n ) { int min1 = a [ 0 ] ; int max1 = a [ 0 ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > max1 ) max1 = a [ i ] ; if ( a [ i ] < min1 ) min1 = a [ i ] ; } return abs ( min1 - max1 ) ; } int main ( ) { int arr [ ] = { -1 , 2 , 3 , 4 , -10 } ; int size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Largest ▁ gap ▁ is ▁ : ▁ % 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\":\"\\\"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 = \\\" ▁ \\\" )\\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\":\"\\\"Find a point that lies inside exactly K given squares | PHP implementation of the approach ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function PointInKSquares ( $ n , $ a , $ k ) { sort ( $ a ) ; return $ a [ $ n - $ k ] ; } $ k = 2 ; $ a = array ( 1 , 2 , 3 , 4 ) ; $ n = sizeof ( $ a ) ; $ x = PointInKSquares ( $ n , $ a , $ k ) ; echo \\\" ( \\\" . $ x . \\\" , \\\" ▁ . ▁ $ x ▁ . ▁ \\\" ) \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count numbers from 1 to n that have 4 as a digit | C ++ program to count numbers having 4 as a digit ; Function to count numbers from 1 to n that have 4 as a digit ; Base case ; d = number of digits minus one in n . For 328 , d is 2 ; computing count of numbers from 1 to 10 ^ d - 1 , d = 0 a [ 0 ] = 0 ; d = 1 a [ 1 ] = count of numbers from 0 to 9 = 1 d = 2 a [ 2 ] = count of numbers from 0 to 99 = a [ 1 ] * 9 + 10 = 19 d = 3 a [ 3 ] = count of numbers from 0 to 999 = a [ 2 ] * 19 + 100 = 171 ; Computing 10 ^ d ; Most significant digit ( msd ) of n , For 328 , msd is 3 which can be obtained using 328 \\/ 100 ; If MSD is 4. For example if n = 428 , then count of numbers is sum of following . 1 ) Count of numbers from 1 to 399 2 ) Count of numbers from 400 to 428 which is 29. ; IF MSD > 4. For example if n is 728 , then count of numbers is sum of following . 1 ) Count of numbers from 1 to 399 and count of numbers from 500 to 699 , i . e . , \\\" a [ 2 ] ▁ * ▁ 6\\\" 2 ) Count of numbers from 400 to 499 , i . e . 100 3 ) Count of numbers from 700 to 728 , recur for 28 ; IF MSD < 4. For example if n is 328 , then count of numbers is sum of following . 1 ) Count of numbers from 1 to 299 a 2 ) Count of numbers from 300 to 328 , recur for 28 ; Driver Program\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int countNumbersWith4 ( int n ) { if ( n < 4 ) return 0 ; int d = log10 ( n ) ; int * a = new int [ d + 1 ] ; a [ 0 ] = 0 , a [ 1 ] = 1 ; for ( int i = 2 ; i <= d ; i ++ ) a [ i ] = a [ i - 1 ] * 9 + ceil ( pow ( 10 , i - 1 ) ) ; int p = ceil ( pow ( 10 , d ) ) ; int msd = n \\/ p ; if ( msd == 4 ) return ( msd ) * a [ d ] + ( n % p ) + 1 ; if ( msd > 4 ) return ( msd - 1 ) * a [ d ] + p + countNumbersWith4 ( n % p ) ; return ( msd ) * a [ d ] + countNumbersWith4 ( n % p ) ; } int main ( ) { int n = 328 ; cout << \\\" Count ▁ of ▁ numbers ▁ from ▁ 1 ▁ to ▁ \\\" << n << \\\" ▁ that ▁ have ▁ 4 ▁ as ▁ a ▁ a ▁ digit ▁ is ▁ \\\" << countNumbersWith4 ( n ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find the diagonal of the Cube | Function to find length of diagonal of cube ; Formula to Find length of diagonal of cube ; Driver code ; Function call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function diagonal_length ( a ) { let L ; L = a * Math . sqrt ( 3 ) ; return L ; } let a = 5 ; document . write ( diagonal_length ( a ) . toFixed ( 5 ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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-Sharp?\",\"targets\":\"using System ; class PellNumber { public static int pell ( int n ) { if ( n <= 2 ) return n ; int a = 1 ; int b = 2 ; int c ; for ( int i = 3 ; i <= n ; i ++ ) { c = 2 * b + a ; a = b ; b = c ; } return b ; } public static void Main ( ) { int n = 4 ; Console . Write ( pell ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find the day number in the current year for the given date | Javascript implementation of the approach ; Function to return the day number of the year for the given date ; Extract the year , month and the day from the date string ; If current year is a leap year and the date given is after the 28 th of February then it must include the 29 th February ; Add the days in the previous months ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"var days = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] ; function dayOfYear ( date ) { var year = parseInt ( date . substring ( 0 , 4 ) ) ; var month = parseInt ( date . substring ( 5 , 6 ) ) ; var day = parseInt ( date . substring ( 8 ) ) ; if ( month > 2 && year % 4 == 0 && ( year % 100 != 0 year % 400 == 0 ) ) { ++ day ; } while ( month -- > 0 ) { day = day + days [ month - 1 ] ; } return day ; } var date = \\\" \\\" ; document . write ( dayOfYear ( date ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"How to print maximum number of A 's using given four keys | A recursive Java 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 Java:\",\"targets\":\"import java . io . * ; class GFG { static int 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 ; } public static void main ( String [ ] args ) { int N ; for ( N = 1 ; N <= 20 ; N ++ ) System . out . println ( \\\" Maximum ▁ Number ▁ of ▁ A ' s ▁ with ▁ keystrokes ▁ is ▁ \\\" + N + findoptimal ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Area of largest Circle that can be inscribed in a SemiCircle | Function to find the area of the circle ; Radius cannot be negative ; Area of the largest circle ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function circlearea ( R ) { if ( R < 0 ) return - 1 ; var a = 3.14 * R * R \\/ 4 ; return a ; } var R = 2 ; document . write ( circlearea ( R ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sum of bit differences for numbers from 0 to N | 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 ; Given Number ; Function Call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function binpow ( a , b ) { let res = 1 ; while ( b ) { if ( b & 1 ) res = res * a ; a = a * a ; b = Math . floor ( b \\/ 2 ) ; } return res ; } function find ( x ) { if ( x == 0 ) return 0 ; let p = Math . log2 ( x ) ; return binpow ( 2 , p + 1 ) - 1 ; } function getBinary ( n ) { let ans = \\\" \\\" ; while ( n ) { let dig = n % 2 ; ans += String ( dig ) ; n = Math . floor ( n \\/ 2 ) ; } return ans ; } function totalCountDifference ( n ) { let ans = getBinary ( n ) ; let req = 0 ; for ( let i = 0 ; i < ans . length ; i ++ ) { if ( ans [ i ] == ' ' ) { req += find ( binpow ( 2 , i ) ) ; } } return req ; } let N = 5 ; document . write ( totalCountDifference ( N ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find politeness of a number | A function to count all odd prime factors of a given number n ; Eliminate all even prime factor of number of n ; n must be odd at this point , so iterate for only odd numbers till sqrt ( n ) ; if i divides n , then start counting of Odd divisors ; If n odd prime still remains then count it ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function countOddPrimeFactors ( $ n ) { $ result = 1 ; while ( $ n % 2 == 0 ) $ n \\/= 2 ; for ( $ i = 3 ; $ i * $ i <= $ n ; $ i += 2 ) { $ divCount = 0 ; while ( $ n % $ i == 0 ) { $ n \\/= $ i ; ++ $ divCount ; } $ result *= $ divCount + 1 ; } if ( $ n > 2 ) $ result *= 2 ; return $ result ; } function politness ( $ n ) { return countOddPrimeFactors ( $ n ) - 1 ; } $ n = 90 ; echo \\\" Politness ▁ of ▁ \\\" , $ n , \\\" ▁ = ▁ \\\" , politness ( $ n ) , \\\" \\n \\\" ; $ n = 15 ; echo \\\" Politness ▁ of ▁ \\\" , $ n , \\\" ▁ = ▁ \\\" , politness ( $ n ) , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count n digit numbers not having a particular digit | PHP Implementation of above method ; Finding number of possible number with n digits excluding a particular digit ; Checking if number of digits is zero ; Checking if number of digits is one ; Checking if number of digits is odd ; Calling digitNumber function with ( digit - 1 ) \\/ 2 digits ; ; Calling digitNumber function with n \\/ 2 digits ; Calling digitNumber function Checking if excluding digit is zero or non - zero ; Initializing variables\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ mod = 1000000007 ; function digitNumber ( $ n ) { global $ mod ; if ( $ n == 0 ) return 1 ; if ( $ n == 1 ) return 9 ; if ( $ n % 2 != 0 ) { $ temp = digitNumber ( ( $ n - 1 ) \\/ 2 ) % $ mod ; return ( 9 * ( $ temp * $ temp ) % $ mod ) % $ mod ; } else { $ temp = digitNumber ( $ n \\/ 2 ) % $ mod ; return ( $ temp * $ temp ) % $ mod ; } } function countExcluding ( $ n , $ d ) { global $ mod ; if ( $ d == 0 ) return ( 9 * digitNumber ( $ n - 1 ) ) % $ mod ; else return ( 8 * digitNumber ( $ n - 1 ) ) % $ mod ; } $ d = 9 ; $ n = 3 ; print ( countExcluding ( $ n , $ d ) ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find original numbers from gcd ( ) every pair | Utility function to print the contents of an array ; Function to find the required numbers ; Sort array in decreasing order ; Count frequency of each element ; Size of the resultant array ; Store the highest element in the resultant array ; Decrement the frequency of that element ; Compute GCD ; Decrement GCD value by 2 ; Reverse array ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + \\\" \\\" ) ; } } function findNumbers ( arr , n ) { arr . sort ( function ( a , b ) { return a - b } ) ; reverse ( arr ) ; let freq = new Array ( arr [ 0 ] + 1 ) ; freq . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { freq [ arr [ i ] ] ++ ; } let size = parseInt ( Math . sqrt ( n ) , 10 ) ; let brr = new Array ( size ) ; brr . fill ( 0 ) ; let x , l = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( freq [ arr [ i ] ] > 0 && l < size ) { brr [ l ] = arr [ i ] ; freq [ brr [ l ] ] -- ; l ++ ; for ( let j = 0 ; j < l ; j ++ ) { if ( i != j ) { x = __gcd ( arr [ i ] , brr [ j ] ) ; freq [ x ] -= 2 ; } } } } printArr ( brr , size ) ; } function reverse ( input ) { let last = input . length - 1 ; let middle = parseInt ( input . length \\/ 2 , 10 ) ; for ( let i = 0 ; i <= middle ; i ++ ) { let temp = input [ i ] ; input [ i ] = input [ last - i ] ; input [ last - i ] = temp ; } } function __gcd ( a , b ) { if ( b == 0 ) { return a ; } return __gcd ( b , a % b ) ; } let arr = [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 5 , 5 , 5 , 7 , 10 , 12 , 2 , 2 ] ; let n = arr . length ; findNumbers ( arr , n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximum sum of pairs that are at least K distance apart in an array | Function to find the largest sum pair that are K distant apart ; Stores the prefix maximum array ; Base Case ; Traverse the array and update the maximum value upto index i ; Stores the maximum sum of pairs ; Iterate over the range [ K , N ] ; Find the maximum value of the sum of valid pairs ; Return the resultant sum ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function getMaxPairSum ( arr , N , K ) { var preMax = Array ( N ) ; preMax [ 0 ] = arr [ 0 ] ; for ( var i = 1 ; i < N ; i ++ ) { preMax [ i ] = Math . max ( preMax [ i - 1 ] , arr [ i ] ) ; } var res = - 1000000000 ; for ( var i = K ; i < N ; i ++ ) { res = Math . max ( res , arr [ i ] + preMax [ i - K ] ) ; } return res ; } var arr = [ 1 , 2 , 4 , 8 , 6 , 3 ] ; var K = 3 ; var N = arr . length ; document . write ( getMaxPairSum ( arr , N , K ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Final cell position in the matrix | function to find the final cell position in the given matrix ; to count up , down , left and cright movements ; to store the final coordinate position ; traverse the command array ; calculate final values ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function finalPos ( $ command , $ n , $ x , $ y ) { $ cup ; $ cdown ; $ cleft ; $ cright ; $ final_x ; $ final_y ; $ cup = $ cdown = $ cleft = $ cright = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ command [ $ i ] == ' U ' ) $ cup ++ ; else if ( $ command [ $ i ] == ' D ' ) $ cdown ++ ; else if ( $ command [ $ i ] == ' L ' ) $ cleft ++ ; else if ( $ command [ $ i ] == ' R ' ) $ cright ++ ; } $ final_x = $ x + ( $ cright - $ cleft ) ; $ final_y = $ y + ( $ cdown - $ cup ) ; echo \\\" Final ▁ Position : ▁ \\\" . \\\" ( \\\" . $ final_x . \\\" , ▁ \\\" . $ final_y . \\\" ) \\\" ; } $ command = \\\" DDLRULL \\\" ; $ n = strlen ( $ command ) ; $ x = 3 ; $ y = 4 ; finalPos ( $ command , $ n , $ x , $ y ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Construct two N | C # program for the above approach ; Satisfying the given conditions ; Declare the two arrays A and B ; Iterate from range [ 1 , 2 * n ] ; Assign consecutive numbers to same indices of the two arrays ; Print the first array ; Print the second array , B ; Driver Code ; Function Call\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void printArrays ( int n ) { List < int > A = new List < int > ( ) ; List < int > B = new List < int > ( ) ; for ( int i = 1 ; i <= 2 * n ; i ++ ) { if ( i % 2 == 0 ) A . Add ( i ) ; else B . Add ( i ) ; } Console . Write ( \\\" { ▁ \\\" ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( A [ i ] ) ; if ( i != n - 1 ) Console . Write ( \\\" , ▁ \\\" ) ; } Console . Write ( \\\" ▁ } \\n \\\" ) ; Console . Write ( \\\" { ▁ \\\" ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( B [ i ] ) ; if ( i != n - 1 ) Console . Write ( \\\" , ▁ \\\" ) ; } Console . Write ( \\\" ▁ } \\\" ) ; } public static void Main ( ) { int N = 5 ; printArrays ( N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Detect loop in a linked list | Java program to detect loop in a linked list ; head of list ; Linked list Node ; Inserts a new Node at front of the list . ; 1 & 2 : Allocate the Node & Put in the data ; 3. Make next of new Node as head ; 4. Move the head to point to new Node ; Driver program to test above functions ; Start with the empty list ; Create loop for testing\\\"\\nSolution in Java:\",\"targets\":\"class LinkedList { Node head ; class Node { int data ; Node next ; Node ( int d ) { data = d ; next = null ; } } public void push ( int new_data ) { Node new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; } void detectLoop ( ) { Node slow_p = head , fast_p = head ; int flag = 0 ; while ( slow_p != null && fast_p != null && fast_p . next != null ) { slow_p = slow_p . next ; fast_p = fast_p . next . next ; if ( slow_p == fast_p ) { flag = 1 ; break ; } } if ( flag == 1 ) System . out . println ( \\\" Loop ▁ found \\\" ) ; else System . out . println ( \\\" Loop ▁ not ▁ found \\\" ) ; } public static void main ( String args [ ] ) { LinkedList llist = new LinkedList ( ) ; llist . push ( 20 ) ; llist . push ( 4 ) ; llist . push ( 15 ) ; llist . push ( 10 ) ; llist . head . next . next . next . next = llist . head ; llist . detectLoop ( ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Online Queries for GCD of array after divide operations | PHP implementation of the approach returns the gcd after all updates in the array ; Function to calculate gcd of onine queries ; stores the gcd of the initial array elements ; calculates the gcd ; performing online queries ; index is 1 based ; divide the array element ; calculates the current gcd ; print the gcd after each step ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function gcd ( $ a , $ b ) { if ( $ a == 0 ) return $ b ; return gcd ( $ b % $ a , $ a ) ; } function print_gcd_online ( $ n , $ m , $ query , $ arr ) { $ max_gcd = 0 ; $ i = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ max_gcd = gcd ( $ max_gcd , $ arr [ $ i ] ) ; for ( $ i = 0 ; $ i < $ m ; $ i ++ ) { $ query [ $ i ] [ 0 ] -- ; $ arr [ $ query [ $ i ] [ 0 ] ] \\/= $ query [ $ i ] [ 1 ] ; $ max_gcd = gcd ( $ arr [ $ query [ $ i ] [ 0 ] ] , $ max_gcd ) ; echo ( $ max_gcd ) , \\\" \\n \\\" ; } } $ n = 3 ; $ m = 3 ; $ query ; $ arr = array ( 36 , 24 , 72 ) ; $ query [ 0 ] [ 0 ] = 1 ; $ query [ 0 ] [ 1 ] = 3 ; $ query [ 1 ] [ 0 ] = 3 ; $ query [ 1 ] [ 1 ] = 12 ; $ query [ 2 ] [ 0 ] = 2 ; $ query [ 2 ] [ 1 ] = 4 ; print_gcd_online ( $ n , $ m , $ query , $ arr ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Given an n x n square matrix , find sum of all sub | Size of given matrix ; A O ( n ^ 2 ) function to find sum of all sub - squares of size k x k in a given square matrix of size n x n ; k must be smaller than or equal to n ; 1 : PREPROCESSING To store sums of all strips of size k x 1 ; Go column by column ; Calculate sum of first k x 1 rectangle in this column ; Calculate sum of remaining rectangles ; 2 : CALCULATE SUM of Sub - Squares using stripSum [ ] [ ] ; Calculate and print sum of first subsquare in this row ; Calculate sum of remaining squares in current row by removing the leftmost strip of previous sub - square and adding a new strip ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ n = 5 ; function printSumTricky ( $ mat , $ k ) { global $ n ; if ( $ k > $ n ) return ; $ stripSum = array ( array ( ) ) ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { $ sum = 0 ; for ( $ i = 0 ; $ i < $ k ; $ i ++ ) $ sum += $ mat [ $ i ] [ $ j ] ; $ stripSum [ 0 ] [ $ j ] = $ sum ; for ( $ i = 1 ; $ i < $ n - $ k + 1 ; $ i ++ ) { $ sum += ( $ mat [ $ i + $ k - 1 ] [ $ j ] - $ mat [ $ i - 1 ] [ $ j ] ) ; $ stripSum [ $ i ] [ $ j ] = $ sum ; } } for ( $ i = 0 ; $ i < $ n - $ k + 1 ; $ i ++ ) { $ sum = 0 ; for ( $ j = 0 ; $ j < $ k ; $ j ++ ) $ sum += $ stripSum [ $ i ] [ $ j ] ; echo $ sum , \\\" \\\" ; for ( $ j = 1 ; $ j < $ n - $ k + 1 ; $ j ++ ) { $ sum += ( $ stripSum [ $ i ] [ $ j + $ k - 1 ] - $ stripSum [ $ i ] [ $ j - 1 ] ) ; echo $ sum , \\\" \\\" ; } echo \\\" \\n \\\" ; } } $ mat = array ( array ( 1 , 1 , 1 , 1 , 1 ) , array ( 2 , 2 , 2 , 2 , 2 ) , array ( 3 , 3 , 3 , 3 , 3 ) , array ( 4 , 4 , 4 , 4 , 4 ) , array ( 5 , 5 , 5 , 5 , 5 ) ) ; $ k = 3 ; printSumTricky ( $ mat , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum steps to change N to 1 by changing it to 2 * N or N \\/ 10 at any step | Java program for the above approach ; Function to check if N can be changed to 1 or not . ; Count the number of 2 in the prime factorisation of N ; Count the number of 5 in the prime factorisation of N ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static void check ( int N ) { int twos = 0 , fives = 0 ; while ( N % 2 == 0 ) { N \\/= 2 ; twos ++ ; } while ( N % 5 == 0 ) { N \\/= 5 ; fives ++ ; } if ( N == 1 && twos <= fives ) { System . out . println ( 2 * fives - twos ) ; } else { System . out . println ( - 1 ) ; } } public static void main ( String [ ] args ) { int N = 50 ; check ( N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Construct the smallest possible Array with given Sum and XOR | Function to find array ; Array not possible ; Array possible with exactly 1 or no element ; Checking array with two elements possible or not . ; Given sum and value of Bitwise XOR ; Function Call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findArray ( _sum , xorr ) :\\n\\tif ( xorr > _sum or _sum % 2 != xorr % 2 ) :\\n\\t\\tprint ( \\\" No ▁ Array ▁ Possible \\\" )\\n\\t\\treturn\\n\\tif ( _sum == xorr ) :\\n\\t\\tif ( _sum == 0 ) :\\n\\t\\t\\tprint ( \\\" Array ▁ is ▁ empty \\\" , \\\" ▁ with ▁ size ▁ 0\\\" )\\n\\t\\telse :\\n\\t\\t\\tprint ( \\\" Array ▁ size ▁ is \\\" , 1 )\\n\\t\\t\\tprint ( \\\" Array ▁ is \\\" , _sum )\\n\\t\\treturn\\n\\tmid = ( _sum - xorr ) \\/\\/ 2\\n\\tif ( xorr & mid == 1 ) :\\n\\t\\tprint ( \\\" Array ▁ size ▁ is \\\" , 3 )\\n\\t\\tprint ( \\\" Array ▁ is \\\" , xorr , mid , mid )\\n\\telse :\\n\\t\\tprint ( \\\" Array ▁ size ▁ is \\\" , 2 )\\n\\t\\tprint ( \\\" Array ▁ is \\\" , ( xorr + mid ) , mid )\\n_sum = 4\\nxorr = 2\\nfindArray ( _sum , xorr )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Centered Hexadecagonal Number | centered hexadecagonal function ; Formula to calculate nth centered hexadecagonal number ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function center_hexadecagonal_num ( $ n ) { return 8 * $ n * $ n - 8 * $ n + 1 ; } $ n = 2 ; echo $ n , \\\" th ▁ centered ▁ hexadecagonal ▁ number ▁ : ▁ \\\" , center_hexadecagonal_num ( $ n ) ; echo \\\" \\n \\\" ; $ n = 12 ; echo $ n , \\\" th ▁ centered ▁ hexadecagonal ▁ numbe ▁ : ▁ \\\" , center_hexadecagonal_num ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximum area rectangle by picking four sides from array | function for finding max area ; sort array in non - increasing order ; Initialize two sides of rectangle ; traverse through array ; if any element occurs twice store that as dimension ; return the product of dimensions ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function findArea ( $ arr , $ n ) { rsort ( $ arr ) ; $ dimension = array ( 0 , 0 ) ; for ( $ i = 0 , $ j = 0 ; $ i < $ n - 1 && $ j < 2 ; $ i ++ ) if ( $ arr [ $ i ] == $ arr [ $ i + 1 ] ) $ dimension [ $ j ++ ] = $ arr [ $ i ++ ] ; return ( $ dimension [ 0 ] * $ dimension [ 1 ] ) ; } $ arr = array ( 4 , 2 , 1 , 4 , 6 , 6 , 2 , 5 ) ; $ n = count ( $ arr ) ; echo findArea ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Missing occurrences of a number in an array such that maximum absolute difference of adjacent elements is minimum | C ++ implementation of the missing number such that maximum absolute difference between adjacent element is minimum ; Function to find the missing number such that maximum absolute difference is minimum ; Loop to find the maximum and minimum adjacent element to missing number ; Driver Code ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int missingnumber ( int n , int arr [ ] ) { int mn = INT_MAX , mx = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { if ( i > 0 && arr [ i ] == -1 && arr [ i - 1 ] != -1 ) { mn = min ( mn , arr [ i - 1 ] ) ; mx = max ( mx , arr [ i - 1 ] ) ; } if ( i < ( n - 1 ) && arr [ i ] == -1 && arr [ i + 1 ] != -1 ) { mn = min ( mn , arr [ i + 1 ] ) ; mx = max ( mx , arr [ i + 1 ] ) ; } } long long int res = ( mx + mn ) \\/ 2 ; return res ; } int main ( ) { int n = 5 ; int arr [ 5 ] = { -1 , 10 , -1 , 12 , -1 } ; int ans = 0 ; int res = missingnumber ( n , arr ) ; cout << res ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Hexanacci Numbers | Function to print the Nth term of the Hexanacci number ; Initialize first five numbers to base cases ; Declare a current variable ; Loop to add previous five numbers for each number starting from 5 and then assign first , second , third , fourth fifth to second , third , fourth , fifth and curr to sixth respectively ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function printhexa ( n ) { if ( n < 0 ) return ; let first = 0 ; let second = 0 ; let third = 0 ; let fourth = 0 ; let fifth = 0 ; let sixth = 1 ; let curr = 0 ; if ( n < 6 ) document . write ( first ) ; else if ( n == 6 ) document . write ( sixth ) ; else { for ( let i = 6 ; i < n ; i ++ ) { curr = first + second + third + fourth + fifth + sixth ; first = second ; second = third ; third = fourth ; fourth = fifth ; fifth = sixth ; sixth = curr ; } } document . write ( curr ) ; } let n = 11 ; printhexa ( n ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Print number in ascending order which contains 1 , 2 and 3 in their digits . | CPP program to print all number containing 1 , 2 and 3 in any order . ; prints all the number containing 1 , 2 , 3 ; check if the number contains 1 , 2 & 3 in any order ; sort all the numbers ; convert the number to string and find if it contains 1 , 2 & 3. ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; string printNumbers ( int numbers [ ] , int n ) { vector < int > oneTwoThree ; for ( int i = 0 ; i < n ; i ++ ) { if ( findContainsOneTwoThree ( numbers [ i ] ) ) oneTwoThree . push_back ( numbers [ i ] ) ; } sort ( oneTwoThree . begin ( ) , oneTwoThree . end ( ) ) ; string result = \\\" \\\" ; for ( auto number : oneTwoThree ) { int value = number ; if ( result . length ( ) > 0 ) result += \\\" , ▁ \\\" ; result += to_string ( value ) ; } return ( result . length ( ) > 0 ) ? result : \\\" - 1\\\" ; } bool findContainsOneTwoThree ( int number ) { string str = to_string ( number ) ; int countOnes = 0 , countTwo = 0 , countThree = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == '1' ) countOnes ++ ; else if ( str [ i ] == '2' ) countTwo ++ ; else if ( str [ i ] == '3' ) countThree ++ ; } return ( countOnes && countTwo && countThree ) ; } int main ( ) { int numbers [ ] = { 123 , 1232 , 456 , 234 , 32145 } ; int n = sizeof ( numbers ) \\/ sizeof ( numbers [ 0 ] ) ; string result = printNumbers ( numbers , n ) ; cout << result ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find K such that changing all elements of the Array greater than K to K will make array sum N | Function to return K such that changing all elements greater than K to K will make array sum N otherwise return - 1 ; Sorting the array in increasing order ; Loop through all the elements of the array ; Checking if sum of array equals N ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def findK ( arr , size , N ) :\\n\\tarr = sorted ( arr )\\n\\ttemp_sum = 0\\n\\tfor i in range ( size ) :\\n\\t\\ttemp_sum += arr [ i ]\\n\\t\\tif ( N - temp_sum == arr [ i ] * ( size - i - 1 ) ) :\\n\\t\\t\\treturn arr [ i ]\\n\\treturn - 1\\narr = [ 3 , 1 , 10 , 4 , 8 ]\\nsize = len ( arr )\\nN = 16\\nprint ( findK ( arr , size , N ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Perpendicular distance between a point and a Line in 2 D | Function to find distance ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function shortest_distance ( $ x1 , $ y1 , $ a , $ b , $ c ) { $ d = abs ( ( $ a * $ x1 + $ b * $ y1 + $ c ) ) \\/ ( sqrt ( $ a * $ a + $ b * $ b ) ) ; echo \\\" Perpendicular ▁ distance ▁ is ▁ \\\" , $ d ; } $ x1 = 5 ; $ y1 = 6 ; $ a = -2 ; $ b = 3 ; $ c = 4 ; shortest_distance ( $ x1 , $ y1 , $ a , $ b , $ c ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Search an element in a sorted and rotated array with duplicates | Java 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 Java:\",\"targets\":\"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 ) ; } else if ( arr [ l ] <= arr [ mid ] ) { if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ; else return search ( arr , mid + 1 , h , key ) ; } else 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 ( String [ ] args ) { int arr [ ] = { 3 , 3 , 1 , 2 , 3 , 3 } ; int n = arr . length ; int key = 3 ; System . out . println ( search ( arr , 0 , n - 1 , key ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Number of sequences which has HEAD at alternate positions to the right of the first HEAD | function to calculate total sequences possible ; Value of N is even ; Value of N is odd ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findAllSequence ( N ) :\\n\\tif ( N % 2 == 0 ) :\\n\\t\\treturn ( pow ( 2 , N \\/ 2 + 1 ) + pow ( 2 , N \\/ 2 ) - 2 ) ;\\n\\telse :\\n\\t\\treturn ( pow ( 2 , ( N + 1 ) \\/ 2 ) + pow ( 2 , ( N + 1 ) \\/ 2 ) - 2 ) ;\\nN = 2 ;\\nprint ( int ( findAllSequence ( N ) ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Queries on XOR of greatest odd divisor of the range | Precompute the prefix XOR of greatest odd divisor ; Finding the Greatest Odd divisor ; Finding prefix XOR ; Return XOR of the range ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def prefixXOR ( arr , preXOR , n ) :\\n\\tfor i in range ( 0 , n , 1 ) :\\n\\t\\twhile ( arr [ i ] % 2 != 1 ) :\\n\\t\\t\\tarr [ i ] = int ( arr [ i ] \\/ 2 )\\n\\t\\tpreXOR [ i ] = arr [ i ]\\n\\tfor i in range ( 1 , n , 1 ) :\\n\\t\\tpreXOR [ i ] = preXOR [ i - 1 ] ^ preXOR [ i ]\\ndef query ( preXOR , l , r ) :\\n\\tif ( l == 0 ) :\\n\\t\\treturn preXOR [ r ]\\n\\telse :\\n\\t\\treturn preXOR [ r ] ^ preXOR [ l - 1 ]\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 3 , 4 , 5 ]\\n\\tn = len ( arr )\\n\\tpreXOR = [ 0 for i in range ( n ) ]\\n\\tprefixXOR ( arr , preXOR , n )\\n\\tprint ( query ( preXOR , 0 , 2 ) )\\n\\tprint ( query ( preXOR , 1 , 2 ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Finding a Non Transitive Co | Java program to find possible non transitive triplets btw L and R ; Function to return gcd of a and b ; function to check for gcd ; a and b are coprime if their gcd is 1. ; Checks if any possible triplet ( a , b , c ) satifying the condition that ( a , b ) is coprime , ( b , c ) is coprime but ( a , c ) isnt ; Generate and check for all possible triplets between L and R ; if we find any such triplets set flag to true ; flag = True indicates that a pair exists between L and R ; Driver code ; finding possible Triplet between 2 and 10 ; finding possible Triplet between 23 and 46\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static boolean coprime ( int a , int b ) { return ( gcd ( a , b ) == 1 ) ; } static void possibleTripletInRange ( int L , int R ) { boolean flag = false ; int possibleA = 0 , possibleB = 0 , possibleC = 0 ; for ( int a = L ; a <= R ; a ++ ) { for ( int b = a + 1 ; b <= R ; b ++ ) { for ( int c = b + 1 ; c <= R ; c ++ ) { if ( coprime ( a , b ) && coprime ( b , c ) && ! coprime ( a , c ) ) { flag = true ; possibleA = a ; possibleB = b ; possibleC = c ; break ; } } } } if ( flag == true ) { System . out . println ( \\\" ( \\\" + possibleA + \\\" , ▁ \\\" + possibleB + \\\" , ▁ \\\" + possibleC + \\\" ) \\\" + \\\" ▁ is ▁ one ▁ such ▁ possible ▁ triplet ▁ \\\" + \\\" between ▁ \\\" + L + \\\" ▁ and ▁ \\\" + R ) ; } else { System . out . println ( \\\" No ▁ Such ▁ Triplet ▁ exists \\\" + \\\" between ▁ \\\" + L + \\\" ▁ and ▁ \\\" + R ) ; } } public static void main ( String [ ] args ) { int L , R ; L = 2 ; R = 10 ; possibleTripletInRange ( L , R ) ; L = 23 ; R = 46 ; possibleTripletInRange ( L , R ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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\\nHow can the above be solved 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 ▁ \\\" , C ) ; C = C * ( line - i ) \\/ i ; } printf ( \\\" \\n \\\" ) ; } } int main ( ) { int n = 5 ; printPascal ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"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 + â €¦ . . + 1 \\/ 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 Maths { static double Series ( int n ) { int i ; double sums = 0.0 , ser ; for ( i = 1 ; i <= n ; ++ i ) { ser = 1 \\/ Math . pow ( i , i ) ; sums += ser ; } return sums ; } public static void main ( String [ ] args ) { int n = 3 ; double res = Series ( n ) ; res = Math . round ( res * 100000.0 ) \\/ 100000.0 ; System . out . println ( res ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum flips required to generate continuous substrings of 0 â €™ s and 1 â €™ s | Javascript 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 Javascript:\",\"targets\":\"function minChanges ( str , N ) { var res ; var count0 = 0 , count1 = 0 ; str . split ( ' ' ) . forEach ( x => { count0 += ( x == ' ' ) ; } ) ; res = count0 ; str . split ( ' ' ) . forEach ( x => { count0 -= ( x == ' ' ) ; count1 += ( x == ' ' ) ; res = Math . min ( res , count1 + count0 ) ; } ) ; return res ; } var N = 9 ; var str = \\\" \\\" ; document . write ( minChanges ( str , N ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Number of ways to split a binary number such that every part is divisible by 2 | 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 Python:\",\"targets\":\"def cntSplits ( s ) :\\n\\tif ( s [ len ( s ) - 1 ] == '1' ) :\\n\\t\\treturn 0 ;\\n\\tc_zero = 0 ;\\n\\tfor i in range ( len ( s ) ) :\\n\\t\\tc_zero += ( s [ i ] == '0' ) ;\\n\\treturn int ( pow ( 2 , c_zero - 1 ) ) ;\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\ts = \\\"10010\\\" ;\\n\\tprint ( cntSplits ( s ) ) ;\",\"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 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 ) { if ( n <= 0 ) return 0 ; int max_val = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) max_val = max ( max_val , price [ i ] + cutRod ( price , n - i - 1 ) ) ; return max_val ; } int main ( ) { int arr [ ] = { 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 } ; int size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printf ( \\\" Maximum ▁ Obtainable ▁ Value ▁ is ▁ % dn \\\" , cutRod ( arr , size ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"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 . ; Driven Program\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int sumDivisorsOfDivisors ( int n ) { map < int , int > mp ; for ( int j = 2 ; j <= sqrt ( n ) ; j ++ ) { int count = 0 ; while ( n % j == 0 ) { n \\/= j ; count ++ ; } if ( count ) mp [ j ] = count ; } if ( n != 1 ) mp [ n ] = 1 ; int ans = 1 ; for ( auto it : mp ) { int pw = 1 ; int sum = 0 ; for ( int i = it . second + 1 ; i >= 1 ; i -- ) { sum += ( i * pw ) ; pw *= it . first ; } ans *= sum ; } return ans ; } int main ( ) { int n = 10 ; cout << sumDivisorsOfDivisors ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Remove an element to minimize the LCM of the given array | C ++ implementation of the above approach ; Function to return the LCM of two numbers ; Function to return the minimum LCM after removing a single element from the given array ; Prefix and Suffix arrays ; Single state dynamic programming relation for storing LCM of first i elements from the left in Prefix [ i ] ; Initializing Suffix array ; Single state dynamic programming relation for storing LCM of all the elements having index greater than or equal to i in Suffix [ i ] ; If first or last element of the array has to be removed ; If any other element is replaced ; Return the minimum LCM ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int lcm ( int a , int b ) { int GCD = __gcd ( a , b ) ; return ( a * b ) \\/ GCD ; } int MinLCM ( int a [ ] , int n ) { int Prefix [ n + 2 ] ; int Suffix [ n + 2 ] ; Prefix [ 1 ] = a [ 0 ] ; for ( int i = 2 ; i <= n ; i += 1 ) { Prefix [ i ] = lcm ( Prefix [ i - 1 ] , a [ i - 1 ] ) ; } Suffix [ n ] = a [ n - 1 ] ; for ( int i = n - 1 ; i >= 1 ; i -= 1 ) { Suffix [ i ] = lcm ( Suffix [ i + 1 ] , a [ i - 1 ] ) ; } int ans = min ( Suffix [ 2 ] , Prefix [ n - 1 ] ) ; for ( int i = 2 ; i < n ; i += 1 ) { ans = min ( ans , lcm ( Prefix [ i - 1 ] , Suffix [ i + 1 ] ) ) ; } return ans ; } int main ( ) { int a [ ] = { 5 , 15 , 9 , 36 } ; int n = sizeof ( a ) \\/ sizeof ( a [ 0 ] ) ; cout << MinLCM ( a , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimum distance between two occurrences of maximum | C program to find Min distance of maximum element ; function to return min distance ; case a ; case b ; case c ; driver program\\\"\\nSolution in C:\",\"targets\":\"#include \\nusing namespace std ; int minDistance ( int arr [ ] , int n ) { int maximum_element = arr [ 0 ] ; int min_dis = n ; int index = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( maximum_element == arr [ i ] ) { min_dis = min ( min_dis , ( i - index ) ) ; index = i ; } else if ( maximum_element < arr [ i ] ) { maximum_element = arr [ i ] ; min_dis = n ; index = i ; } else continue ; } return min_dis ; } int main ( ) { int arr [ ] = { 6 , 3 , 1 , 3 , 6 , 4 , 6 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << \\\" Minimum ▁ distance ▁ = ▁ \\\" << minDistance ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Optimal Binary Search Tree | DP | Dynamic Programming code for Optimal Binary Search Tree Problem ; A utility function to get sum of array elements freq [ i ] to freq [ j ] ; A Dynamic Programming based function that calculates minimum cost of a Binary Search Tree . ; Create an auxiliary 2D matrix to store results of subproblems ; For a single key , cost is equal to frequency of the key ; Now we need to consider chains of length 2 , 3 , ... . L is chain length . ; i is row number in cost ; Get column number j from row number i and chain length L ; Try making all keys in interval keys [ i . . j ] as root ; c = cost when keys [ r ] becomes root of this subtree ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"INT_MAX = 2147483647\\ndef sum ( freq , i , j ) :\\n\\ts = 0\\n\\tfor k in range ( i , j + 1 ) :\\n\\t\\ts += freq [ k ]\\n\\treturn s\\ndef optimalSearchTree ( keys , freq , n ) :\\n\\tcost = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\\n\\tfor i in range ( n ) :\\n\\t\\tcost [ i ] [ i ] = freq [ i ]\\n\\tfor L in range ( 2 , n + 1 ) :\\n\\t\\tfor i in range ( n - L + 2 ) :\\n\\t\\t\\tj = i + L - 1\\n\\t\\t\\tif i >= n or j >= n :\\n\\t\\t\\t\\tbreak\\n\\t\\t\\tcost [ i ] [ j ] = INT_MAX\\n\\t\\t\\tfor r in range ( i , j + 1 ) :\\n\\t\\t\\t\\tc = 0\\n\\t\\t\\t\\tif ( r > i ) :\\n\\t\\t\\t\\t\\tc += cost [ i ] [ r - 1 ]\\n\\t\\t\\t\\tif ( r < j ) :\\n\\t\\t\\t\\t\\tc += cost [ r + 1 ] [ j ]\\n\\t\\t\\t\\tc += sum ( freq , i , j )\\n\\t\\t\\t\\tif ( c < cost [ i ] [ j ] ) :\\n\\t\\t\\t\\t\\tcost [ i ] [ j ] = c\\n\\treturn cost [ 0 ] [ n - 1 ]\\nif __name__ == ' _ _ main _ _ ' :\\n\\tkeys = [ 10 , 12 , 20 ]\\n\\tfreq = [ 34 , 8 , 50 ]\\n\\tn = len ( keys )\\n\\tprint ( \\\" Cost ▁ of ▁ Optimal ▁ BST ▁ is \\\" , optimalSearchTree ( keys , freq , n ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Number of positions with Same address in row major and column major order | C # Program to count the number of positions with same address in row major and column major order ; Returns count of required positions ; horizontal 1D array ; vertical 1D array ; iterating for all possible i ; checking if j is integer ; checking if j lies b \\/ w 1 to N ; iterating for all possible j ; checking if i is integer ; checking if i lies b \\/ w 1 to M ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int getCount ( int M , int N ) { int count = 0 ; if ( M == 1 ) return N ; if ( N == 1 ) return M ; if ( N > M ) { for ( int i = 1 ; i <= M ; i ++ ) { int numerator = N * i - N + M - i ; int denominator = M - 1 ; if ( numerator % denominator == 0 ) { int j = numerator \\/ denominator ; if ( j >= 1 && j <= N ) count ++ ; } } } else { for ( int j = 1 ; j <= N ; j ++ ) { int numerator = M * j - M + N - j ; int denominator = N - 1 ; if ( numerator % denominator == 0 ) { int i = numerator \\/ denominator ; if ( i >= 1 && i <= M ) count ++ ; } } } return count ; } public static void Main ( ) { int M = 3 , N = 5 ; Console . WriteLine ( getCount ( M , N ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"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 3 | CPP program to find the smallest positive missing number ; Function to find the smallest positive missing number ; Default smallest Positive Integer ; Store values in set which are greater than variable m ; Store value when m is less than current index of given array ; Increment m when it is equal to current element ; Increment m when it is one of the element of the set ; Return the required answer ; Driver code ; Function call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int findMissingPositive ( int arr [ ] , int n ) { int m = 1 ; set < int > x ; for ( int i = 0 ; i < n ; i ++ ) { if ( m < arr [ i ] ) { x . insert ( arr [ i ] ) ; } else if ( m == arr [ i ] ) { m = m + 1 ; while ( x . count ( m ) ) { x . erase ( m ) ; m = m + 1 ; } } } return m ; } int main ( ) { int arr [ ] = { 2 , 3 , -7 , 6 , 8 , 1 , -10 , 15 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << findMissingPositive ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of cuts required to pay salary from N length Gold Bar | Python Implementation to find the minimum number of cuts to pay the worker . ; Function to find the minimum number of cuts to pay the worker . ; Nearest Integer to the Log value of the number N ; Driver Code ; Cuts Required in the Length of 15\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import math\\ndef pay ( n ) :\\n\\tcuts = int ( math . log ( n , 2 ) )\\n\\treturn cuts\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tn = 5\\n\\tcuts = pay ( n )\\n\\tprint ( cuts )\\n\\tn = 15\\n\\tcuts = pay ( n )\\n\\tprint ( cuts )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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 [ ] ; Initialize index of first repeating element ; Creates an empty hashset ; Traverse the input array from right to left ; If element is already in hash set , update min ; Else add element to hash set ; Print the result ; 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 min = -1 ; set < int > myset ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( myset . find ( arr [ i ] ) != myset . end ( ) ) min = i ; else myset . insert ( arr [ i ] ) ; } if ( min != -1 ) cout << \\\" The ▁ first ▁ repeating ▁ element ▁ is ▁ \\\" << arr [ min ] ; else cout << \\\" There ▁ are ▁ no ▁ repeating ▁ elements \\\" ; } 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\":\"\\\"Count numbers in range 1 to N which are divisible by X but not by Y | Function to count total numbers divisible by x but not y in range 1 to N ; Check if Number is divisible by x but not Y if yes , Increment count ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function countNumbers ( $ X , $ Y , $ N ) { $ count = 0 ; for ( $ i = 1 ; $ i <= $ N ; $ i ++ ) { if ( ( $ i % $ X == 0 ) && ( $ i % $ Y != 0 ) ) $ count ++ ; } return $ count ; } $ X = 2 ; $ Y = 3 ; $ N = 10 ; echo ( countNumbers ( $ X , $ Y , $ N ) ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Rank of all elements in an array | Java Code to find rank of elements ; Function to print m Maximum elements ; Rank Vector ; Sweep through all elements in A for each element count the number of less than and equal elements separately in r and s ; Use formula to obtain rank ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"public class GfG { public static void rankify ( int A [ ] , int n ) { float R [ ] = new float [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int r = 1 , s = 1 ; for ( int j = 0 ; j < n ; j ++ ) { if ( j != i && A [ j ] < A [ i ] ) r += 1 ; if ( j != i && A [ j ] == A [ i ] ) s += 1 ; } R [ i ] = r + ( float ) ( s - 1 ) \\/ ( float ) 2 ; } for ( int i = 0 ; i < n ; i ++ ) System . out . print ( R [ i ] + \\\" ▁ \\\" ) ; } public static void main ( String args [ ] ) { int A [ ] = { 1 , 2 , 5 , 2 , 1 , 25 , 2 } ; int n = A . length ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( A [ i ] + \\\" ▁ \\\" ) ; System . out . println ( ) ; rankify ( A , n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Compress a Binary Tree from top to bottom with overlapping condition | Structure of a node of th tree ; Function to compress all the nodes on the same vertical line ; Stores node by compressing all nodes on the current vertical line ; Check if i - th bit of current bit set or not ; Iterate over the range [ 0 , 31 ] ; Stores count of set bits at i - th positions ; Stores count of clear bits at i - th positions ; Traverse the array ; If i - th bit of current element is set ; Update S ; Update NS ; If count of set bits at i - th position is greater than count of clear bits ; Update ans ; Update getBit ; Function to compress all the nodes on the same vertical line with a single node that satisfies the condition ; Map all the nodes on the same vertical line ; Function to traverse the tree and map all the nodes of same vertical line to vertical distance ; Storing the values in the map ; Recursive calls on left and right subtree ; Getting the range of horizontal distances ; Driver Code ; Function Call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"class TreeNode :\\n\\tdef __init__ ( self , val = ' ' , left = None , right = None ) :\\n\\t\\tself . val = val\\n\\t\\tself . left = left\\n\\t\\tself . right = right\\ndef evalComp ( arr ) :\\n\\tans = 0\\n\\tgetBit = 1\\n\\tfor i in range ( 32 ) :\\n\\t\\tS = 0\\n\\t\\tNS = 0\\n\\t\\tfor j in arr :\\n\\t\\t\\tif getBit & j :\\n\\t\\t\\t\\tS += 1\\n\\t\\t\\telse :\\n\\t\\t\\t\\tNS += 1\\n\\t\\tif S > NS :\\n\\t\\t\\tans += 2 ** i\\n\\t\\tgetBit <<= 1\\n\\tprint ( ans , end = \\\" ▁ \\\" )\\ndef compressTree ( root ) :\\n\\tmp = { }\\n\\tdef Trav ( root , hd ) :\\n\\t\\tif not root :\\n\\t\\t\\treturn\\n\\t\\tif hd not in mp :\\n\\t\\t\\tmp [ hd ] = [ root . val ]\\n\\t\\telse :\\n\\t\\t\\tmp [ hd ] . append ( root . val )\\n\\t\\tTrav ( root . left , hd - 1 )\\n\\t\\tTrav ( root . right , hd + 1 )\\n\\tTrav ( root , 0 )\\n\\tlower = min ( mp . keys ( ) )\\n\\tupper = max ( mp . keys ( ) )\\n\\tfor i in range ( lower , upper + 1 ) :\\n\\t\\tevalComp ( mp [ i ] )\\nif __name__ == ' _ _ main _ _ ' :\\n\\troot = TreeNode ( 5 )\\n\\troot . left = TreeNode ( 3 )\\n\\troot . right = TreeNode ( 2 )\\n\\troot . left . left = TreeNode ( 1 )\\n\\troot . left . right = TreeNode ( 4 )\\n\\troot . right . left = TreeNode ( 1 )\\n\\troot . right . right = TreeNode ( 2 )\\n\\tcompressTree ( root )\",\"language\":\"python\",\"split\":\"train\",\"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\\\"\\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 ▁ Number ▁ of ▁ A ' s ▁ with ▁ % d ▁ keystrokes ▁ is ▁ % d \\n \\\" , N , findoptimal ( N ) ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of deletions so that no two consecutive are same | Function for counting deletions ; If two consecutive characters are the same , delete one of them . ; Driver code ; Function call to prvar answer\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function countDeletions ( s ) { var ans = 0 ; var str = s ; for ( var i = 0 ; i < str . length - 1 ; i ++ ) if ( str [ i ] == str [ i + 1 ] ) ans ++ ; return ans ; } var str = \\\" \\\" ; document . write ( countDeletions ( str ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all leaf nodes of binary tree | Java program to find sum of all leaf nodes of binary tree ; user define class node ; constructor ; utility function which calculates sum of all leaf nodes ; add root data to sum if root is a leaf node ; propagate recursively in left and right subtree ; driver program ; construct binary tree ; variable to store sum of leaf nodes\\\"\\nSolution in Java:\",\"targets\":\"public class GFG { static class Node { int data ; Node left , right ; Node ( int data ) { this . data = data ; left = null ; right = null ; } } static int sum ; static void leafSum ( Node root ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) sum += root . data ; leafSum ( root . left ) ; leafSum ( root . right ) ; } public static void main ( String args [ ] ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right = new Node ( 3 ) ; root . right . right = new Node ( 7 ) ; root . right . left = new Node ( 6 ) ; root . right . left . right = new Node ( 8 ) ; sum = 0 ; leafSum ( root ) ; System . out . println ( sum ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"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 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\\\"\\nHow can the above be solved 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 ▁ after ▁ segregation ▁ is ▁ \\\" ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo ( $ arr [ $ i ] . \\\" ▁ \\\" ) ; } $ arr = array ( 0 , 1 , 0 , 1 , 1 , 1 ) ; $ n = sizeof ( $ arr ) ; segregate0and1 ( $ arr , $ n ) ; toprint ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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 != ' ▁ ' ) ) { word_begin = temp ; } if ( word_begin && ( ( * ( temp + 1 ) == ' ▁ ' ) || ( * ( 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\":\"\\\"Minimum steps to reduce N to 0 by given operations | C # program for the above approach ; Function to find the minimum number to steps to reduce N to 0 ; Base case ; Recursive call to count the minimum steps needed ; Return the answer ; Driver Code ; Given number N ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int minDays ( int n ) { if ( n < 1 ) return n ; int cnt = 1 + Math . Min ( n % 2 + minDays ( n \\/ 2 ) , n % 3 + minDays ( n \\/ 3 ) ) ; return cnt ; } public static void Main ( String [ ] args ) { int N = 6 ; Console . Write ( minDays ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Partition problem | DP | A recursive C ++ program for partition problem ; A utility function that returns true if there is a subset of arr [ ] with sun 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 ; Returns true if arr [ ] can be partitioned in two subsets of equal sum , otherwise false ; Calculate sum of the elements in array ; If sum is odd , there cannot be two subsets with equal sum ; Find if there is subset with sum equal to half of total sum ; Driver code ; Function call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool isSubsetSum ( int arr [ ] , int n , int sum ) { if ( sum == 0 ) return true ; if ( n == 0 && sum != 0 ) return false ; if ( arr [ n - 1 ] > sum ) return isSubsetSum ( arr , n - 1 , sum ) ; return isSubsetSum ( arr , n - 1 , sum ) || isSubsetSum ( arr , n - 1 , sum - arr [ n - 1 ] ) ; } bool findPartiion ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; return isSubsetSum ( arr , n , sum \\/ 2 ) ; } int main ( ) { int arr [ ] = { 3 , 1 , 5 , 9 , 12 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; if ( findPartiion ( arr , n ) == true ) cout << \\\" Can ▁ be ▁ divided ▁ into ▁ two ▁ subsets ▁ \\\" \\\" of ▁ equal ▁ sum \\\" ; else cout << \\\" Can ▁ not ▁ be ▁ divided ▁ into ▁ two ▁ subsets \\\" \\\" ▁ of ▁ equal ▁ sum \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Write a program to calculate pow ( x , n ) | ; Function to calculate x raised to the power y ; Program to test function power\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint power ( int x , unsigned int y ) { if ( y == 0 ) return 1 ; else if ( y % 2 == 0 ) return power ( x , y \\/ 2 ) * power ( x , y \\/ 2 ) ; else return x * power ( x , y \\/ 2 ) * power ( x , y \\/ 2 ) ; } int main ( ) { int x = 2 ; unsigned int y = 3 ; printf ( \\\" % d \\\" , power ( x , y ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count triplets with sum smaller than a given value | C ++ program to count triplets with sum smaller than a given value ; Sort input array ; Initialize result ; Every iteration of loop counts triplet with first element as arr [ i ] . ; Initialize other two elements as corner elements of subarray arr [ j + 1. . k ] ; Use Meet in the Middle concept ; If sum of current triplet is more or equal , move right corner to look for smaller values ; Else move left corner ; This is important . For current i and j , there can be total k - j third elements . ; Driver program\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int countTriplets ( int arr [ ] , int n , int sum ) { sort ( arr , arr + n ) ; int ans = 0 ; for ( int i = 0 ; i < n - 2 ; i ++ ) { int j = i + 1 , k = n - 1 ; while ( j < k ) { if ( arr [ i ] + arr [ j ] + arr [ k ] >= sum ) k -- ; else { ans += ( k - j ) ; j ++ ; } } } return ans ; } int main ( ) { int arr [ ] = { 5 , 1 , 3 , 4 , 7 } ; int n = sizeof arr \\/ sizeof arr [ 0 ] ; int sum = 12 ; cout << countTriplets ( arr , n , sum ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count Odd and Even numbers in a range from L to R | C # implementation of the above approach ; Return the number of odd numbers in the range [ L , R ] ; if either R or L is odd ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int countOdd ( int L , int R ) { int N = ( R - L ) \\/ 2 ; if ( R % 2 != 0 L % 2 != 0 ) N ++ ; return N ; } public static void Main ( ) { int L = 3 , R = 7 ; int odds = countOdd ( L , R ) ; int evens = ( R - L + 1 ) - odds ; Console . WriteLine ( \\\" Count ▁ of ▁ odd ▁ numbers ▁ is ▁ \\\" + odds ) ; Console . WriteLine ( \\\" Count ▁ of ▁ even ▁ numbers ▁ is ▁ \\\" + evens ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimize K whose XOR with given array elements leaves array unchanged | C # program for the above approach ; Function to find the minimum value of K in given range ; Declare a set ; Initialize count variable ; Iterate in range [ 1 , 1024 ] ; counter set as 0 ; Iterating through the Set ; Check if the XOR calculated is present in the Set ; If the value of Bitwise XOR inside the given set then increment count ; Check if the value of count is equal to the size of set ; Return minimum value of K ; If no such K is found ; Driver code ; Given array ; Function call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int min_value ( int [ ] arr , int N ) { int X , K ; HashSet < int > S = new HashSet < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { S . Add ( arr [ i ] ) ; } int count = 0 ; for ( int i = 1 ; i <= 1024 ; i ++ ) { count = 0 ; foreach ( int it in S ) { X = ( ( i it ) - ( i & it ) ) ; if ( S . Contains ( X ) ) { count ++ ; } } if ( count == S . Count ) { K = i ; return K ; } } return - 1 ; } static void Main ( ) { int [ ] arr = { 1 , 0 , 3 , 3 , 0 , 2 } ; int N = arr . Length ; Console . Write ( min_value ( arr , N ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find all sides of a right angled triangle from given hypotenuse and area | Set 1 | limit for float comparison ; Utility method to get area of right angle triangle , given base and hypotenuse ; Prints base and height of triangle using hypotenuse and area information ; maximum area will be obtained when base and height are equal ( = sqrt ( h * h \\/ 2 ) ) ; if given area itself is larger than maxArea then no solution is possible ; binary search for base ; get height by pythagorean rule ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"let eps = 1e-6 ; function getArea ( base , hypotenuse ) { let height = Math . sqrt ( hypotenuse * hypotenuse - base * base ) ; return 0.5 * base * height ; } function printRightAngleTriangle ( hypotenuse , area ) { let hsquare = hypotenuse * hypotenuse ; let sideForMaxArea = Math . sqrt ( hsquare \\/ 2.0 ) ; let maxArea = getArea ( sideForMaxArea , hypotenuse ) ; if ( area > maxArea ) { document . write ( \\\" \\\" ) ; return ; } let low = 0.0 ; let high = sideForMaxArea ; let base = 0 ; while ( Math . abs ( high - low ) > eps ) { base = ( low + high ) \\/ 2.0 ; if ( getArea ( base , hypotenuse ) >= area ) { high = base ; } else { low = base ; } } let height = Math . sqrt ( hsquare - base * base ) ; document . write ( Math . round ( base ) + \\\" \\\" + Math . round ( height ) ) ; } let hypotenuse = 5 ; let area = 6 ; printRightAngleTriangle ( hypotenuse , area ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count the triplets such that A [ i ] < B [ j ] < C [ k ] | Function to return the count of elements in arr [ ] which are less than the given key ; Modified binary search ; Function to return the count of elements in arr [ ] which are greater than the given key ; Modified binary search ; Function to return the count of the required triplets ; Sort all three arrays ; Iterate for all the elements of array B ; Count of elements in A [ ] which are less than the chosen element from B [ ] ; Count of elements in C [ ] which are greater than the chosen element from B [ ] ; Update the count ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function countLessThan ( & $ arr , $ n , $ key ) { $ l = 0 ; $ r = $ n - 1 ; $ index = -1 ; while ( $ l <= $ r ) { $ m = intval ( ( $ l + $ r ) \\/ 2 ) ; if ( $ arr [ $ m ] < $ key ) { $ l = $ m + 1 ; $ index = $ m ; } else { $ r = $ m - 1 ; } } return ( $ index + 1 ) ; } function countGreaterThan ( & $ arr , $ n , $ key ) { $ l = 0 ; $ r = $ n - 1 ; $ index = -1 ; while ( $ l <= $ r ) { $ m = intval ( ( $ l + $ r ) \\/ 2 ) ; if ( $ arr [ $ m ] <= $ key ) { $ l = $ m + 1 ; } else { $ r = $ m - 1 ; $ index = $ m ; } } if ( $ index == -1 ) return 0 ; return ( $ n - $ index ) ; } function countTriplets ( $ n , & $ a , & $ b , & $ c ) { sort ( $ a ) ; sort ( $ b ) ; sort ( $ c ) ; $ count = 0 ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { $ current = $ b [ $ i ] ; $ a_index = -1 ; $ c_index = -1 ; $ low = countLessThan ( $ a , $ n , $ current ) ; $ high = countGreaterThan ( $ c , $ n , $ current ) ; $ count += ( $ low * $ high ) ; } return $ count ; } $ a = array ( 1 , 5 ) ; $ b = array ( 2 , 4 ) ; $ c = array ( 3 , 6 ) ; $ size = sizeof ( $ a ) ; echo countTriplets ( $ size , $ a , $ b , $ c ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximum sum from three arrays such that picking elements consecutively from same is not allowed | JavaScript 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\\\"\\nHow can the above be solved in JS?\",\"targets\":\"var N = 3 ; function FindMaximumSum ( ind , kon , a , b , c , n , dp ) { if ( ind == n ) return 0 ; if ( dp [ ind ] [ kon ] != - 1 ) return dp [ ind ] [ kon ] ; var ans = - 1000000005 ; if ( kon == 0 ) { ans = Math . max ( ans , b [ ind ] + FindMaximumSum ( ind + 1 , 1 , a , b , c , n , dp ) ) ; ans = Math . max ( ans , c [ ind ] + FindMaximumSum ( ind + 1 , 2 , a , b , c , n , dp ) ) ; } else if ( kon == 1 ) { ans = Math . max ( ans , a [ ind ] + FindMaximumSum ( ind + 1 , 0 , a , b , c , n , dp ) ) ; ans = Math . max ( ans , c [ ind ] + FindMaximumSum ( ind + 1 , 2 , a , b , c , n , dp ) ) ; } else if ( kon == 2 ) { ans = Math . max ( ans , a [ ind ] + FindMaximumSum ( ind + 1 , 1 , a , b , c , n , dp ) ) ; ans = Math . max ( ans , b [ ind ] + FindMaximumSum ( ind + 1 , 0 , a , b , c , n , dp ) ) ; } return dp [ ind ] [ kon ] = ans ; } var a = [ 6 , 8 , 2 , 7 , 4 , 2 , 7 ] ; var b = [ 7 , 8 , 5 , 8 , 6 , 3 , 5 ] ; var c = [ 8 , 3 , 2 , 6 , 8 , 4 , 1 ] ; var n = a . length ; var dp = Array . from ( Array ( n ) , ( ) => Array ( n ) . fill ( - 1 ) ) ; var x = FindMaximumSum ( 0 , 0 , a , b , c , n , dp ) ; var y = FindMaximumSum ( 0 , 1 , a , b , c , n , dp ) ; var z = FindMaximumSum ( 0 , 2 , a , b , c , n , dp ) ; document . write ( Math . max ( x , Math . max ( y , z ) ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find Selling Price from given Profit Percentage and Cost | C # implementation of above approach ; calculate Nth term of series ; Decimal Equivalent of Profit Percentage ; Find the Selling Price ; return the calculated Selling Price ; Driver Code ; Get the CP Profit % ; Printing the returned value\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static float SellingPrice ( float CP , float PP ) { float P_decimal = 1 + ( PP \\/ 100 ) ; float res = P_decimal * CP ; return res ; } public static void Main ( ) { float C = 720 , P = 13 ; Console . Write ( SellingPrice ( C , P ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Smallest N digit number divisible by all possible prime digits | C # implementation of the above approach ; Function to find the minimum number of n digits divisible by all prime digits ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void minNum ( int n ) { if ( n < 3 ) Console . WriteLine ( - 1 ) ; else Console . WriteLine ( 210 * ( ( int ) ( Math . Pow ( 10 , n - 1 ) \\/ 210 ) + 1 ) ) ; } public static void Main ( String [ ] args ) { int n = 5 ; minNum ( n ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Fibonacci Cube Graph | function to find fibonacci number ; function for finding number of vertices in fibonacci cube graph ; return fibonacci number for f ( n + 2 ) ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function fib ( $ n ) { if ( $ n <= 1 ) return $ n ; return fib ( $ n - 1 ) + fib ( $ n - 2 ) ; } function findVertices ( $ n ) { return fib ( $ n + 2 ) ; } $ n = 3 ; echo findVertices ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find number of subarrays with even sum | C # program to count number of sub - arrays with even sum using an efficient algorithm Time Complexity - O ( N ) Space Complexity - O ( 1 ) ; result may be large enough not to fit in int ; ; to keep track of subarrays with even sum starting from index i ; if a [ i ] is odd then all subarrays starting from index i + 1 which was odd becomeseven when a [ i ] gets added to it . ; if a [ i ] is even then all subarrays starting from index i + 1 which was even remainseven and one extra a [ i ] even subarray gets added to it . ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GFG { public static long countEvenSum ( int [ ] a , int n ) { long res = 0 ; int s = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( a [ i ] % 2 == 1 ) { s = n - i - 1 - s ; } else { s = s + 1 ; } res = res + s ; } return res ; } static public void Main ( ) { int [ ] arr = { 1 , 2 , 2 , 3 , 4 , 1 } ; int n = arr . Length ; Console . WriteLine ( \\\" The ▁ Number ▁ of ▁ Subarrays \\\" + \\\" ▁ with ▁ even ▁ sum ▁ is ▁ \\\" + countEvenSum ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"How to print maximum number of A 's using given four keys | A Dynamic Programming based C program to find maximum number of A 's that can be printed using 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 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 screen [ N ] ; int b ; int 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 -- ) { int curr = ( n - b - 1 ) * screen [ b - 1 ] ; if ( curr > screen [ n - 1 ] ) screen [ n - 1 ] = curr ; } } return screen [ N - 1 ] ; } int main ( ) { int N ; for ( N = 1 ; N <= 20 ; N ++ ) printf ( \\\" Maximum ▁ Number ▁ of ▁ A ' s ▁ with ▁ % d ▁ keystrokes ▁ is ▁ % d \\n \\\" , N , findoptimal ( N ) ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Print squares of first n natural numbers without using * , \\/ and | PHP program to print squares of first ' n ' natural numbers wothout using * , \\/ and - ; Initialize ' square ' and first odd number ; Calculate and print squares ; Print square ; Update ' square ' and ' odd ' ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function printSquares ( $ n ) { $ square = 0 ; $ odd = 1 ; for ( $ x = 0 ; $ x < $ n ; $ x ++ ) { echo $ square , \\\" \\\" ; $ square = $ square + $ odd ; $ odd = $ odd + 2 ; } } $ n = 5 ; printSquares ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Calculate depth of a full Binary tree from Preorder | function to return max of left subtree height or right subtree height ; calc height of left subtree ( In preorder left subtree is processed before right ) ; calc height of right subtree ; Wrapper over findDepthRec ( ) ; Driver program\\\"\\nSolution in Javascript:\",\"targets\":\"function findDepthRec ( tree , n , index ) { if ( index >= n tree [ index ] == ' ' ) return 0 ; index ++ ; let left = findDepthRec ( tree , n , index ) ; index ++ ; let right = findDepthRec ( tree , n , index ) ; return Math . max ( left , right ) + 1 ; } function findDepth ( tree , n ) { let index = 0 ; return ( findDepthRec ( tree , n , index ) ) ; } let tree = \\\" \\\" . split ( ' ' ) ; let n = tree . length ; document . write ( findDepth ( tree , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Compare two strings considering only alphanumeric characters | 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 C++?\",\"targets\":\"#include \\nusing namespace std ; bool CompareAlphanumeric ( string & str1 , string & str2 ) { int i , j ; i = 0 ; j = 0 ; int len1 = str1 . size ( ) ; int len2 = str2 . size ( ) ; 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 ; } void CompareAlphanumericUtil ( string str1 , string str2 ) { bool res ; res = CompareAlphanumeric ( str1 , str2 ) ; if ( res == true ) cout << \\\" Equal \\\" << endl ; else cout << \\\" Unequal \\\" << endl ; } int main ( ) { string str1 , str2 ; str1 = \\\" Ram , ▁ Shyam \\\" ; str2 = \\\" ▁ Ram ▁ - ▁ Shyam . \\\" ; CompareAlphanumericUtil ( str1 , str2 ) ; str1 = \\\" abc123\\\" ; str2 = \\\"123abc \\\" ; CompareAlphanumericUtil ( str1 , str2 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"Count number of squares in a rectangle | C program to count squares in a rectangle of size m x n ; Returns count of all squares in a rectangle of size m x n ; If n is smaller , swap m and n ; Now n is greater dimension , apply formula ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint countSquares ( int m , int n ) { int temp ; if ( n < m ) { temp = n ; n = m ; m = temp ; } return m * ( m + 1 ) * ( 2 * m + 1 ) \\/ 6 + ( n - m ) * m * ( m + 1 ) \\/ 2 ; } int main ( ) { int m = 4 , n = 3 ; printf ( \\\" Count ▁ of ▁ squares ▁ is ▁ % d \\\" , countSquares ( m , n ) ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-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\\\"\\nHow can the above be solved 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\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count all possible paths from top left to bottom right of a mXn matrix | Returns count of possible paths to reach cell at row number m and column number n from the topmost leftmost cell ( cell at 1 , 1 ) ; Create a 1D array to store results of subproblems ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int numberOfPaths ( int m , int n ) { int dp [ n ] = { 1 } ; dp [ 0 ] = 1 ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 1 ; j < n ; j ++ ) { dp [ j ] += dp [ j - 1 ] ; } } return dp [ n - 1 ] ; } int main ( ) { cout << numberOfPaths ( 3 , 3 ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Alternating Numbers | Java program for the above approach ; Function to check if a string is of the form even odd even odd ... ; Function to check if a string is of the form odd even odd even ... ; Function to check if n is an alternating number ; Driver Code ; Given number N ; Function call\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static boolean isEvenOddForm ( String s ) { int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 && s . charAt ( i ) % 2 != 0 ) return false ; if ( i % 2 == 1 && s . charAt ( i ) % 2 != 1 ) return false ; } return true ; } static boolean isOddEvenForm ( String s ) { int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 && s . charAt ( i ) % 2 != 1 ) return false ; if ( i % 2 == 1 && s . charAt ( i ) % 2 != 0 ) return false ; } return true ; } static boolean isAlternating ( int n ) { String str = Integer . toString ( n ) ; return ( isEvenOddForm ( str ) || isOddEvenForm ( str ) ) ; } public static void main ( String [ ] args ) { int N = 129 ; if ( isAlternating ( 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\":\"\\\"Print prime factors of a given integer in decreasing order using Stack | C # program for the above approach ; Function to print prime factors of N in decreasing order ; Stores prime factors of N in decreasing order ; Insert i into stack ; Update N ; Update i ; Print value of stack st ; Driver Code ; Function Call\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void PrimeFactors ( int N ) { Stack < int > st = new Stack < int > ( ) ; int i = 2 ; while ( N != 1 ) { if ( N % i == 0 ) { st . Push ( i ) ; while ( N % i == 0 ) { N = N \\/ i ; } } i ++ ; } while ( st . Count != 0 ) { Console . Write ( st . Peek ( ) ) ; st . Pop ( ) ; } } public static void Main ( ) { int N = 8 ; PrimeFactors ( N ) ; ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Number of substrings with count of each character as k |\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\n#include \\nint min ( int a , int b ) { return a < b ? a : b ; } bool have_same_frequency ( int freq [ ] , int k ) { for ( int i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] != 0 && freq [ i ] != k ) { return false ; } } return true ; } int count_substrings ( char * s , int n , int k ) { int count = 0 ; int distinct = 0 ; bool have [ 26 ] = { false } ; for ( int i = 0 ; i < n ; i ++ ) { have [ s [ i ] - ' a ' ] = true ; } for ( int i = 0 ; i < 26 ; i ++ ) { if ( have [ i ] ) { distinct ++ ; } } for ( int length = 1 ; length <= distinct ; length ++ ) { int window_length = length * k ; int freq [ 26 ] = { 0 } ; int window_start = 0 ; int window_end = window_start + window_length - 1 ; for ( int i = window_start ; i <= min ( window_end , n - 1 ) ; i ++ ) { freq [ s [ i ] - ' a ' ] ++ ; } while ( window_end < n ) { if ( have_same_frequency ( freq , k ) ) { count ++ ; } freq [ s [ window_start ] - ' a ' ] -- ; window_start ++ ; window_end ++ ; if ( window_end < n ) { freq [ s [ window_end ] - ' a ' ] ++ ; } } } return count ; } int main ( ) { char * s = \\\" aabbcc \\\" ; int k = 2 ; printf ( \\\" % d \\n \\\" , count_substrings ( s , 6 , k ) ) ; s = \\\" aabbc \\\" ; k = 2 ; printf ( \\\" % d \\n \\\" , count_substrings ( s , 5 , k ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count paths with distance equal to Manhattan distance | Function to return the value of nCk ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] \\/ [ k * ( k - 1 ) * -- - * 1 ] ; Function to return the number of paths ; Difference between the ' x ' coordinates of the given points ; Difference between the ' y ' coordinates of the given points ; 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 ; } function countPaths ( $ x1 , $ y1 , $ x2 , $ y2 ) { $ m = abs ( $ x1 - $ x2 ) ; $ n = abs ( $ y1 - $ y2 ) ; return ( binomialCoeff ( $ m + $ n , $ n ) ) ; } { $ x1 = 2 ; $ y1 = 3 ; $ x2 = 4 ; $ y2 = 5 ; echo ( countPaths ( $ x1 , $ y1 , $ x2 , $ y2 ) ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum product of maximum and minimum element over all possible subarrays | Function to find the minimum product of the minimum and maximum among all the possible subarrays ; Stores resultant minimum product ; Traverse the given array arr [ ] ; Min of product of all two pair of consecutive elements ; Return the resultant value ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def findMinMax ( a ) :\\n\\tmin_val = 1000000000\\n\\tfor i in range ( 1 , len ( a ) ) :\\n\\t\\tmin_val = min ( min_val , a [ i ] * a [ i - 1 ] )\\n\\treturn min_val\\nif __name__ == ( \\\" _ _ main _ _ \\\" ) :\\n\\tarr = [ 6 , 4 , 5 , 6 , 2 , 4 , 1 ]\\n\\tprint ( findMinMax ( arr ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if the first and last digit of the smallest number forms a prime | function to check prime ; Function to generate smallest possible number with given digits ; Declare a hash array of size 10 and initialize all the elements to zero ; store the number of occurrences of the digits in the given array into the hash table ; Traverse the hash in ascending order to print the required number ; Print the number of times a digits occurs ; extracting the first digit ; extracting the last digit ; printing the prime combinations ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function isPrime ( $ n ) { $ c = 0 ; for ( $ i = 1 ; $ i < $ n \\/ 2 ; $ i ++ ) { if ( $ n % $ i == 0 ) $ c ++ ; } if ( $ c == 1 ) return 1 ; else return 0 ; } function findMinNum ( $ arr , $ n ) { $ first = 0 ; $ last = 0 ; $ num ; $ rev ; $ i ; $ hash = array_fill ( 0 , 20 , 0 ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ hash [ $ arr [ $ i ] ] ++ ; } echo \\\" Minimum ▁ number : ▁ \\\" ; for ( $ i = 0 ; $ i <= 9 ; $ i ++ ) { for ( $ j = 0 ; $ j < $ hash [ $ i ] ; $ j ++ ) echo $ i ; } for ( $ i = 0 ; $ i <= 9 ; $ i ++ ) { if ( $ hash [ $ i ] != 0 ) { $ first = $ i ; break ; } } for ( $ i = 9 ; $ i >= 0 ; $ i -- ) { if ( $ hash [ $ i ] != 0 ) { $ last = $ i ; break ; } } $ num = $ first * 10 + $ last ; $ rev = $ last * 10 + $ first ; echo \\\" Prime combinations : \\\" if ( isPrime ( $ num ) && isPrime ( $ rev ) ) echo $ num . \\\" ▁ \\\" . $ rev ; else if ( isPrime ( $ num ) ) echo $ num ; else if ( isPrime ( $ rev ) ) echo $ rev ; else echo \\\" No ▁ combinations ▁ exist \\\" ; } $ arr = array ( 1 , 2 , 4 , 7 , 8 ) ; findMinNum ( $ arr , 5 ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"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\\\"\\nSolution 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 ▁ obtained ▁ value ▁ is ▁ % d ▁ \\n \\\" , un_kp ( price , length , n , Max_len ) ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to calculate area of a rhombus whose one side and diagonal are given | Java program to calculate the area of a rhombus whose one side and one diagonal is given ; function to calculate the area of the rhombus ; Second diagonal ; area of rhombus ; return the area ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static double area ( double d1 , double a ) { double d2 = Math . sqrt ( 4 * ( a * a ) - d1 * d1 ) ; double area = 0.5 * d1 * d2 ; return area ; } public static void main ( String [ ] args ) { double d = 7.07 ; double a = 5 ; System . out . println ( area ( d , a ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find minimum possible values of A , B and C when two of the ( A + B ) , ( A + C ) and ( B + C ) are given | C # implementation of the approach ; Function to find A , B and C ; Keep minimum number in x ; Find the numbers ; Driver code ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void MinimumValue ( int x , int y ) { if ( x > y ) { int temp = x ; x = y ; y = temp ; } int a = 1 ; int b = x - 1 ; int c = y - b ; Console . WriteLine ( a + \\\" ▁ \\\" + b + \\\" ▁ \\\" + c ) ; } public static void Main ( ) { int x = 123 , y = 13 ; MinimumValue ( x , y ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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 ▁ number ▁ of ▁ groups ▁ are ▁ % 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\":\"\\\"Sum of all the prime divisors of a number | function to find prime divisors of all numbers from 1 to n ; if the number is prime ; add this prime to all it 's multiples ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function Sum ( N ) { let SumOfPrimeDivisors = new Array ( N + 1 ) ; for ( let i = 0 ; i < SumOfPrimeDivisors . length ; i ++ ) { SumOfPrimeDivisors [ i ] = 0 ; } for ( let i = 2 ; i <= N ; ++ i ) { if ( SumOfPrimeDivisors [ i ] == 0 ) { for ( let j = i ; j <= N ; j += i ) { SumOfPrimeDivisors [ j ] += i ; } } } return SumOfPrimeDivisors [ N ] ; } let N = 60 ; document . write ( \\\" \\\" + \\\" \\\" + Sum ( N ) + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimize cost to modify the Array such that even indices have even elements and vice versa | C ++ program for the above approach ; Function to find the minimum cost to modify the array according to the given criteria ; Count of wrong positioned odd and even elements ; Odd Count ; Even Count ; Swapping Cost ; Decrementing cost after swapping ; Only decrementing cost ; Return the minimum cost of the two cases ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int minimumCost ( int arr [ ] , int N , int X , int Y ) { int even_count = 0 , odd_count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] & 1 ) && ( i % 2 == 0 ) ) { odd_count ++ ; } if ( ( arr [ i ] % 2 ) == 0 && ( i & 1 ) ) { even_count ++ ; } } int cost1 = X * min ( odd_count , even_count ) ; int cost2 = Y * ( max ( odd_count , even_count ) - min ( odd_count , even_count ) ) ; int cost3 = ( odd_count + even_count ) * Y ; return min ( cost1 + cost2 , cost3 ) ; } int main ( ) { int arr [ ] = { 5 , 3 , 7 , 2 , 1 } , X = 10 , Y = 2 ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << minimumCost ( arr , N , X , Y ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count of buttons pressed in a keypad mobile | Java implementation of the approach ; Array to store how many times a button has to be pressed for typing a particular character ; Function to return the count of buttons pressed to type the given string ; Count the key presses ; Return the required count ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static final int arr [ ] = { 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 1 , 2 , 3 , 4 } ; public static int countKeyPressed ( String str , int len ) { int count = 0 ; for ( int i = 0 ; i < len ; i ++ ) count = count + arr [ str . charAt ( i ) - ' a ' ] ; return count ; } public static void main ( String [ ] args ) { String str = \\\" abcdef \\\" ; int len = str . length ( ) ; System . out . print ( countKeyPressed ( str , len ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 ▁ 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\":\"\\\"Minimum time required to cover a Binary Array | CPP implementation to find the Minimum time required to cover a Binary Array ; function to calculate the time ; Map to mark or store the binary values ; Firstly fill the boolean array with all zeroes ; Mark the 1 s ; Number of 0 s until first '1' occurs ; Maximum Number of 0 s in between 2 '1' s . ; Number of 0 s from right until first '1' occurs ; Return maximum from left and right segment ; check if count is odd ; check ifcount is even ; return the time ; driver code ; initialise N ; array initialisation\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int solve ( vector < int > arr , int n ) { int k = arr . size ( ) ; bool mp [ n + 2 ] ; for ( int i = 0 ; i <= n ; i ++ ) { mp [ i ] = 0 ; } for ( int i = 0 ; i < k ; i ++ ) { mp [ arr [ i ] ] = 1 ; } int leftSegment = arr [ 0 ] - 1 ; for ( int i = 1 ; i < k ; i ++ ) { leftSegment = max ( leftSegment , arr [ i ] - arr [ i - 1 ] - 1 ) ; } int rightSegment = n - arr [ k - 1 ] ; int maxSegment = max ( leftSegment , rightSegment ) ; int tim ; if ( maxSegment & 1 ) tim = ( maxSegment \\/ 2 ) + 1 ; else tim = maxSegment \\/ 2 ; return tim ; } int main ( ) { int N = 5 ; vector < int > arr = { 1 , 4 } ; cout << solve ( arr , N ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find four factors of N with maximum product and sum equal to N | Set | C ++ program to find four factors of N with maximum product and sum equal to N ; Function to find factors and to print those four factors ; push all the factors in the container ; number of factors ; Initial maximum ; hash - array to mark the pairs ; form all the pair sums ; if the pair sum is less than n ; push in another container ; mark the sum with the elements formed ; mark in the map that v [ i ] + v [ j ] is present ; new size of all the pair sums ; iterate for all pair sum ; the required part ; if the required part is also present in pair sum ; find the elements with which the first pair is formed ; find the elements with which the second pair is formed ; check for previous maximum ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void findfactors ( int n ) { unordered_map < int , int > mpp ; vector < int > v , v1 ; for ( int i = 1 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v . push_back ( i ) ; if ( i != ( n \\/ i ) && i != 1 ) v . push_back ( n \\/ i ) ; } } int s = v . size ( ) ; int maxi = -1 ; pair < int , int > mp1 [ n + 5 ] ; for ( int i = 0 ; i < s ; i ++ ) { for ( int j = i ; j < s ; j ++ ) { if ( v [ i ] + v [ j ] < n ) { v1 . push_back ( v [ i ] + v [ j ] ) ; mp1 [ v [ i ] + v [ j ] ] = { v [ i ] , v [ j ] } ; mpp [ v [ i ] + v [ j ] ] = 1 ; } } } s = v1 . size ( ) ; for ( int i = 0 ; i < s ; i ++ ) { int el = n - ( v1 [ i ] ) ; if ( mpp [ el ] == 1 ) { int a = mp1 [ v1 [ i ] ] . first ; int b = mp1 [ v1 [ i ] ] . second ; int c = mp1 [ n - v1 [ i ] ] . first ; int d = mp1 [ n - v1 [ i ] ] . second ; maxi = max ( a * b * c * d , maxi ) ; } } if ( maxi == -1 ) cout << \\\" Not ▁ Possible \\n \\\" ; else { cout << \\\" The ▁ maximum ▁ product ▁ is ▁ \\\" << maxi << endl ; } } int main ( ) { int n = 50 ; findfactors ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Number of values of b such that a = b + ( a ^ b ) | function to return the number of solutions ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def countSolutions ( a ) :\\n\\tcount = bin ( a ) . count ( '1' )\\n\\treturn 2 ** count\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\ta = 3\\n\\tprint ( countSolutions ( a ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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 ▁ smaller ▁ circle ▁ lies ▁ completely \\\" + \\\" ▁ inside ▁ the ▁ bigger ▁ circle ▁ with ▁ \\\" + \\\" touching ▁ each ▁ other ▁ \\\" + \\\" at ▁ a ▁ point ▁ of ▁ circumference . ▁ \\\" ) ; } else if ( distSq + r2 < r1 ) { System . out . println ( \\\" The ▁ smaller ▁ circle ▁ lies ▁ completely \\\" + \\\" ▁ inside ▁ the ▁ bigger ▁ circle ▁ without \\\" + \\\" ▁ touching ▁ each ▁ other ▁ \\\" + \\\" at ▁ a ▁ point ▁ of ▁ circumference . \\\" ) ; } else { System . out . println ( \\\" The ▁ smaller ▁ does ▁ not ▁ lies ▁ inside \\\" + \\\" ▁ the ▁ bigger ▁ circle ▁ 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\":\"\\\"Program to calculate area of a parallelogram | Javascript program for the above approach ; Function to return the area of parallelogram using sides and angle at the intersection of diagonal ; Calculate area of parallelogram ; Return the answer ; Function to return the area of parallelogram using sides and angle at the intersection of sides ; Calculate area of parallelogram ; Return the answer ; Function to return the area of parallelogram using diagonals and angle at the intersection of diagonals ; Calculate area of parallelogram ; Return the answer ; Given diagonal and angle ; Function call ; Print the area\\\"\\nSolution in Javascript:\",\"targets\":\"function toRadians ( degree ) { let pi = 3.14159265359 ; return ( degree * ( pi \\/ 180 ) ) ; } function Area_Parallelogram1 ( a , b , theta ) { let area = ( Math . abs ( Math . tan ( toRadians ( theta ) ) ) \\/ 2 ) * Math . abs ( a * a - b * b ) ; return area ; } function Area_Parallelogram2 ( a , b , gamma ) { let area = ( Math . abs ( Math . sin ( toRadians ( gamma ) ) ) ) * Math . abs ( a * b ) ; return area ; } function Area_Parallelogram3 ( d1 , d2 , theta ) { let area = ( Math . abs ( Math . sin ( toRadians ( theta ) ) ) \\/ 2 ) * Math . abs ( d1 * d2 ) ; return area ; } let d1 = 3 ; let d2 = 5 ; let theta = 90 ; let area = Area_Parallelogram3 ( d1 , d2 , theta ) ; document . write ( area ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Write a function that returns 2 for input 1 and returns 1 for 2 |\\\"\\nSolution in C:\",\"targets\":\"int invertSub ( int x ) { return ( 3 - x ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximize element at index K in an array with at most sum M and difference between adjacent elements at most 1 | Java program for the above approach ; Function to calculate the maximum possible value at index K ; Stores the sum of elements in the left and right of index K ; Stores the maximum possible value at index K ; Print the answer ; Driver Code ; Given N , K & M\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static void maxValueAtIndexK ( int N , int K , int M ) { int S1 = 0 , S2 = 0 ; S1 = K * ( K + 1 ) \\/ 2 ; S2 = ( N - K - 1 ) * ( N - K ) \\/ 2 ; int X = ( M + S1 + S2 ) \\/ N ; System . out . println ( X ) ; } public static void main ( String [ ] args ) { int N = 3 , K = 1 , M = 7 ; maxValueAtIndexK ( N , K , M ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"Kronecker Product of two matrices | C code to find the Kronecker Product of two matrices and stores it as matrix C ; rowa and cola are no of rows and columns of matrix A rowb and colb are no of rows and columns of matrix B ; Function to computes the Kronecker Product of two matrices ; i loops till rowa ; k loops till rowb ; j loops till cola ; l loops till colb ; Each element of matrix A is multiplied by whole Matrix B resp and stored as Matrix C ; Driver Code\\nHow can the above be solved in C?\",\"targets\":\"#include \\nconst int cola = 2 , rowa = 3 , colb = 3 , rowb = 2 ; void Kroneckerproduct ( int A [ ] [ cola ] , int B [ ] [ colb ] ) { int C [ rowa * rowb ] [ cola * colb ] ; for ( int i = 0 ; i < rowa ; i ++ ) { for ( int k = 0 ; k < rowb ; k ++ ) { for ( int j = 0 ; j < cola ; j ++ ) { for ( int l = 0 ; l < colb ; l ++ ) { C [ i + l + 1 ] [ j + k + 1 ] = A [ i ] [ j ] * B [ k ] [ l ] ; printf ( \\\" % d \\t \\\" , C [ i + l + 1 ] [ j + k + 1 ] ) ; } } printf ( \\\" \\n \\\" ) ; } } } int main ( ) { int A [ 3 ] [ 2 ] = { { 1 , 2 } , { 3 , 4 } , { 1 , 0 } } , B [ 2 ] [ 3 ] = { { 0 , 5 , 2 } , { 6 , 7 , 3 } } ; Kroneckerproduct ( A , B ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program to Convert Radian to Degree | Function for convertion ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function Convert ( $ radian ) { $ pi = 3.14159 ; return ( $ radian * ( 180 \\/ $ pi ) ) ; } $ radian = 5.0 ; $ degree = Convert ( $ radian ) ; echo ( $ degree ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"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 \\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 ▁ gap ▁ is ▁ : ▁ % d \\\" , solve ( arr , size ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count of repeating digits in a given Number | C ++ program for the above approach ; 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 ; Driver Code ; Given array arr [ ] ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int countRepeatingDigits ( int N ) { int res = 0 ; int cnt [ 10 ] = { 0 } ; while ( N > 0 ) { int rem = N % 10 ; cnt [ rem ] ++ ; N = N \\/ 10 ; } for ( int i = 0 ; i < 10 ; i ++ ) { if ( cnt [ i ] > 1 ) { res ++ ; } } return res ; } int main ( ) { int N = 12 ; cout << countRepeatingDigits ( N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Print all positions of a given string having count of smaller characters equal on both sides | Function to find indexes of the given string that satisfy the condition ; Stores length of given string ; Stores frequency of each character of str ; Update frequency of current character ; cntLeftFreq [ i ] Stores frequency of characters present on the left side of index i . ; Traverse the given string ; Stores count of smaller characters on left side of i . ; Stores count of smaller characters on Right side of i . ; Traverse smaller characters on left side of index i . ; Update cntLeft ; Update cntRight ; Update cntLeftFreq [ str [ i ] ] ; If count of smaller elements on both sides equal ; Print current index ; ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function printIndexes ( str ) { var N = str . length ; var cntFreq = Array ( 256 ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { cntFreq [ str [ i ] . charCodeAt ( 0 ) ] ++ ; } var cntLeftFreq = Array ( 256 ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { var cntLeft = 0 ; var cntRight = 0 ; for ( var j = str [ i ] . charCodeAt ( 0 ) - 1 ; j >= 0 ; j -- ) { cntLeft += cntLeftFreq [ j ] ; cntRight += cntFreq [ j ] - cntLeftFreq [ j ] ; } cntLeftFreq [ str [ i ] . charCodeAt ( 0 ) ] ++ ; if ( cntLeft == cntRight && cntLeft != 0 ) { document . write ( i + \\\" \\\" ) ; } } } var str = \\\" \\\" ; printIndexes ( str ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Calculate the value of 2 raised to the power of twice the binary representation of N | C ++ program to implement the above approach ; Function to find the value of power ( X , Y ) in O ( log Y ) ; Stores power ( X , Y ) ; Update X ; Base Case ; Calculate power ( X , Y ) ; If Y is an odd number ; Update res ; Update Y ; Update X ; Function to calculate ( 2 ^ ( 2 * x ) ) % ( 10 ^ 9 + 7 ) ; dp [ N ] * dp [ N ] : Stores value of ( 2 ^ ( 2 * x ) ) % ( 10 ^ 9 + 7 ) ; Base Case ; Iterate over the range [ 3 , N ] ; Stores rightmost bit of i ; Stores the value of ( i - y ) ; If x is power of 2 ; Update dp [ i ] ; Update dp [ i ] ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; #define M 1000000007\\nlong long power ( long long X , long long Y ) { long long res = 1 ; X = X % M ; if ( X == 0 ) return 0 ; while ( Y > 0 ) { if ( Y & 1 ) { res = ( res * X ) % M ; } Y = Y >> 1 ; X = ( X * X ) % M ; } return res ; } long long findValue ( long long N ) { long long dp [ N + 1 ] ; dp [ 1 ] = 2 ; dp [ 2 ] = 1024 ; for ( int i = 3 ; i <= N ; i ++ ) { int y = ( i & ( - i ) ) ; int x = i - y ; if ( x == 0 ) { dp [ i ] = power ( dp [ i \\/ 2 ] , 10 ) ; } else { dp [ i ] = ( dp [ x ] * dp [ y ] ) % M ; } } return ( dp [ N ] * dp [ N ] ) % M ; } int main ( ) { long long n = 150 ; cout << findValue ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum equlibrium sum in an array | Function to find maximum equilibrium sum . ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findMaxSum ( $ arr , $ n ) { $ res = PHP_INT_MIN ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ prefix_sum = $ arr [ $ i ] ; for ( $ j = 0 ; $ j < $ i ; $ j ++ ) $ prefix_sum += $ arr [ $ j ] ; $ suffix_sum = $ arr [ $ i ] ; for ( $ j = $ n - 1 ; $ j > $ i ; $ j -- ) $ suffix_sum += $ arr [ $ j ] ; if ( $ prefix_sum == $ suffix_sum ) $ res = max ( $ res , $ prefix_sum ) ; } return $ res ; } $ arr = array ( -2 , 5 , 3 , 1 , 2 , 6 , -4 , 2 ) ; $ n = count ( $ arr ) ; echo findMaxSum ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Print path from root to all nodes in a Complete Binary Tree | Java program to 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 ; Driver Code ; Given Node ; Print path from root to all node .\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void printPath ( Vector < Integer > res , int nThNode , int kThNode ) { if ( kThNode > nThNode ) return ; res . add ( kThNode ) ; for ( int i = 0 ; i < res . size ( ) ; i ++ ) System . out . print ( res . get ( i ) + \\\" ▁ \\\" ) ; System . out . print ( \\\"\\n\\\"); printPath ( res , nThNode , kThNode * 2 ) ; printPath ( res , nThNode , kThNode * 2 + 1 ) ; res . remove ( res . size ( ) - 1 ) ; } static void printPathToCoverAllNodeUtil ( int nThNode ) { Vector < Integer > res = new Vector < Integer > ( ) ; printPath ( res , nThNode , 1 ) ; } public static void main ( String args [ ] ) { int nThNode = 7 ; printPathToCoverAllNodeUtil ( nThNode ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum change in lanes required to cross all barriers | C # program for the above approach ; Function to find the minimum number of changes of lane required ; If there is a barrier , then add very large value ; Add the minimum value to move forword with or without crossing barrier ; Return the minimum value of dp [ 0 ] , dp [ 1 ] and dp [ 2 ] ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; public class GFG { static int minChangeInLane ( int [ ] barrier , int n ) { int [ ] dp = { 1 , 0 , 1 } ; for ( int j = 0 ; j < n ; j ++ ) { int val = barrier [ j ] ; if ( val > 0 ) { dp [ val - 1 ] = ( int ) 1e6 ; } for ( int i = 0 ; i < 3 ; i ++ ) { if ( val != i + 1 ) { dp [ i ] = Math . Min ( dp [ i ] , Math . Min ( dp [ ( i + 1 ) % 3 ] , dp [ ( i + 2 ) % 3 ] ) + 1 ) ; } } } return Math . Min ( dp [ 0 ] , Math . Min ( dp [ 1 ] , dp [ 2 ] ) ) ; } static public void Main ( ) { int [ ] barrier = { 0 , 1 , 2 , 3 , 0 } ; int N = barrier . Length ; Console . Write ( minChangeInLane ( barrier , N ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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\\nHow can the above be solved 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 ▁ gap ▁ is ▁ : ▁ % d \\\" , solve ( arr , size ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Undulating numbers | Python3 program to check whether a number is undulating or not ; Considering the definition with restriction that there should be at least 3 digits ; Check if all alternate digits are same or not . ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def isUndulating ( n ) :\\n\\tif ( len ( n ) <= 2 ) :\\n\\t\\treturn False\\n\\tfor i in range ( 2 , len ( n ) ) :\\n\\t\\tif ( n [ i - 2 ] != n [ i ] ) :\\n\\t\\t\\treturn False\\n\\treturn True\\nn = \\\"1212121\\\"\\nif ( isUndulating ( n ) ) :\\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 K '0' s can be flipped such that Binary String contains no pair of adjacent '1' s | C # program for the above approach ; Function to check if k '0' s can be flipped such that the string does not contain any pair of adjacent '1' s ; Store the count of flips ; Variable to iterate the string ; Iterate over characters of the string ; If the current character is '1' , increment i by 2 ; Otherwise , 3 cases arises ; If the current index is the starting index ; If next character is '0' ; Increment i by 1 ; If the current index is the last index ; If previous character is '0' ; For remaining characters ; If both the adjacent characters are '0' ; If cnt is at least K , print \\\" Yes \\\" ; Otherwise , print \\\" No \\\" ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void canPlace ( string s , int n , int k ) { int cnt = 0 ; int i = 0 ; while ( i < n ) { if ( s [ i ] == '1' ) { i += 2 ; } else { if ( i == 0 ) { if ( s [ i + 1 ] == '0' ) { cnt ++ ; i += 2 ; } else i ++ ; } else if ( i == n - 1 ) { if ( s [ i - 1 ] == '0' ) { cnt ++ ; i += 2 ; } else i ++ ; } else { if ( s [ i + 1 ] == '0' && s [ i - 1 ] == '0' ) { cnt ++ ; i += 2 ; } else i ++ ; } } } if ( cnt >= k ) { Console . WriteLine ( \\\" Yes \\\" ) ; } else { Console . WriteLine ( \\\" No \\\" ) ; } } public static void Main ( String [ ] args ) { string S = \\\"10001\\\" ; int K = 1 ; int N = S . Length ; canPlace ( S , N , K ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Kronecker Product of two matrices | C code to find the Kronecker Product of two matrices and stores it as matrix C ; rowa and cola are no of rows and columns of matrix A rowb and colb are no of rows and columns of matrix B ; Function to computes the Kronecker Product of two matrices ; i loops till rowa ; k loops till rowb ; j loops till cola ; l loops till colb ; Each element of matrix A is multiplied by whole Matrix B resp and stored as Matrix C ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\nconst int cola = 2 , rowa = 3 , colb = 3 , rowb = 2 ; void Kroneckerproduct ( int A [ ] [ cola ] , int B [ ] [ colb ] ) { int C [ rowa * rowb ] [ cola * colb ] ; for ( int i = 0 ; i < rowa ; i ++ ) { for ( int k = 0 ; k < rowb ; k ++ ) { for ( int j = 0 ; j < cola ; j ++ ) { for ( int l = 0 ; l < colb ; l ++ ) { C [ i + l + 1 ] [ j + k + 1 ] = A [ i ] [ j ] * B [ k ] [ l ] ; printf ( \\\" % d \\t \\\" , C [ i + l + 1 ] [ j + k + 1 ] ) ; } } printf ( \\\" \\n \\\" ) ; } } } int main ( ) { int A [ 3 ] [ 2 ] = { { 1 , 2 } , { 3 , 4 } , { 1 , 0 } } , B [ 2 ] [ 3 ] = { { 0 , 5 , 2 } , { 6 , 7 , 3 } } ; Kroneckerproduct ( A , B ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Ternary Search | Java program to illustrate the iterative approach to ternary search ; Function to perform Ternary Search ; Find the mid1 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 Java?\",\"targets\":\"class GFG { static int 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 ; } public static void main ( String args [ ] ) { 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 ) ; System . out . println ( \\\" Index ▁ of ▁ \\\" + key + \\\" ▁ is ▁ \\\" + p ) ; key = 50 ; p = ternarySearch ( l , r , key , ar ) ; System . out . println ( \\\" Index ▁ of ▁ \\\" + key + \\\" ▁ is ▁ \\\" + p ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Insertion Sort | Java program for implementation of Insertion Sort ; Function to sort 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 array of size n ; Driver method\\\"\\nSolution in Java:\",\"targets\":\"class InsertionSort { void sort ( int arr [ ] ) { int n = arr . length ; for ( int i = 1 ; i < n ; ++ i ) { int key = arr [ i ] ; int j = i - 1 ; while ( j >= 0 && arr [ j ] > key ) { arr [ j + 1 ] = arr [ j ] ; j = j - 1 ; } arr [ j + 1 ] = key ; } } static void printArray ( int arr [ ] ) { int n = arr . length ; for ( int i = 0 ; i < n ; ++ i ) System . out . print ( arr [ i ] + \\\" ▁ \\\" ) ; System . out . println ( ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 12 , 11 , 13 , 5 , 6 } ; InsertionSort ob = new InsertionSort ( ) ; ob . sort ( arr ) ; printArray ( arr ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximum equlibrium sum in an array | Function to find maximum equilibrium sum . ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function findMaxSum ( $ arr , $ n ) { $ res = PHP_INT_MIN ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ prefix_sum = $ arr [ $ i ] ; for ( $ j = 0 ; $ j < $ i ; $ j ++ ) $ prefix_sum += $ arr [ $ j ] ; $ suffix_sum = $ arr [ $ i ] ; for ( $ j = $ n - 1 ; $ j > $ i ; $ j -- ) $ suffix_sum += $ arr [ $ j ] ; if ( $ prefix_sum == $ suffix_sum ) $ res = max ( $ res , $ prefix_sum ) ; } return $ res ; } $ arr = array ( -2 , 5 , 3 , 1 , 2 , 6 , -4 , 2 ) ; $ n = count ( $ arr ) ; echo findMaxSum ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find same contacts in a list of contacts | Structure for storing contact details . ; A utility function to fill entries in adjacency matrix representation of graph ; Initialize the adjacency matrix ; Traverse through all contacts ; Add mat from i to j and vice versa , if possible . Since length of each contact field is at max some constant . ( say 30 ) so body execution of this for loop takes constant time . ; A recuesive function to perform DFS with vertex i as source ; Finds similar contacrs in an array of contacts ; vector for storing the solution ; Declare 2D adjaceny matrix for mats ; visited array to keep track of visited nodes ; Fill adjacency matrix ; Since , we made a graph with contacts as nodes with fields as links . Two nodes are linked if they represent the same person . So , total number of connected components and nodes in each component will be our answer . ; Add delimeter to separate nodes of one component from other . ; Print the solution ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"class contact :\\n\\tdef __init__ ( self , field1 , field2 , field3 ) :\\n\\t\\tself . field1 = field1\\n\\t\\tself . field2 = field2\\n\\t\\tself . field3 = field3\\ndef buildGraph ( arr , n , mat ) :\\n\\tfor i in range ( n ) :\\n\\t\\tfor j in range ( n ) :\\n\\t\\t\\tmat [ i ] [ j ] = 0\\n\\tfor i in range ( n ) :\\n\\t\\tfor j in range ( i + 1 , n ) :\\n\\t\\t\\tif ( arr [ i ] . field1 == arr [ j ] . field1 or arr [ i ] . field1 == arr [ j ] . field2 or arr [ i ] . field1 == arr [ j ] . field3 or arr [ i ] . field2 == arr [ j ] . field1 or arr [ i ] . field2 == arr [ j ] . field2 or arr [ i ] . field2 == arr [ j ] . field3 or arr [ i ] . field3 == arr [ j ] . field1 or arr [ i ] . field3 == arr [ j ] . field2 or arr [ i ] . field3 == arr [ j ] . field3 ) :\\n\\t\\t\\t\\tmat [ i ] [ j ] = 1\\n\\t\\t\\t\\tmat [ j ] [ i ] = 1\\n\\t\\t\\t\\tbreak\\ndef DFSvisit ( i , mat , visited , sol , n ) :\\n\\tvisited [ i ] = True\\n\\tsol . append ( i )\\n\\tfor j in range ( n ) :\\n\\t\\tif ( mat [ i ] [ j ] and not visited [ j ] ) :\\n\\t\\t\\tDFSvisit ( j , mat , visited , sol , n )\\ndef findSameContacts ( arr , n ) :\\n\\tsol = [ ]\\n\\tmat = [ [ None ] * n for i in range ( n ) ]\\n\\tvisited = [ 0 ] * n\\n\\tbuildGraph ( arr , n , mat )\\n\\tfor i in range ( n ) :\\n\\t\\tif ( not visited [ i ] ) :\\n\\t\\t\\tDFSvisit ( i , mat , visited , sol , n )\\n\\t\\t\\tsol . append ( - 1 )\\n\\tfor i in range ( len ( sol ) ) :\\n\\t\\tif ( sol [ i ] == - 1 ) :\\n\\t\\t\\tprint ( )\\n\\t\\telse :\\n\\t\\t\\tprint ( sol [ i ] , end = \\\" ▁ \\\" )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ contact ( \\\" Gaurav \\\" , \\\" gaurav @ gmail . com \\\" , \\\" gaurav @ gfgQA . com \\\" ) , contact ( \\\" Lucky \\\" , \\\" lucky @ gmail . com \\\" , \\\" + 1234567\\\" ) , contact ( \\\" gaurav123\\\" , \\\" + 5412312\\\" , \\\" gaurav123 @ skype . com \\\" ) , contact ( \\\" gaurav1993\\\" , \\\" + 5412312\\\" , \\\" gaurav @ gfgQA . com \\\" ) , contact ( \\\" raja \\\" , \\\" + 2231210\\\" , \\\" raja @ gfg . com \\\" ) , contact ( \\\" bahubali \\\" , \\\" + 878312\\\" , \\\" raja \\\" ) ]\\n\\tn = len ( arr )\\n\\tfindSameContacts ( arr , n )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Gold Mine Problem | JavaScript 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 Javascript:\",\"targets\":\"let MAX = 100 ; function getMaxGold ( gold , m , n ) { let goldTable = new Array ( m ) ; for ( let i = 0 ; i < m ; i ++ ) { goldTable [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { goldTable [ i ] [ j ] = 0 ; } } for ( let col = n - 1 ; col >= 0 ; col -- ) { for ( let row = 0 ; row < m ; row ++ ) { let right = ( col == n - 1 ) ? 0 : goldTable [ row ] [ col + 1 ] ; let right_up = ( row == 0 col == n - 1 ) ? 0 : goldTable [ row - 1 ] [ col + 1 ] ; let 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 ) ) ; } } let res = goldTable [ 0 ] [ 0 ] ; for ( let i = 1 ; i < m ; i ++ ) res = Math . max ( res , goldTable [ i ] [ 0 ] ) ; return res ; } let gold = [ [ 1 , 3 , 1 , 5 ] , [ 2 , 2 , 4 , 1 ] , [ 5 , 0 , 2 , 3 ] , [ 0 , 6 , 1 , 2 ] ] ; let m = 4 , n = 4 ; document . write ( getMaxGold ( gold , m , n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\":\"\\\"Count of indices in an array that satisfy the given condition | Function to return the count of indices that satisfy the given condition ; To store the result ; To store the current maximum Initialized to 0 since there are only positive elements in the array ; i is a valid index ; Update the maximum so far ; Increment the counter ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def countIndices ( arr , n ) :\\n\\tcnt = 0 ;\\n\\tmax = 0 ;\\n\\tfor i in range ( n ) :\\n\\t\\tif ( max < arr [ i ] ) :\\n\\t\\t\\tmax = arr [ i ] ;\\n\\t\\t\\tcnt += 1 ;\\n\\treturn cnt ;\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 1 , 2 , 3 , 4 ] ;\\n\\tn = len ( arr ) ;\\n\\tprint ( countIndices ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check whether the given floating point number is a palindrome | C ++ implementation of the approach ; Function that returns true if num is palindrome ; Convert the given floating point number into a string ; Pointers pointing to the first and the last character of the string ; Not a palindrome ; Update the pointers ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool isPalindrome ( float num ) { stringstream ss ; ss << num ; string s ; ss >> s ; int low = 0 ; int high = s . size ( ) - 1 ; while ( low < high ) { if ( s [ low ] != s [ high ] ) return false ; low ++ ; high -- ; } return true ; } int main ( ) { float n = 123.321f ; if ( isPalindrome ( n ) ) 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\":\"\\\"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\\\"\\nSolution in C#:\",\"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\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Area of a Circular Sector | PHP program to find Area of a Sector ; Calculating area of the sector ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function SectorArea ( $ radius , $ angle ) { if ( $ angle >= 360 ) echo ( \\\" Angle ▁ not ▁ possible \\\" ) ; else { $ sector = ( ( 22 * $ radius * $ radius ) \\/ 7 ) * ( $ angle \\/ 360 ) ; echo ( $ sector ) ; } } $ radius = 9 ; $ angle = 60 ; SectorArea ( $ radius , $ angle ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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 Javascript:\",\"targets\":\"function findDirection ( s ) { let count = 0 ; let d = \\\" \\\" ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( s [ 0 ] == ' ' ) return null ; if ( s [ i ] == ' ' ) count -- ; else { if ( s [ i ] == ' ' ) count ++ ; } } if ( count > 0 ) { if ( count % 4 == 0 ) d = \\\" \\\" ; else if ( count % 4 == 1 ) d = \\\" \\\" ; else if ( count % 4 == 2 ) d = \\\" \\\" ; else if ( count % 4 == 3 ) d = \\\" \\\" ; } if ( count < 0 ) { if ( count % 4 == 0 ) d = \\\" \\\" ; else if ( count % 4 == - 1 ) d = \\\" \\\" ; else if ( count % 4 == - 2 ) d = \\\" \\\" ; else if ( count % 4 == - 3 ) d = \\\" \\\" ; } return d ; } let s = \\\" \\\" ; document . write ( findDirection ( s ) + \\\" \\\" ) ; s = \\\" \\\" ; document . write ( findDirection ( s ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Make all array elements equal with minimum cost | Utility method to compute cost , when all values of array are made equal to X ; Method to find minimum cost to make all elements equal ; Setting limits for ternary search by smallest and largest element ; loop until difference between low and high become less than 3 , because after that mid1 and mid2 will start repeating ; mid1 and mid2 are representative array equal values of search space ; if mid2 point gives more total cost , skip third part ; if mid1 point gives more total cost , skip first part ; computeCost gets optimum cost by sending average of low and high as X ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def computeCost ( arr , N , X ) :\\n\\tcost = 0\\n\\tfor i in range ( N ) :\\n\\t\\tcost += abs ( arr [ i ] - X )\\n\\treturn cost\\ndef minCostToMakeElementEqual ( arr , N ) :\\n\\tlow = high = arr [ 0 ]\\n\\tfor i in range ( N ) :\\n\\t\\tif ( low > arr [ i ] ) : low = arr [ i ]\\n\\t\\tif ( high < arr [ i ] ) : high = arr [ i ]\\n\\twhile ( ( high - low ) > 2 ) :\\n\\t\\tmid1 = low + ( high - low ) \\/\\/ 3\\n\\t\\tmid2 = high - ( high - low ) \\/\\/ 3\\n\\t\\tcost1 = computeCost ( arr , N , mid1 )\\n\\t\\tcost2 = computeCost ( arr , N , mid2 )\\n\\t\\tif ( cost1 < cost2 ) :\\n\\t\\t\\thigh = mid2\\n\\t\\telse :\\n\\t\\t\\tlow = mid1\\n\\treturn computeCost ( arr , N , ( low + high ) \\/\\/ 2 )\\narr = [ 1 , 100 , 101 ]\\nN = len ( arr )\\nprint ( minCostToMakeElementEqual ( arr , N ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Largest subarray with equal number of 0 s and 1 s | A simple C ++ program to find the largest subarray with equal number of 0 s and 1 s ; This function Prints the starting and ending indexes of the largest subarray with equal number of 0 s and 1 s . Also returns the size of such subarray . ; Pick a starting point as i ; Consider all subarrays starting from i ; If this is a 0 sum subarray , then compare it with maximum size subarray calculated so far ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int findSubArray ( int arr [ ] , int n ) { int sum = 0 ; int maxsize = -1 , startindex ; for ( int i = 0 ; i < n - 1 ; i ++ ) { sum = ( arr [ i ] == 0 ) ? -1 : 1 ; for ( int j = i + 1 ; j < n ; j ++ ) { ( arr [ j ] == 0 ) ? ( sum += -1 ) : ( sum += 1 ) ; if ( sum == 0 && maxsize < j - i + 1 ) { maxsize = j - i + 1 ; startindex = i ; } } } if ( maxsize == -1 ) cout << \\\" No ▁ such ▁ subarray \\\" ; else cout << startindex << \\\" ▁ to ▁ \\\" << startindex + maxsize - 1 ; return maxsize ; } int main ( ) { int arr [ ] = { 1 , 0 , 0 , 1 , 0 , 1 , 1 } ; int size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; findSubArray ( arr , size ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Print characters and their frequencies in order of occurrence | C # implementation to print the characters and frequencies in order of its occurrence ; Store all characters and their frequencies in dictionary ; Print characters and their frequencies in same order of their appearance ; Print only if this character is not printed before ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections ; using System . Collections . Generic ; class GFG { public static void prCharWithFreq ( string s ) { Dictionary < char , int > d = new Dictionary < char , int > ( ) ; foreach ( char i in s ) { if ( d . ContainsKey ( i ) ) { d [ i ] ++ ; } else { d [ i ] = 1 ; } } foreach ( char i in s ) { if ( d [ i ] != 0 ) { Console . Write ( i + d [ i ] . ToString ( ) + \\\" ▁ \\\" ) ; d [ i ] = 0 ; } } } public static void Main ( string [ ] args ) { string s = \\\" geeksforgeeks \\\" ; prCharWithFreq ( s ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find the element in the matrix generated by given rules | Java implementation of the above approach ; 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\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { static int getElement ( int N , int r , int c ) { if ( r > c ) return 0 ; if ( r == 1 ) { return c ; } int a = ( r + 1 ) * ( int ) ( Math . pow ( 2 , ( r - 2 ) ) ) ; int d = ( int ) ( Math . pow ( 2 , ( r - 1 ) ) ) ; c = c - r ; int element = a + d * c ; return element ; } public static void main ( String [ ] args ) { int N = 4 , R = 3 , C = 4 ; System . out . println ( getElement ( N , R , C ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Smallest character in a string having minimum sum of distances between consecutive repetitions | Java program for the above approach ; Function to find the character repeats with minimum distance ; Stores the first and last index ; Initialize with - 1 ; Get the values of last and first occurence ; Update the first index ; Update the last index ; Initialize min ; Get the minimum ; Values must not be same ; Update the minimum distance ; return ans ; Driver Code ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static char minDistChar ( char [ ] s ) { int n = s . length ; int [ ] first = new int [ 26 ] ; int [ ] last = new int [ 26 ] ; for ( int i = 0 ; i < 26 ; i ++ ) { first [ i ] = - 1 ; last [ i ] = - 1 ; } for ( int i = 0 ; i < n ; i ++ ) { if ( first [ s [ i ] - ' a ' ] == - 1 ) { first [ s [ i ] - ' a ' ] = i ; } last [ s [ i ] - ' a ' ] = i ; } int min = Integer . MAX_VALUE ; char ans = '1' ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( last [ i ] == first [ i ] ) continue ; if ( min > last [ i ] - first [ i ] ) { min = last [ i ] - first [ i ] ; ans = ( char ) ( i + ' a ' ) ; } } return ans ; } public static void main ( String [ ] args ) { String str = \\\" geeksforgeeks \\\" ; System . out . print ( minDistChar ( str . toCharArray ( ) ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find the minimum element in a sorted and rotated array | PHP 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 Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findMin ( $ arr , $ low , $ high ) { if ( $ high < $ low ) return $ arr [ 0 ] ; if ( $ high == $ low ) return $ arr [ $ low ] ; $ 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 ) ; } $ arr1 = array ( 5 , 6 , 1 , 2 , 3 , 4 ) ; $ n1 = sizeof ( $ arr1 ) ; echo \\\" The ▁ minimum ▁ element ▁ is ▁ \\\" . findMin ( $ arr1 , 0 , $ n1 - 1 ) . \\\" \\n \\\" ; $ arr2 = array ( 1 , 2 , 3 , 4 ) ; $ n2 = sizeof ( $ arr2 ) ; echo \\\" The ▁ minimum ▁ element ▁ is ▁ \\\" . findMin ( $ arr2 , 0 , $ n2 - 1 ) . \\\" \\n \\\" ; $ arr3 = array ( 1 ) ; $ n3 = sizeof ( $ arr3 ) ; echo \\\" The ▁ minimum ▁ element ▁ is ▁ \\\" . findMin ( $ arr3 , 0 , $ n3 - 1 ) . \\\" \\n \\\" ; $ arr4 = array ( 1 , 2 ) ; $ n4 = sizeof ( $ arr4 ) ; echo \\\" The ▁ minimum ▁ element ▁ is ▁ \\\" . findMin ( $ arr4 , 0 , $ n4 - 1 ) . \\\" \\n \\\" ; $ arr5 = array ( 2 , 1 ) ; $ n5 = sizeof ( $ arr5 ) ; echo \\\" The ▁ minimum ▁ element ▁ is ▁ \\\" . findMin ( $ arr5 , 0 , $ n5 - 1 ) . \\\" \\n \\\" ; $ arr6 = array ( 5 , 6 , 7 , 1 , 2 , 3 , 4 ) ; $ n6 = sizeof ( $ arr6 ) ; echo \\\" The ▁ minimum ▁ element ▁ is ▁ \\\" . findMin ( $ arr6 , 0 , $ n6 - 1 ) . \\\" \\n \\\" ; $ arr7 = array ( 1 , 2 , 3 , 4 , 5 , 6 , 7 ) ; $ n7 = sizeof ( $ arr7 ) ; echo \\\" The ▁ minimum ▁ element ▁ is ▁ \\\" . findMin ( $ arr7 , 0 , $ n7 - 1 ) . \\\" \\n \\\" ; $ arr8 = array ( 2 , 3 , 4 , 5 , 6 , 7 , 8 , 1 ) ; $ n8 = sizeof ( $ arr8 ) ; echo \\\" The ▁ minimum ▁ element ▁ is ▁ \\\" . findMin ( $ arr8 , 0 , $ n8 - 1 ) . \\\" \\n \\\" ; $ arr9 = array ( 3 , 4 , 5 , 1 , 2 ) ; $ n9 = sizeof ( $ arr9 ) ; echo \\\" The ▁ minimum ▁ element ▁ is ▁ \\\" . findMin ( $ arr9 , 0 , $ n9 - 1 ) . \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Write you own Power without using multiplication ( * ) and division ( \\/ ) operators | ; A recursive function to get x * y ; A recursive function to get a ^ b Works only if a >= 0 and b >= 0 ; driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\nint multiply ( int x , int y ) { if ( y ) return ( x + multiply ( x , y - 1 ) ) ; else return 0 ; } int pow ( int a , int b ) { if ( b ) return multiply ( a , pow ( a , b - 1 ) ) ; else return 1 ; } int main ( ) { printf ( \\\" % d \\\" , pow ( 5 , 3 ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find the last two missing digits of the given phone number | C ++ implementation of the approach ; 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 C++:\",\"targets\":\"#include \\nusing namespace std ; void findPhoneNumber ( int n ) { int temp = n ; int sum ; while ( temp != 0 ) { sum += temp % 10 ; temp = temp \\/ 10 ; } if ( sum < 10 ) cout << n << \\\"0\\\" << sum ; else cout << n << sum ; } int main ( ) { long int n = 98765432 ; findPhoneNumber ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find the sum of first N odd Fibonacci numbers | Python3 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\\\"\\nHow can the above be solved in Python?\",\"targets\":\"mod = 1000000007 ;\\ndef sumOddFibonacci ( n ) :\\n\\tSum = [ 0 ] * ( n + 1 ) ;\\n\\tSum [ 0 ] = 0 ;\\n\\tSum [ 1 ] = 1 ;\\n\\tSum [ 2 ] = 2 ;\\n\\tSum [ 3 ] = 5 ;\\n\\tSum [ 4 ] = 10 ;\\n\\tSum [ 5 ] = 23 ;\\n\\tfor i in range ( 6 , n + 1 ) :\\n\\t\\tSum [ 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 ;\\n\\treturn Sum [ n ] ;\\nn = 6 ;\\nprint ( sumOddFibonacci ( n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find Nth item distributed from infinite items of infinite types based on given conditions | C # code for the above approach ; 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\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GFG { static int itemType ( int n ) { int count = 0 ; for ( int day = 1 ; ; day ++ ) { for ( int type = day ; type > 0 ; type -- ) { count += type ; if ( count >= n ) return type ; } } } static public void Main ( ) { int N = 10 ; Console . WriteLine ( itemType ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximum count of values of S modulo M lying in a range [ L , R ] after performing given operations on the array | Lookup table ; Function to count the value of S after adding arr [ i ] or arr [ i - 1 ] to the sum S at each time ; Base Case ; Store the mod value ; If the mod value lies in the range then return 1 ; Else return 0 ; Store the current state ; If already computed , return the computed value ; Recursively adding the elements to the sum adding ai value ; Adding arr [ i ] - 1 value ; Return the maximum count to check for root value as well ; Avoid counting idx = 0 as possible solution we are using idx != 0 ; Return the value of current state ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"dp = { }\\ndef countMagicNumbers ( idx , sum , a , n , m , l , r ) :\\n\\tif ( idx == n ) :\\n\\t\\ttemp = sum % m\\n\\t\\tif ( temp == l or temp == r or ( temp > l and temp < r ) ) :\\n\\t\\t\\tdp [ ( idx , sum ) ] = 1\\n\\t\\t\\treturn dp [ ( idx , sum ) ]\\n\\t\\telse :\\n\\t\\t\\tdp [ ( idx , sum ) ] = 0\\n\\t\\t\\treturn dp [ ( idx , sum ) ]\\n\\tcurr = ( idx , sum )\\n\\tif ( curr in dp ) :\\n\\t\\treturn dp [ curr ]\\n\\tls = countMagicNumbers ( idx + 1 , sum + a [ idx ] , a , n , m , l , r )\\n\\trs = countMagicNumbers ( idx + 1 , sum + ( a [ idx ] - 1 ) , a , n , m , l , r )\\n\\ttemp1 = max ( ls , rs )\\n\\ttemp = sum % m\\n\\tif ( ( temp == l or temp == r or ( temp > l and temp < r ) ) and idx != 0 ) :\\n\\t\\ttemp1 += 1\\n\\tdp [ ( idx , sum ) ] = temp1\\n\\treturn dp [ ( idx , sum ) ]\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 5\\n\\tM = 22\\n\\tL = 14\\n\\tR = 16\\n\\tarr = [ 17 , 11 , 10 , 8 , 15 ]\\n\\tprint ( countMagicNumbers ( 0 , 0 , arr , N , M , L , R ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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 set1 [ i ] . Similarly con_s2 [ i ] is going to store an integer whose set bits represent presence \\/ absence of characters in 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 Python?\",\"targets\":\"def countCompletePairs ( set1 , set2 , n , m ) :\\n\\tresult = 0\\n\\tcon_s1 , con_s2 = [ 0 ] * n , [ 0 ] * m\\n\\tfor i in range ( n ) :\\n\\t\\tcon_s1 [ i ] = 0\\n\\t\\tfor j in range ( len ( set1 [ i ] ) ) :\\n\\t\\t\\tcon_s1 [ i ] = con_s1 [ i ] | ( 1 << ( ord ( set1 [ i ] [ j ] ) - ord ( ' a ' ) ) )\\n\\tfor i in range ( m ) :\\n\\t\\tcon_s2 [ i ] = 0\\n\\t\\tfor j in range ( len ( set2 [ i ] ) ) :\\n\\t\\t\\tcon_s2 [ i ] = con_s2 [ i ] | ( 1 << ( ord ( set2 [ i ] [ j ] ) - ord ( ' a ' ) ) )\\n\\tcomplete = ( 1 << 26 ) - 1\\n\\tfor i in range ( n ) :\\n\\t\\tfor j in range ( m ) :\\n\\t\\t\\tif ( ( con_s1 [ i ] con_s2 [ j ] ) == complete ) :\\n\\t\\t\\t\\tresult += 1\\n\\treturn result\\nif __name__ == ' _ _ main _ _ ' :\\n\\tset1 = [ \\\" abcdefgh \\\" , \\\" geeksforgeeks \\\" , \\\" lmnopqrst \\\" , \\\" abc \\\" ]\\n\\tset2 = [ \\\" ijklmnopqrstuvwxyz \\\" , \\\" abcdefghijklmnopqrstuvwxyz \\\" , \\\" defghijklmnopqrstuvwxyz \\\" ]\\n\\tn = len ( set1 )\\n\\tm = len ( set2 )\\n\\tprint ( countCompletePairs ( set1 , set2 , n , m ) )\",\"language\":\"python\",\"split\":\"validation\",\"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\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; #define MAX 1000000\\nbool prime [ MAX + 1 ] ; int sum [ MAX + 1 ] ; void SieveOfEratosthenes ( ) { memset ( prime , true , sizeof ( prime ) ) ; memset ( sum , 0 , sizeof ( sum ) ) ; 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 ] ; } } int main ( ) { SieveOfEratosthenes ( ) ; int l = 3 , r = 9 ; int c = ( sum [ r ] - sum [ l - 1 ] ) ; cout << \\\" Count : ▁ \\\" << c << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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\\nHow can the above be solved 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 ▁ \\\" , 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 ▁ array : ▁ \\n \\\" ) ; printArray ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Find all factors of a natural number | Set 1 | A Better ( than Naive ) Solution to find all divisiors ; method to print the divisors ; Note that this loop runs till square root ; If divisors are equal , print only one ; Otherwise print both ; Driver method\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import math\\ndef printDivisors ( n ) :\\n\\ti = 1\\n\\twhile i <= math . sqrt ( n ) :\\n\\t\\tif ( n % i == 0 ) :\\n\\t\\t\\tif ( n \\/ i == i ) :\\n\\t\\t\\t\\tprint i ,\\n\\t\\t\\telse :\\n\\t\\t\\t\\tprint i , n \\/ i ,\\n\\t\\ti = i + 1\\nprint \\\" The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ \\\"\\nprintDivisors ( 100 )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimize steps to reach K from 0 by adding 1 or doubling at each step | Function to find minimum operations ; dp is initialised to store the steps ; For all even numbers ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def minOperation ( k ) :\\n\\tdp = [ 0 ] * ( k + 1 )\\n\\tfor i in range ( 1 , k + 1 ) :\\n\\t\\tdp [ i ] = dp [ i - 1 ] + 1\\n\\t\\tif ( i % 2 == 0 ) :\\n\\t\\t\\tdp [ i ] = min ( dp [ i ] , dp [ i \\/\\/ 2 ] + 1 )\\n\\treturn dp [ k ]\\nif __name__ == ' _ _ main _ _ ' :\\n\\tk = 12\\n\\tprint ( minOperation ( k ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Position of n among the numbers made of 2 , 3 , 5 & 7 | Javascript Program position of n among the numbers made of 2 , 3 , 5 & 7 ; If number is 2 then it is on the position pos * 2 + 1 ; If number is 3 then it is on the position pos * 2 + 2 ; If number is 5 then it is on the position pos * 2 + 3 ; If number is 7 then it is on the position pos * 2 + 4 ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function findpos ( n ) { var pos = 0 ; for ( i = 0 ; i < n . length ; i ++ ) { switch ( n . charAt ( i ) ) { case ' ' : pos = pos * 4 + 1 ; break ; case ' ' : pos = pos * 4 + 2 ; break ; case ' ' : pos = pos * 4 + 3 ; break ; case ' ' : pos = pos * 4 + 4 ; break ; } } return pos ; } var n = \\\" \\\" ; document . write ( findpos ( n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Number with maximum number of prime factors | Python 3 program to find integer having maximum number of prime factor in first N natural numbers . ; 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 Python?\",\"targets\":\"from math import sqrt\\ndef maxPrimefactorNum ( N ) :\\n\\tarr = [ 0 for i in range ( N + 5 ) ]\\n\\tfor i in range ( 2 , int ( sqrt ( N ) ) + 1 , 1 ) :\\n\\t\\tif ( arr [ i ] == 0 ) :\\n\\t\\t\\tfor j in range ( 2 * i , N + 1 , i ) :\\n\\t\\t\\t\\tarr [ j ] += 1\\n\\t\\tarr [ i ] = 1\\n\\tmaxval = 0\\n\\tmaxint = 1\\n\\tfor i in range ( 1 , N + 1 , 1 ) :\\n\\t\\tif ( arr [ i ] > maxval ) :\\n\\t\\t\\tmaxval = arr [ i ]\\n\\t\\t\\tmaxint = i\\n\\treturn maxint\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 40\\n\\tprint ( maxPrimefactorNum ( N ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sort Matrix in alternating ascending and descending order rowwise | C ++ implementation to print row of matrix in ascending or descending order alternatively ; Iterate matrix rowwise ; Sort even rows in ascending order ; compare adjacent elements ; swap adjacent element ; Sort even rows in descending order ; compare adjacent elements ; swap adjacent element ; Printing the final Output ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\n#define N 4\\nvoid func ( int a [ ] [ N ] ) { for ( int i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { for ( int j = 0 ; j < N ; j ++ ) { for ( int k = j + 1 ; k < N ; ++ k ) { if ( a [ i ] [ j ] > a [ i ] [ k ] ) { int temp = a [ i ] [ j ] ; a [ i ] [ j ] = a [ i ] [ k ] ; a [ i ] [ k ] = temp ; } } } } else { for ( int j = 0 ; j < N ; j ++ ) { for ( int k = j + 1 ; k < N ; ++ k ) { if ( a [ i ] [ j ] < a [ i ] [ k ] ) { int temp = a [ i ] [ j ] ; a [ i ] [ j ] = a [ i ] [ k ] ; a [ i ] [ k ] = temp ; } } } } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { printf ( \\\" % d ▁ \\\" , a [ i ] [ j ] ) ; } printf ( \\\" \\n \\\" ) ; } } int main ( ) { int a [ N ] [ N ] = { { 5 , 7 , 3 , 4 } , { 9 , 5 , 8 , 2 } , { 6 , 3 , 8 , 1 } , { 5 , 8 , 9 , 3 } } ; func ( a ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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\\\"\\nHow can the above be solved in JS?\",\"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\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Number formed by flipping all bits to the left of rightmost set bit | JavaScript program to find the integer formed after flipping all bits to the left of the rightmost set bit ; Function to get the total count ; Moving until we get the rightmost set bit ; To get total number of bits in a number ; Function to find the integer formed after flipping all bits to the left of the rightmost set bit ; Find the total count of bits and the rightmost set bit ; XOR given number with the number which has is made up of only totbits set ; To avoid flipping the bits to the right of the set bit , take XOR with the number made up of only set firstbits ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"let totCount ; let firstCount ; function getTotCount ( num ) { totCount = 1 ; firstCount = 1 ; let temp = 1 ; while ( ( num & temp ) == 0 ) { temp = temp << 1 ; totCount += 1 ; } firstCount = totCount ; temp = num >> totCount ; while ( temp != 0 ) { totCount += 1 ; temp = temp >> 1 ; } } function flipBitsFromRightMostSetBit ( num ) { getTotCount ( num ) ; let num1 = num ^ ( ( 1 << totCount ) - 1 ) ; num1 = num1 ^ ( ( 1 << firstCount ) - 1 ) ; return num1 ; } let n = 120 ; document . write ( flipBitsFromRightMostSetBit ( n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Dynamic Programming | Java 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 ▁ know ▁ which ▁ value ▁ is ▁ ▁ full - fill ▁ our ▁ criteria ▁ ▁ that ' s why we doing two calls ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"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 ) { System . out . println ( \\\"YES\\n\\\"); } else System . out . println ( \\\"NO\\n\\\"); } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximum consecutive repeating character in string | Returns the maximum repeating character in a given string ; Traverse string except last character ; If current character matches with next ; If doesn 't match, update result (if required) and reset count ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function maxRepeating ( $ str ) { $ n = strlen ( $ str ) ; $ count = 0 ; $ res = $ str [ 0 ] ; $ cur_count = 1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ i < $ n - 1 && $ str [ $ i ] == $ str [ $ i + 1 ] ) $ cur_count ++ ; else { if ( $ cur_count > $ count ) { $ count = $ cur_count ; $ res = $ str [ $ i ] ; } $ cur_count = 1 ; } } return $ res ; } $ str = \\\" aaaabbaaccde \\\" ; echo maxRepeating ( $ str ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count trailing zero bits using lookup table | Simple Java code for counting trailing zeros in binary representation of a number ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { public static int countTrailingZero ( int x ) { int count = 0 ; while ( ( x & 1 ) == 0 ) { x = x >> 1 ; count ++ ; } return count ; } public static void main ( String [ ] args ) { System . out . println ( countTrailingZero ( 11 ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Program to find whether a given number is power of 2 | 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 0\\n\\tif ( ( n & ( ~ ( n - 1 ) ) ) == n ) :\\n\\t\\treturn 1\\n\\treturn 0\\nif ( isPowerofTwo ( 30 ) ) :\\n\\tprint ( ' Yes ' )\\nelse :\\n\\tprint ( ' No ' )\\nif ( isPowerofTwo ( 128 ) ) :\\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\":\"\\\"String obtained by reversing and complementing a Binary string K times | Function to perform K operations upon the string and find modified string ; Number of reverse operations ; Number of complement operations ; If rev is odd parity ; If complement is odd parity ; Complementing each position ; Return the modified string ; Driver Code ; Function call\\\"\\nSolution in Python:\",\"targets\":\"def ReverseComplement ( s , n , k ) :\\n\\trev = ( k + 1 ) \\/\\/ 2\\n\\tcomplement = k - rev\\n\\tif ( rev % 2 ) :\\n\\t\\ts = s [ : : - 1 ]\\n\\tif ( complement % 2 ) :\\n\\t\\tfor i in range ( n ) :\\n\\t\\t\\tif ( s [ i ] == '0' ) :\\n\\t\\t\\t\\ts [ i ] = '1'\\n\\t\\t\\telse :\\n\\t\\t\\t\\ts [ i ] = '0'\\n\\treturn s\\nif __name__ == ' _ _ main _ _ ' :\\n\\tstr1 = \\\"10011\\\"\\n\\tk = 5\\n\\tn = len ( str1 )\\n\\tprint ( ReverseComplement ( str1 , n , k ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\":\"\\\"Check if a number is divisible by 8 using bitwise operators | C ++ program to check whether the number is divisible by 8 or not using bitwise operator ; function to check number is div by 8 or not using bitwise operator ; Driver program\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int Div_by_8 ( int n ) { return ( ( ( n >> 3 ) << 3 ) == n ) ; } int main ( ) { int n = 16 ; if ( Div_by_8 ( n ) ) cout << \\\" YES \\\" << endl ; else cout << \\\" NO \\\" << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Sophie Germain Prime | CPP program to print all sophie german prime number till n . ; function to detect prime number here we have used sieve method https : www . geeksforgeeks . org \\/ sieve - of - eratosthenes \\/ to detect prime number ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; We have made array till 2 * n + 1 so that we can check prime number till that and conclude about sophie german prime . ; checking every i whether it is sophie german prime or not . ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool sieve ( int n , bool 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 ; } } } void printSophieGermanNumber ( int n ) { bool prime [ 2 * n + 1 ] ; memset ( prime , true , sizeof ( prime ) ) ; sieve ( 2 * n + 1 , prime ) ; for ( int i = 2 ; i <= n ; ++ i ) { if ( prime [ i ] && prime [ 2 * i + 1 ] ) cout << i << \\\" ▁ \\\" ; } } int main ( ) { int n = 25 ; printSophieGermanNumber ( 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\\\"\\nSolution in C#:\",\"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\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sunny Number | Java program for the above approach ; Function check whether x is a perfect square or not ; Find floating point value of square root of x . ; If square root is an integer ; Function to check Sunny Number ; Check if ( N + 1 ) is a perfect square or not ; If ( N + 1 ) is not a perfect square ; Driver code ; Given Number ; Function call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static boolean isPerfectSquare ( double x ) { double sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } static void checkSunnyNumber ( int N ) { if ( isPerfectSquare ( N + 1 ) ) { System . out . println ( \\\" Yes \\\" ) ; } else { System . out . println ( \\\" No \\\" ) ; } } public static void main ( String [ ] args ) { int N = 8 ; checkSunnyNumber ( N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Cost to Balance the parentheses | Python 3 code to calculate the minimum cost to make the given parentheses balanced ; To store absolute count of balanced and unbalanced parenthesis ; o ( open bracket ) stores count of ' ( ' and c ( close bracket ) stores count of ') ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def costToBalance ( s ) :\\n\\tif ( len ( s ) == 0 ) :\\n\\t\\tprint ( 0 )\\n\\tans = 0\\n'\\n\\to = 0\\n\\tc = 0\\n\\tfor i in range ( len ( s ) ) :\\n\\t\\tif ( s [ i ] == ' ( ' ) :\\n\\t\\t\\to += 1\\n\\t\\tif ( s [ i ] == ' ) ' ) :\\n\\t\\t\\tc += 1\\n\\tif ( o != c ) :\\n\\t\\treturn - 1\\n\\ta = [ 0 for i in range ( len ( s ) ) ]\\n\\tif ( s [ 0 ] == ' ( ' ) :\\n\\t\\ta [ 0 ] = 1\\n\\telse :\\n\\t\\ta [ 0 ] = - 1\\n\\tif ( a [ 0 ] < 0 ) :\\n\\t\\tans += abs ( a [ 0 ] )\\n\\tfor i in range ( 1 , len ( s ) ) :\\n\\t\\tif ( s [ i ] == ' ( ' ) :\\n\\t\\t\\ta [ i ] = a [ i - 1 ] + 1\\n\\t\\telse :\\n\\t\\t\\ta [ i ] = a [ i - 1 ] - 1\\n\\t\\tif ( a [ i ] < 0 ) :\\n\\t\\t\\tans += abs ( a [ i ] )\\n\\treturn ans\\nif __name__ == ' _ _ main _ _ ' : s = \\\" ) ) ) ( ( ( \\\"\\n\\tprint ( costToBalance ( s ) ) s = \\\" ) ) ( ( \\\"\\n\\tprint ( costToBalance ( s ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check if given four integers ( or sides ) make rectangle | Function to check if the given integers value make a rectangle ; check all sides of rectangle combinations ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def isRectangle ( a , b , c , d ) :\\n\\tif ( a == b and d == c ) or ( a == c and b == d ) or ( a == d and b == c ) :\\n\\t\\treturn True\\n\\telse :\\n\\t\\treturn False\\na , b , c , d = 1 , 2 , 3 , 4\\nprint ( \\\" Yes \\\" if isRectangle ( a , b , c , d ) else \\\" No \\\" )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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 \\nbool 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 ) printf ( \\\" Found ▁ a ▁ subset ▁ with ▁ given ▁ sum \\\" ) ; else printf ( \\\" No ▁ subset ▁ with ▁ given ▁ sum \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimum absolute difference between N and a power of 2 | Function to return the minimum difference between N and a power of 2 ; Power of 2 closest to n on its left ; Power of 2 closest to n on its right ; Return the minimum abs difference ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function minAbsDiff ( $ n ) { $ left = 1 << ( ( floor ( log ( $ n ) \\/ log ( 2 ) ) ) ) ; $ right = $ left * 2 ; return min ( ( $ n - $ left ) , ( $ right - $ n ) ) ; } $ n = 15 ; echo minAbsDiff ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Range Query on array whose each element is XOR of index value and previous element | function return derived formula value . ; finding xor value of range [ y ... x ] ; function to solve query for l and r . ; if l or r is 0. ; finding x is divisible by 2 or not . ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def fun ( x ) :\\n\\ty = ( x \\/\\/ 4 ) * 4\\n\\tans = 0\\n\\tfor i in range ( y , x + 1 ) :\\n\\t\\tans ^= i\\n\\treturn ans\\ndef query ( x ) :\\n\\tif ( x == 0 ) :\\n\\t\\treturn 0\\n\\tk = ( x + 1 ) \\/\\/ 2\\n\\tif x % 2 == 0 :\\n\\t\\treturn ( ( fun ( k - 1 ) * 2 ) ^ ( k & 1 ) )\\n\\telse :\\n\\t\\treturn ( 2 * fun ( k ) )\\ndef allQueries ( q , l , r ) :\\n\\tfor i in range ( q ) :\\n\\t\\tprint ( query ( r [ i ] ) ^ query ( l [ i ] - 1 ) )\\nq = 3\\nl = [ 2 , 2 , 5 ]\\nr = [ 4 , 8 , 9 ]\\nallQueries ( q , l , r )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Contiguous subsegments of a string having distinct subsequent characters | Java implementation of the approach ; Function that prints the segments ; New array for every iteration ; Check if the character is in the array ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void sub_segments ( String str , int n ) { int l = str . length ( ) ; for ( int x = 0 ; x < l ; x += n ) { String newlist = str . substring ( x , x + n ) ; List < Character > arr = new ArrayList < Character > ( ) ; for ( char y : newlist . toCharArray ( ) ) { if ( ! arr . contains ( y ) ) arr . add ( y ) ; } for ( char y : arr ) System . out . print ( y ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { String str = \\\" geeksforgeeksgfg \\\" ; int n = 4 ; sub_segments ( str , n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find initial sequence that produces a given Array by cyclic increments upto index P | Function to generate and return the required initial arrangement ; Store the minimum element in the array ; Store the number of increments ; Subtract mi - 1 from every index ; Start from the last index which had been incremented ; Stores the index chosen to distribute its element ; Traverse the array cyclically and find the index whose element was distributed ; If any index has its value reduced to 0 ; Index whose element was distributed ; Store the number of increments at the starting index ; Print the original array ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function findArray ( a , n , P ) { let mi = Math . min ( ... a ) ; let ctr = 0 ; mi = Math . max ( 0 , mi - 1 ) ; for ( let i = 0 ; i < n ; i ++ ) { a [ i ] -= mi ; ctr += mi ; } let i = P - 1 ; let start = - 1 ; while ( true ) { if ( a [ i ] == 0 ) { start = i ; break ; } a [ i ] -= 1 ; ctr += 1 ; i = ( i - 1 + n ) % n ; } a [ start ] = ctr ; for ( i = 0 ; i < n ; i ++ ) { document . write ( a [ i ] + \\\" \\\" ) ; } } let N = 5 ; let P = 2 ; let arr = [ 3 , 2 , 0 , 2 , 7 ] ; findArray ( arr , N , P ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Twin Pythagorean triplets in an array | C ++ program for the above approach ; Function to check if there exist a twin pythagorean triplet in the given array ; Loop to check if there is a Pythagorean triplet in the array ; Check if there is consecutive triple ; Calculate square of array elements ; Driver Code ; Given array arr [ ] ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool isTriplet ( int ar [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = j + 1 ; k < n ; k ++ ) { if ( abs ( ar [ i ] - ar [ j ] ) == 1 || abs ( ar [ j ] - ar [ k ] ) == 1 || abs ( ar [ i ] - ar [ k ] ) == 1 ) { int x = ar [ i ] * ar [ i ] , y = ar [ j ] * ar [ j ] , z = ar [ k ] * ar [ k ] ; if ( x == y + z y == x + z z == x + y ) return true ; } } } } return false ; } int main ( ) { int arr [ ] = { 3 , 1 , 4 , 6 , 5 } ; int ar_size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; isTriplet ( arr , ar_size ) ? cout << \\\" Yes \\\" : cout << \\\" No \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function squareRootExists ( n , p ) { n = n % p ; for ( let x = 2 ; x < p ; x ++ ) if ( ( x * x ) % p == n ) return true ; return false ; } let p = 7 ; let n = 2 ; if ( squareRootExists ( n , p ) === true ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Distinct powers of a number N such that the sum is equal to K | Initializing the PowerArray with all 0 's ; Function to find the powers of N that add up to K ; Initializing the counter ; Executing the while loop until K is greater than 0 ; If K % N == 1 , then the power array is incremented by 1 ; Checking if any power is occurred more than once ; For any other value , the sum of powers cannot be added up to K ; Printing the powers of N that sum up to K ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"b = [ 0 for i in range ( 50 ) ]\\ndef PowerArray ( n , k ) :\\n\\tcount = 0\\n\\twhile ( k ) :\\n\\t\\tif ( k % n == 0 ) :\\n\\t\\t\\tk \\/\\/= n\\n\\t\\t\\tcount += 1\\n\\t\\telif ( k % n == 1 ) :\\n\\t\\t\\tk -= 1\\n\\t\\t\\tb [ count ] += 1\\n\\t\\t\\tif ( b [ count ] > 1 ) :\\n\\t\\t\\t\\tprint ( - 1 )\\n\\t\\t\\t\\treturn 0\\n\\t\\telse :\\n\\t\\t\\tprint ( - 1 )\\n\\t\\t\\treturn 0\\n\\tfor i in range ( 50 ) :\\n\\t\\tif ( b [ i ] ) :\\n\\t\\t\\tprint ( i , end = \\\" , \\\" )\\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\":\"\\\"Program to find N | Function to find n - th number in series made of 3 and 5 ; create an array of size ( n + 1 ) ; If i is odd ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function printNthElement ( $ n ) { $ arr = array_fill ( 0 , ( $ n + 1 ) , NULL ) ; $ arr [ 1 ] = 3 ; $ arr [ 2 ] = 5 ; for ( $ i = 3 ; $ i <= $ n ; $ i ++ ) { if ( $ i % 2 != 0 ) $ arr [ $ i ] = $ arr [ $ i \\/ 2 ] * 10 + 3 ; else $ arr [ $ i ] = $ arr [ ( $ i \\/ 2 ) - 1 ] * 10 + 5 ; } return $ arr [ $ n ] ; } $ n = 6 ; echo printNthElement ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Make largest palindrome by changing at most K | Returns maximum possible palindrome using k changes ; Initialize l and r by leftmost and rightmost ends ; First try to make String palindrome ; Replace left and right character by maximum of both ; If k is negative then we can 't make String palindrome ; At mid character , if K > 0 then change it to 9 ; If character at lth ( same as rth ) is less than 9 ; If none of them is changed in the previous loop then subtract 2 from K and convert both to 9 ; If one of them is changed in the previous loop then subtract 1 from K ( 1 more is subtracted already ) and make them 9 ; Driver code to test above methods\\\"\\nSolution in Javascript:\",\"targets\":\"function maximumPalinUsingKChanges ( str , k ) { let palin = str . split ( \\\" \\\" ) ; let ans = \\\" \\\" ; let l = 0 ; let r = str . length - 1 ; while ( l < r ) { if ( str [ l ] != str [ r ] ) { palin [ l ] = palin [ r ] = String . fromCharCode ( Math . max ( str . charAt ( l ) , str . charAt ( r ) ) ) ; k -- ; } l ++ ; r -- ; } if ( k < 0 ) { return \\\" \\\" ; } l = 0 ; r = str . length - 1 ; while ( l <= r ) { if ( l == r ) { if ( k > 0 ) { palin [ l ] = ' ' ; } } if ( palin [ l ] < ' ' ) { if ( k >= 2 && palin [ l ] == str [ l ] && palin [ r ] == str [ r ] ) { k -= 2 ; palin [ l ] = palin [ r ] = ' ' ; } else if ( k >= 1 && ( palin [ l ] != str [ l ] palin [ r ] != str [ r ] ) ) { k -- ; palin [ l ] = palin [ r ] = ' ' ; } } l ++ ; r -- ; } for ( let i = 0 ; i < palin . length ; i ++ ) ans += palin [ i ] ; return ans ; } let str = \\\" \\\" ; let k = 3 ; document . write ( maximumPalinUsingKChanges ( str , k ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Create a matrix with alternating rectangles of O and X | Function to print alternating rectangles of 0 and X ; k - starting row index m - ending row index l - starting column index n - ending column index i - iterator ; Store given number of rows and columns for later use ; Iniitialize the character to be stoed in a [ ] [ ] ; Fill characters in a [ ] [ ] in spiral form . Every iteration fills one rectangle of either Xs or Os ; Fill the first row from the remaining rows ; Fill the last column from the remaining columns ; Fill the last row from the remaining rows ; Print the first column from the remaining columns ; Flip character for next iteration ; Print the filled matrix ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function fill0X ( $ m , $ n ) { $ k = 0 ; $ l = 0 ; $ r = $ m ; $ c = $ n ; $ x = ' X ' ; while ( $ k < $ m && $ l < $ n ) { for ( $ i = $ l ; $ i < $ n ; ++ $ i ) $ a [ $ k ] [ $ i ] = $ x ; $ k ++ ; for ( $ i = $ k ; $ i < $ m ; ++ $ i ) $ a [ $ i ] [ $ n - 1 ] = $ x ; $ n -- ; if ( $ k < $ m ) { for ( $ i = $ n - 1 ; $ i >= $ l ; -- $ i ) $ a [ $ m - 1 ] [ $ i ] = $ x ; $ m -- ; } if ( $ l < $ n ) { for ( $ i = $ m - 1 ; $ i >= $ k ; -- $ i ) $ a [ $ i ] [ $ l ] = $ x ; $ l ++ ; } $ x = ( $ x == '0' ) ? ' X ' : '0' ; } for ( $ i = 0 ; $ i < $ r ; $ i ++ ) { for ( $ j = 0 ; $ j < $ c ; $ j ++ ) echo ( $ a [ $ i ] [ $ j ] . \\\" ▁ \\\" ) ; echo \\\" \\n \\\" ; } } echo \\\" Output ▁ for ▁ m ▁ = ▁ 5 , ▁ n ▁ = ▁ 6 \\n \\\" ; fill0X ( 5 , 6 ) ; echo \\\" Output for m = 4 , n = 4 \\\" ; fill0X ( 4 , 4 ) ; echo \\\" Output for m = 3 , n = 4 \\\" ; fill0X ( 3 , 4 ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Digital Root of a given large integer using Recursion | C # program to print the digital root of a given very large number ; Function to convert given sum into String ; Loop to extract digit one by one from the given sum and concatenate into the String ; Type casting for concatenation ; Return converted String ; Function to get individual digit sum from String ; Loop to get individual digit sum ; Function call to convert sum into String ; Function to calculate the digital root of a very large number ; Base condition ; Function call to get individual digit sum ; Recursive function to get digital root of a very large number ; Driver code ; Function to print readonly digit\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static String convertToString ( int sum ) { String str = \\\" \\\" ; while ( sum > 0 ) { str = str + ( char ) ( ( sum % 10 ) + '0' ) ; sum = sum \\/ 10 ; } return str ; } static String GetIndividulaDigitSum ( String str , int len ) { int sum = 0 ; for ( int i = 0 ; i < len ; i ++ ) { sum = sum + str [ i ] - '0' ; } return convertToString ( sum ) ; } static int GetDigitalRoot ( String str ) { if ( str . Length == 1 ) { return str [ 0 ] - '0' ; } str = GetIndividulaDigitSum ( str , str . Length ) ; return GetDigitalRoot ( str ) ; } public static void Main ( String [ ] args ) { String str = \\\"675987890789756545689070986776987\\\" ; Console . Write ( GetDigitalRoot ( str ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all odd length palindromic numbers within the range [ L , R ] | C program to find the sum of all odd length palindromic numbers within the given range ; Function that returns true if the given number is a palindrome ; Here we are generating a new number ( reverse_num ) * by reversing the digits of original input number ; If the original input number ( num ) is equal to * to its reverse ( reverse_num ) then its palindrome * else it is not . ; Function that returns true if the given number is of odd length ; Function to return the sum of all odd length palindromic numbers within the given range ; if number is palindrome and of odd length ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nbool isPalindrome ( int num ) { int reverse_num = 0 , remainder , temp ; temp = num ; while ( temp != 0 ) { remainder = temp % 10 ; reverse_num = reverse_num * 10 + remainder ; temp \\/= 10 ; } if ( reverse_num == num ) { return true ; } return false ; } bool isOddLength ( int num ) { int count = 0 ; while ( num > 0 ) { num \\/= 10 ; count ++ ; } if ( count % 2 != 0 ) { return true ; } return false ; } long sumOfAllPalindrome ( int L , int R ) { long sum = 0 ; if ( L <= R ) for ( int i = L ; i <= R ; i ++ ) { if ( isPalindrome ( i ) && isOddLength ( i ) ) { sum += i ; } } return sum ; } int main ( ) { int L = 110 , R = 1130 ; printf ( \\\" % ld \\\" , sumOfAllPalindrome ( L , R ) ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Closest sum partition ( into two subsets ) of numbers from 1 to n | Function to return the minimum required absolute difference ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function minAbsDiff ( $ n ) { $ mod = $ n % 4 ; if ( $ mod == 0 $ mod == 3 ) return 0 ; return 1 ; } $ n = 5 ; echo minAbsDiff ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Selection Sort | sort function ; One by one move boundary of unsorted subarray ; Find the minimum element in unsorted array ; swap the minimum value to $ith node ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function selection_sort ( & $ arr , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ low = $ i ; for ( $ j = $ i + 1 ; $ j < $ n ; $ j ++ ) { if ( $ arr [ $ j ] < $ arr [ $ low ] ) { $ low = $ j ; } } if ( $ arr [ $ i ] > $ arr [ $ low ] ) { $ tmp = $ arr [ $ i ] ; $ arr [ $ i ] = $ arr [ $ low ] ; $ arr [ $ low ] = $ tmp ; } } } $ arr = array ( 64 , 25 , 12 , 22 , 11 ) ; $ len = count ( $ arr ) ; selection_sort ( $ arr , $ len ) ; echo \\\" Sorted ▁ array ▁ : ▁ \\n \\\" ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) echo $ arr [ $ i ] . \\\" ▁ \\\" ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Sort a Bitonic Array | Function to Sort a Bitonic array in constant space ; Initialize the value of k ; In each iteration compare elements k distance apart and swap if they are not in order ; k is reduced to half after every iteration ; Print the array elements ; Given array arr [ ] ; Function call\\\"\\nSolution in Javascript:\",\"targets\":\"function sortArr ( a , n ) { let i , k ; k = parseInt ( Math . log ( n ) \\/ Math . log ( 2 ) ) ; k = parseInt ( Math . pow ( 2 , k ) ) ; while ( k > 0 ) { for ( i = 0 ; i + k < n ; i ++ ) if ( a [ i ] > a [ i + k ] ) { let tmp = a [ i ] ; a [ i ] = a [ i + k ] ; a [ i + k ] = tmp ; } k = k \\/ 2 ; } for ( i = 0 ; i < n ; i ++ ) { document . write ( a [ i ] + \\\" \\\" ) ; } } let arr = [ 5 , 20 , 30 , 40 , 36 , 33 , 25 , 15 , 10 ] ; let n = arr . length ; sortArr ( arr , n ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Maximum number of region in which N non | Function to find the maximum number of regions on a plane ; print the maximum number of regions ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def maxRegions ( n ) :\\n\\tnum = n * ( n + 1 ) \\/\\/ 2 + 1\\n\\tprint ( num )\\nn = 10\\nmaxRegions ( n )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Probability that a random pair chosen from an array ( a [ i ] , a [ j ] ) has the maximum sum | Function to return the probability of getting the maximum pair sum when a random pair is chosen from the given array ; Initialize the maximum sum , its count and the count of total pairs ; For every single pair ; Get the sum of the current pair ; If the sum is equal to the current maximum sum so far ; Increment its count ; If the sum is greater than the current maximum ; Update the current maximum and re - initialize the count to 1 ; Find the required probability ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function findProb ( arr , n ) { var maxSum = - 100000000 , maxCount = 0 , totalPairs = 0 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { var sum = arr [ i ] + arr [ j ] ; if ( sum == maxSum ) { maxCount ++ ; } else if ( sum > maxSum ) { maxSum = sum ; maxCount = 1 ; } totalPairs ++ ; } } var prob = maxCount \\/ totalPairs ; return prob ; } var arr = [ 1 , 1 , 1 , 2 , 2 , 2 ] var n = arr . length ; document . write ( findProb ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the Perimeter of a Regular Polygon | Java program to find the perimeter of a regular polygon ; Function to calculate the perimeter ; Calculate Perimeter ; Driver method ; Get the number of sides ; Get the length of side ; find perimeter\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static double Perimeter ( double s , int n ) { double perimeter = 1 ; perimeter = n * s ; return perimeter ; } public static void main ( String [ ] args ) { int n = 5 ; double s = 2.5 , peri ; peri = Perimeter ( s , n ) ; System . out . println ( \\\" Perimeter ▁ of ▁ Regular ▁ Polygon \\\" + \\\" ▁ with ▁ \\\" + n + \\\" ▁ sides ▁ of ▁ length ▁ \\\" + s + \\\" ▁ = ▁ \\\" + peri ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Compositorial of a number | Javascript program to find compositorial of composite numbers ; Function to check if a number is composite . ; Corner cases ; This is checked so that we can skip the middle five numbers in the below loop ; This function stores all composite numbers less than N ; Function to calculate the compositorial of n ; Multiply first n composite number ; Driver code ; Vector to store all the composite less than N\\\"\\nSolution in Javascript:\",\"targets\":\"let compo = [ ] ; function isComposite ( n ) { if ( n <= 3 ) return false ; if ( n % 2 == 0 n % 3 == 0 ) return true ; let i = 5 ; while ( i * i <= n ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true ; i = i + 6 ; } return false ; } function Compositorial_list ( n ) { let l = 0 ; for ( let i = 4 ; i < 1000000 ; i ++ ) { if ( l < n ) { if ( isComposite ( i ) ) { compo . push ( i ) ; l += 1 ; } } } } function calculateCompositorial ( n ) { let result = 1 ; for ( let i = 0 ; i < n ; i ++ ) result = result * compo [ i ] ; return result ; } let n = 5 ; Compositorial_list ( n ) ; document . write ( calculateCompositorial ( n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Move all zeroes to end of array | A C ++ program to move all zeroes at the end of array ; Function which pushes all zeros to end of an array . ; Count of non - zero elements ; Traverse the array . If element encountered is non - zero , then replace the element at index ' count ' with this element ; here count is ; incremented Now all non - zero elements have been shifted to front and ' count ' is set as index of first 0. Make all elements 0 from count to end . ; Driver program to test above function\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void pushZerosToEnd ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] != 0 ) arr [ count ++ ] = arr [ i ] ; while ( count < n ) arr [ count ++ ] = 0 ; } int main ( ) { int arr [ ] = { 1 , 9 , 8 , 4 , 0 , 0 , 2 , 7 , 0 , 6 , 0 , 9 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; pushZerosToEnd ( arr , n ) ; cout << \\\" Array ▁ after ▁ pushing ▁ all ▁ zeros ▁ to ▁ end ▁ of ▁ array ▁ : \\n \\\" ; for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << \\\" ▁ \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find the most valued alphabet in the String | JavaScript implementation of the approach ; Function to return the maximum valued alphabet ; To store the first and the last occurrence of all the characters ; Set the first and the last occurrence of all the characters to - 1 ; Update the occurrences of the characters ; Only set the first occurrence if it hasn 't already been set ; To store the result ; For every alphabet ; If current alphabet doesn 't appear in the given String ; If the current character has the highest value so far ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"const MAX = 26 ; function maxAlpha ( str , len ) { var first = new Array ( MAX ) ; var last = new Array ( MAX ) ; for ( var i = 0 ; i < MAX ; i ++ ) { first [ i ] = - 1 ; last [ i ] = - 1 ; } for ( var i = 0 ; i < len ; i ++ ) { var index = str [ i ] . charCodeAt ( 0 ) - \\\" \\\" . charCodeAt ( 0 ) ; if ( first [ index ] === - 1 ) first [ index ] = i ; last [ index ] = i ; } var ans = - 1 , maxVal = - 1 ; for ( var i = 0 ; i < MAX ; i ++ ) { if ( first [ i ] === - 1 ) continue ; if ( last [ i ] - first [ i ] > maxVal ) { maxVal = last [ i ] - first [ i ] ; ans = i ; } } return String . fromCharCode ( ans + \\\" \\\" . charCodeAt ( 0 ) ) ; } var str = \\\" \\\" ; var len = str . length ; document . write ( maxAlpha ( str , len ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count words in a given string | PHP 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 Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ OUT = 0 ; $ IN = 1 ; function countWords ( $ str ) { global $ OUT , $ IN ; $ state = $ OUT ; $ wc = 0 ; $ i = 0 ; while ( $ i < strlen ( $ str ) ) { if ( $ str [ $ i ] == \\\" ▁ \\\" $ str [ $ i ] == \\\" \\n \\\" $ str [ $ i ] == \\\" \\t \\\" ) $ state = $ OUT ; else if ( $ state == $ OUT ) { $ state = $ IN ; ++ $ wc ; } ++ $ i ; } return $ wc ; } $ str = \\\" One ▁ two \\t \\t three \\n ▁ four \\t five ▁ \\\" ; echo \\\" No ▁ of ▁ words ▁ : ▁ \\\" . countWords ( $ str ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the mean vector of a Matrix | C ++ program to find mean vector of given matrix ; Function to find mean vector ; loop to traverse each column ; to calculate mean of each row ; to store sum of elements of a column ; Drivers code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; #define rows 3\\n#define cols 3\\nvoid meanVector ( int mat [ rows ] [ cols ] ) { cout << \\\" [ ▁ \\\" ; for ( int i = 0 ; i < rows ; i ++ ) { double mean = 0.00 ; int sum = 0 ; for ( int j = 0 ; j < cols ; j ++ ) sum += mat [ j ] [ i ] ; mean = sum \\/ rows ; cout << mean << \\\" ▁ \\\" ; } cout << \\\" ] \\\" ; } int main ( ) { int mat [ rows ] [ cols ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; meanVector ( mat ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Print an N x M matrix such that each row and column has all the vowels in it | Function to print the required matrix ; Impossible to generate the required matrix ; Store all the vowels ; Print the matrix ; Print vowels for every index ; Shift the vowels by one ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function printMatrix ( $ n , $ m ) { if ( $ n < 5 $ m < 5 ) { echo - 1 ; return ; } $ s = \\\" aeiou \\\" ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = 0 ; $ j < $ m ; $ j ++ ) { echo $ s [ $ j % 5 ] . \\\" \\\" ; } echo \\\" \\n \\\" ; $ c = $ s [ 0 ] ; for ( $ k = 0 ; $ k < 4 ; $ k ++ ) { $ s [ $ k ] = $ s [ $ k + 1 ] ; } $ s [ 4 ] = $ c ; } } $ n = 5 ; $ m = 5 ; printMatrix ( $ n , $ m ) ; return 0 ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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\\\"\\nSolution in Javascript:\",\"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\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\\\"\\nSolution 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 ▁ of ▁ % d ▁ numbers ▁ is ▁ % f ▁ \\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\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-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\\\"\\nHow can the above be solved 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 ▁ Point ▁ is ▁ \\\" . linearSearch ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Largest subarray with equal number of 0 s and 1 s | A simple program to find the largest subarray with equal number of 0 s and 1 s ; This function Prints the starting and ending indexes of the largest subarray with equal number of 0 s and 1 s . Also returns the size of such subarray . ; Pick a starting point as i ; Consider all subarrays starting from i ; If this is a 0 sum subarray , then compare it with maximum size subarray calculated so far ; Driver program to test above functions\\\"\\nSolution in C:\",\"targets\":\"#include \\nint findSubArray ( int arr [ ] , int n ) { int sum = 0 ; int maxsize = -1 , startindex ; for ( int i = 0 ; i < n - 1 ; i ++ ) { sum = ( arr [ i ] == 0 ) ? -1 : 1 ; for ( int j = i + 1 ; j < n ; j ++ ) { ( arr [ j ] == 0 ) ? ( sum += -1 ) : ( sum += 1 ) ; if ( sum == 0 && maxsize < j - i + 1 ) { maxsize = j - i + 1 ; startindex = i ; } } } if ( maxsize == -1 ) printf ( \\\" No ▁ such ▁ subarray \\\" ) ; else printf ( \\\" % d ▁ to ▁ % d \\\" , startindex , startindex + maxsize - 1 ) ; return maxsize ; } int main ( ) { int arr [ ] = { 1 , 0 , 0 , 1 , 0 , 1 , 1 } ; int size = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; findSubArray ( arr , size ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all the prime divisors of a number | C # 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 C#:\",\"targets\":\"using System ; class GFG { static bool 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 int SumOfPrimeDivisors ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( n % i == 0 ) { if ( isPrime ( i ) ) sum += i ; } } return sum ; } public static void Main ( ) { int n = 60 ; Console . WriteLine ( \\\" Sum ▁ of ▁ prime ▁ divisors ▁ of ▁ 60 ▁ is ▁ \\\" + SumOfPrimeDivisors ( n ) + \\\" \\n \\\" ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to place all the characters of two given strings alternately | C ++ Program to implement the above approach ; Function to get the factorial of N ; Function to get the total number of distinct ways ; Length of str1 ; Length of str2 ; If both strings have equal length ; If both strings do not have equal length ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int fact ( int n ) { int res = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { res = res * i ; } return res ; } int distinctWays ( string str1 , string str2 ) { int n = str1 . length ( ) ; int m = str2 . length ( ) ; if ( n == m ) { return 2 * fact ( n ) * fact ( m ) ; } return fact ( n ) * fact ( m ) ; } int main ( ) { string str1 = \\\" aegh \\\" ; string str2 = \\\" rsw \\\" ; cout << distinctWays ( str1 , str2 ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check whether given string can be generated after concatenating given strings | 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 ; I$f 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 PHP?\",\"targets\":\"< ? php function startsWith ( $ str , $ pre ) { $ strLen = strlen ( $ str ) ; $ preLen = strlen ( $ pre ) ; $ i = 0 ; $ j = 0 ; while ( $ i < $ strLen && $ j < $ preLen ) { if ( $ str [ $ i ] != $ pre [ $ j ] ) return false ; $ i ++ ; $ j ++ ; } return true ; } function endsWith ( $ str , $ suff ) { $ i = strlen ( $ str ) - 0 ; $ j = strlen ( $ suff ) - 0 ; while ( $ i >= 0 && $ j >= 0 ) { if ( $ str [ $ i ] != $ suff [ $ j ] ) return false ; $ i -- ; $ j -- ; } return true ; } function checkString ( $ str , $ a , $ b ) { if ( strlen ( $ str ) != strlen ( $ a ) + strlen ( $ b ) ) return false ; if ( startsWith ( $ str , $ a ) ) { if ( endsWith ( $ str , $ b ) ) return true ; } if ( startsWith ( $ str , $ b ) ) { if ( endsWith ( $ str , $ a ) ) return true ; } return false ; } $ str = \\\" GeeksforGeeks \\\" ; $ a = \\\" Geeksfo \\\" ; $ b = \\\" rGeeks \\\" ; if ( checkString ( $ str , $ a , $ b ) ) echo \\\" Yes \\\" ; else echo \\\" No \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; const int mod = 1e9 + 7 ; 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 ; } int main ( ) { int arr [ ] = { 5 , 3 , 1 , 4 , 3 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << ways ( 0 , arr , n ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"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\\\"\\nSolution 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\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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\":\"\\\"Find largest d in array such that a + b + c = d | A hashing based C # program to find largest d such that a + b + c = d . ; To store and retrieve indices pair i & j ; The function finds four elements with given sum X ; Store sums ( a + b ) of all pairs ( a , b ) in a hash table ; Traverse through all pairs and find ( d - c ) is present in hash table ; If d - c is present in hash table , ; Making sure that all elements are distinct array elements and an element is not considered more than once . ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; public class Indexes { int i , j ; public Indexes ( int i , int j ) { this . i = i ; this . j = j ; } public int getI ( ) { return i ; } public int getJ ( ) { return j ; } } public class GFG { static int findFourElements ( int [ ] arr , int n ) { Dictionary < int , Indexes > map = new Dictionary < int , Indexes > ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { map . Add ( arr [ i ] + arr [ j ] , new Indexes ( i , j ) ) ; } } int d = int . MinValue ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int abs_diff = Math . Abs ( arr [ i ] - arr [ j ] ) ; if ( map . ContainsKey ( abs_diff ) ) { Indexes indexes = map [ abs_diff ] ; if ( indexes . getI ( ) != i && indexes . getI ( ) != j && indexes . getJ ( ) != i && indexes . getJ ( ) != j ) { d = Math . Max ( d , Math . Max ( arr [ i ] , arr [ j ] ) ) ; } } } } return d ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 5 , 7 , 12 } ; int n = arr . Length ; int res = findFourElements ( arr , n ) ; if ( res == int . MinValue ) Console . WriteLine ( \\\" No ▁ Solution \\\" ) ; else Console . WriteLine ( res ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count pairs with equal Bitwise AND and Bitwise OR value | Java program to implement the above approach ; Function to count pairs in an array whose bitwise AND equal to bitwise OR ; Store count of pairs whose bitwise AND equal to bitwise OR ; Stores frequency of distinct elements of array ; Traverse the array ; Increment the frequency of arr [ i ] ; Traverse map ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { static int countPairs ( int [ ] arr , int N ) { int cntPairs = 0 ; HashMap < Integer , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { mp . put ( arr [ i ] , mp . getOrDefault ( arr [ i ] , 0 ) + 1 ) ; } for ( Map . Entry < Integer , Integer > freq : mp . entrySet ( ) ) { cntPairs += ( freq . getValue ( ) * ( freq . getValue ( ) - 1 ) ) \\/ 2 ; } return cntPairs ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 1 , 2 , 2 } ; int N = arr . length ; System . out . println ( countPairs ( arr , N ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Hyperfactorial of a number | function to calculate the value of hyperfactorial ; initialise the val to 1 ; 1 ^ 1 * 2 ^ 2 * 3 ^ 3. . . . ; returns the hyperfactorial of a number ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function boost_hyperfactorial ( num ) { var val = 1 ; for ( var i = 1 ; i <= num ; i ++ ) { for ( var j = 1 ; j <= i ; j ++ ) { val *= i ; } } return val ; } var num = 5 ; document . write ( boost_hyperfactorial ( num ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"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 JS?\",\"targets\":\"function xor_triplet ( arr , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { for ( let k = j ; k < n ; k ++ ) { let xor1 = 0 , xor2 = 0 ; for ( let x = i ; x < j ; x ++ ) { xor1 ^= arr [ x ] ; } for ( let x = j ; x <= k ; x ++ ) { xor2 ^= arr [ x ] ; } if ( xor1 == xor2 ) { ans ++ ; } } } } return ans ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; document . write ( xor_triplet ( arr , n ) )\",\"language\":\"python\",\"split\":\"test\",\"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 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 ▁ \\\" , i ) ; } if ( i - ( n \\/ i ) == 1 ) { i -- ; } for ( ; i >= 1 ; i -- ) { if ( n % i == 0 ) printf ( \\\" % d ▁ \\\" , n \\/ i ) ; } } int main ( ) { printf ( \\\" The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ \\n \\\" ) ; printDivisors ( 100 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if any K ranges overlap at any point | Function that returns true if any k segments overlap at any point ; Vector to store the starting point and the ending point ; Starting points are marked by - 1 and ending points by + 1 ; Sort the vector by first element ; Stack to store the overlaps ; Get the current element ; If it is the starting point ; Push it in the stack ; It is the ending point ; Pop an element from stack ; If more than k ranges overlap ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def kOverlap ( pairs : list , k ) :\\n\\tvec = list ( )\\n\\tfor i in range ( len ( pairs ) ) :\\n\\t\\tvec . append ( ( pairs [ 0 ] , - 1 ) )\\n\\t\\tvec . append ( ( pairs [ 1 ] , 1 ) )\\n\\tvec . sort ( key = lambda a : a [ 0 ] )\\n\\tst = list ( )\\n\\tfor i in range ( len ( vec ) ) :\\n\\t\\tcur = vec [ i ]\\n\\t\\tif cur [ 1 ] == - 1 :\\n\\t\\t\\tst . append ( cur )\\n\\t\\telse :\\n\\t\\t\\tst . pop ( )\\n\\t\\tif len ( st ) >= k :\\n\\t\\t\\treturn True\\n\\treturn False\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tpairs = list ( )\\n\\tpairs . append ( ( 1 , 3 ) )\\n\\tpairs . append ( ( 2 , 4 ) )\\n\\tpairs . append ( ( 3 , 5 ) )\\n\\tpairs . append ( ( 7 , 10 ) )\\n\\tn = len ( pairs )\\n\\tk = 3\\n\\tif kOverlap ( pairs , k ) :\\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\":\"\\\"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\":\"\\\"Count the triplets such that A [ i ] < B [ j ] < C [ k ] | Function to return the count of elements in arr [ ] which are less than the given key ; Modified binary search ; Function to return the count of elements in arr [ ] which are greater than the given key ; Modified binary search ; Function to return the count of the required triplets ; Sort all three arrays ; Iterate for all the elements of array B ; Count of elements in A [ ] which are less than the chosen element from B [ ] ; Count of elements in C [ ] which are greater than the chosen element from B [ ] ; Update the count ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php function countLessThan ( & $ arr , $ n , $ key ) { $ l = 0 ; $ r = $ n - 1 ; $ index = -1 ; while ( $ l <= $ r ) { $ m = intval ( ( $ l + $ r ) \\/ 2 ) ; if ( $ arr [ $ m ] < $ key ) { $ l = $ m + 1 ; $ index = $ m ; } else { $ r = $ m - 1 ; } } return ( $ index + 1 ) ; } function countGreaterThan ( & $ arr , $ n , $ key ) { $ l = 0 ; $ r = $ n - 1 ; $ index = -1 ; while ( $ l <= $ r ) { $ m = intval ( ( $ l + $ r ) \\/ 2 ) ; if ( $ arr [ $ m ] <= $ key ) { $ l = $ m + 1 ; } else { $ r = $ m - 1 ; $ index = $ m ; } } if ( $ index == -1 ) return 0 ; return ( $ n - $ index ) ; } function countTriplets ( $ n , & $ a , & $ b , & $ c ) { sort ( $ a ) ; sort ( $ b ) ; sort ( $ c ) ; $ count = 0 ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { $ current = $ b [ $ i ] ; $ a_index = -1 ; $ c_index = -1 ; $ low = countLessThan ( $ a , $ n , $ current ) ; $ high = countGreaterThan ( $ c , $ n , $ current ) ; $ count += ( $ low * $ high ) ; } return $ count ; } $ a = array ( 1 , 5 ) ; $ b = array ( 2 , 4 ) ; $ c = array ( 3 , 6 ) ; $ size = sizeof ( $ a ) ; echo countTriplets ( $ size , $ a , $ b , $ c ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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\\\"\\nHow can the above be solved in C-Sharp?\",\"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 ] + \\\" ▁ \\\" ) ; } } 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\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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 program to test\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; 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 ; } int main ( ) { int p = 7 ; int n = 2 ; squareRootExists ( n , p ) ? cout << \\\" Yes \\\" : cout << \\\" No \\\" ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum profit after buying and selling the stocks with transaction fees | Set 2 | Function to find the maximum profit with transaction fee ; Traversing the stocks for each day ; Update buy and sell ; Return the maximum profit ; Driver code ; Given Input ; Function Call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def MaxProfit ( arr , n , transactionFee ) :\\n\\tbuy = - arr [ 0 ]\\n\\tsell = 0\\n\\tfor i in range ( 1 , n , 1 ) :\\n\\t\\ttemp = buy\\n\\t\\tbuy = max ( buy , sell - arr [ i ] )\\n\\t\\tsell = max ( sell , temp + arr [ i ] - transactionFee )\\n\\treturn max ( sell , buy )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 6 , 1 , 7 , 2 , 8 , 4 ]\\n\\tn = len ( arr )\\n\\ttransactionFee = 2\\n\\tprint ( MaxProfit ( arr , n , transactionFee ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\nHow can the above be solved 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 ▁ Obtainable ▁ Value ▁ is ▁ % d \\\" , cutRod ( arr , size ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count of permutations of an Array having each element as a multiple or a factor of its index | C ++ Program to implement the above approach ; Function to find the count of desired permutations ; Base case ; If i has not been inserted ; Backtrack ; Insert i ; Recur to find valid permutations ; Remove i ; Return the final count ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int findPermutation ( unordered_set < int > & arr , int N ) { int pos = arr . size ( ) + 1 ; if ( pos > N ) return 1 ; int res = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( arr . find ( i ) == arr . end ( ) ) { if ( i % pos == 0 or pos % i == 0 ) { arr . insert ( i ) ; res += findPermutation ( arr , N ) ; arr . erase ( arr . find ( i ) ) ; } } } return res ; } int main ( ) { int N = 5 ; unordered_set < int > arr ; cout << findPermutation ( arr , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"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\\\"\\nHow can the above be solved in JS?\",\"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\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Print bitwise AND set of a number N | CPP program to print all bitwise subsets of N ( Efficient approach ) ; function to find bitwise subsets Efficient approach ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void printSubsets ( int n ) { for ( int i = n ; i > 0 ; i = ( i - 1 ) & n ) cout << i << \\\" ▁ \\\" ; cout << 0 ; } int main ( ) { int n = 9 ; printSubsets ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count subarrays with sum equal to its XOR value | Function to count the number of subarrays such that Xor of all the elements of that subarray is equal to sum of the elements ; Maintain two pointers left and right ; Iterating through the array ; Calculate the window where the above condition is satisfied ; Count will be ( right - left ) ; Remove the previous element as it is already included ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function operation ( arr , N ) { let right = 0 , ans = 0 , num = 0 ; for ( let left = 0 ; left < N ; left ++ ) { while ( right < N && num + arr [ right ] == ( num ^ arr [ right ] ) ) { num += arr [ right ] ; right ++ ; } ans += right - left ; if ( left == right ) right ++ ; else num -= arr [ left ] ; } return ans ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; document . write ( operation ( arr , N ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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 ▁ Found : ▁ ( % d , ▁ % d ) \\\" , arr [ i ] , arr [ j ] ) ; return true ; } else if ( arr [ j ] - arr [ i ] < n ) j ++ ; else i ++ ; } printf ( \\\" No ▁ such ▁ 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\":\"\\\"Sort the biotonic doubly linked list | a node of the doubly linked list ; Function to reverse a Doubly Linked List ; swap next and prev for all nodes of doubly linked list ; Before changing head , check for the cases like empty list and list with only one node ; Function to merge two sorted doubly linked lists ; If first linked list is empty ; If second linked list is empty ; Pick the smaller value ; function to sort a biotonic doubly linked list ; if list is empty or if it contains a single node only ; if true , then ' current ' is the first node which is smaller than its previous node ; move to the next node ; if true , then list is already sorted ; spilt into two lists , one starting with ' head ' and other starting with ' current ' ; reverse the list starting with ' current ' ; merge the two lists and return the final merged doubly linked list ; Function to insert a node at the beginning of the Doubly Linked List ; allocate node ; put in the data ; since we are adding at the beginning , prev is always null ; link the old list off the new node ; change prev of head node to new node ; move the head to povar to the new node ; Function to prvar nodes in a given doubly linked list ; if list is empty ; Driver Code ; Create the doubly linked list : 2 < .5 < .7 < .12 < .10 < .6 < .4 < .1 ; sort the biotonic DLL\\\"\\nHow can the above be solved in JS?\",\"targets\":\"class Node { constructor ( ) { this . data = 0 ; this . prev = null ; this . next = null ; } } function reverse ( head_ref ) { var temp = null ; var current = head_ref ; while ( current != null ) { temp = current . prev ; current . prev = current . next ; current . next = temp ; current = current . prev ; } if ( temp != null ) head_ref = temp . prev ; return head_ref ; } function merge ( first , second ) { if ( first == null ) return second ; if ( second == null ) return first ; if ( first . data < second . data ) { first . next = merge ( first . next , second ) ; first . next . prev = first ; first . prev = null ; return first ; } else { second . next = merge ( first , second . next ) ; second . next . prev = second ; second . prev = null ; return second ; } } function sort ( head ) { if ( head == null head . next == null ) return head ; var current = head . next ; while ( current != null ) { if ( current . data < current . prev . data ) break ; current = current . next ; } if ( current == null ) return head ; current . prev . next = null ; current . prev = null ; current = reverse ( current ) ; return merge ( head , current ) ; } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . prev = null ; new_node . next = ( head_ref ) ; if ( ( head_ref ) != null ) ( head_ref ) . prev = new_node ; ( head_ref ) = new_node ; return head_ref ; } function printList ( head ) { if ( head == null ) document . write ( \\\" \\\" ) ; while ( head != null ) { document . write ( head . data + \\\" \\\" ) ; head = head . next ; } } var head = null ; head = push ( head , 1 ) ; head = push ( head , 4 ) ; head = push ( head , 6 ) ; head = push ( head , 10 ) ; head = push ( head , 12 ) ; head = push ( head , 7 ) ; head = push ( head , 5 ) ; head = push ( head , 2 ) ; document . write ( \\\" \\\" ) ; printList ( head ) ; head = sort ( head ) ; document . write ( \\\" \\\" ) ; printList ( head ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Partition problem | DP | A recursive C # solution for partition problem ; A utility function that returns true if there is a subset of arr [ ] with sun 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 ; Returns true if arr [ ] can be partitioned in two subsets of equal sum , otherwise false ; Calculate sum of the elements in array ; If sum is odd , there cannot be two subsets with equal sum ; Find if there is subset with sum equal to half of total sum ; Driver code ; Function call\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static bool isSubsetSum ( int [ ] arr , int n , int sum ) { if ( sum == 0 ) return true ; if ( n == 0 && sum != 0 ) return false ; if ( arr [ n - 1 ] > sum ) return isSubsetSum ( arr , n - 1 , sum ) ; return isSubsetSum ( arr , n - 1 , sum ) || isSubsetSum ( arr , n - 1 , sum - arr [ n - 1 ] ) ; } static bool findPartition ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; return isSubsetSum ( arr , n , sum \\/ 2 ) ; } public static void Main ( ) { int [ ] arr = { 3 , 1 , 5 , 9 , 12 } ; int n = arr . Length ; if ( findPartition ( arr , n ) == true ) Console . Write ( \\\" Can ▁ be ▁ divided ▁ into ▁ two ▁ \\\" + \\\" subsets ▁ of ▁ equal ▁ sum \\\" ) ; else Console . Write ( \\\" Can ▁ not ▁ be ▁ divided ▁ into ▁ \\\" + \\\" two ▁ subsets ▁ of ▁ equal ▁ sum \\\" ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sum of division of the possible pairs for the given Array | C ++ implementation to compute the sum of division of all the possible pairs for the given array ; Function to compute the sum ; counting frequency of each term and finding maximum among it ; Making cumulative frequency ; Taking the ceil value ; nos . in [ ( n - 0.5 ) X , ( n + 0.5 ) X ) range will add n to the ans ; Return the final result ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#define ll long long\\nusing namespace std ; int func ( int arr [ ] , int n ) { double ans = 0 ; int maxx = 0 ; double freq [ 100005 ] = { 0 } ; int temp ; for ( int i = 0 ; i < n ; i ++ ) { temp = arr [ i ] ; freq [ temp ] ++ ; maxx = max ( maxx , temp ) ; } for ( int i = 1 ; i <= maxx ; i ++ ) { freq [ i ] += freq [ i - 1 ] ; } for ( int i = 1 ; i <= maxx ; i ++ ) { if ( freq [ i ] ) { i = ( double ) i ; double j ; ll value = 0 ; double cur = ceil ( 0.5 * i ) - 1.0 ; for ( j = 1.5 ; ; j ++ ) { int val = min ( maxx , ( int ) ( ceil ( i * j ) - 1.0 ) ) ; int times = ( freq [ i ] - freq [ i - 1 ] ) , con = j - 0.5 ; ans += times * con * ( freq [ ( int ) val ] - freq [ ( int ) cur ] ) ; cur = val ; if ( val == maxx ) break ; } } } return ( ll ) ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; cout << func ( arr , n ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Sum of Fibonacci Numbers with alternate negatives | 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 ; Get n ; Find the alternating sum\\\"\\nSolution in php:\",\"targets\":\"< ? php function calculateAlternateSum ( $ n ) { if ( $ n <= 0 ) return 0 ; $ fibo = array ( ) ; $ fibo [ 0 ] = 0 ; $ fibo [ 1 ] = 1 ; $ sum = pow ( $ fibo [ 0 ] , 2 ) + pow ( $ fibo [ 1 ] , 2 ) ; for ( $ 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 ; } $ n = 8 ; echo ( \\\" Alternating ▁ Fibonacci ▁ Sum ▁ upto ▁ \\\" ) ; echo $ n ; echo \\\" ▁ terms : ▁ \\\" ; echo ( calculateAlternateSum ( $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimize the difference between the maximum and minimum values of the modified array | C ++ program to find the minimum difference . ; Function to return required minimum difference ; finding minimum and maximum values ; returning minimum possible difference ; Driver program ; function to return the answer\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int minDiff ( int n , int x , int A [ ] ) { int mn = A [ 0 ] , mx = A [ 0 ] ; for ( int i = 0 ; i < n ; ++ i ) { mn = min ( mn , A [ i ] ) ; mx = max ( mx , A [ i ] ) ; } return max ( 0 , mx - mn - 2 * x ) ; } int main ( ) { int n = 3 , x = 3 ; int A [ ] = { 1 , 3 , 6 } ; cout << minDiff ( n , x , A ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to reach Nth Stairs by taking 1 and 2 steps with exactly one 3 step | Java implementation to find the number the number of ways to reach Nth stair by taking 1 , 2 step at a time and 3 Steps at a time exactly once . ; Function to find the number the number of ways to reach Nth stair ; Array including number of ways that includes 3 ; Array including number of ways that doesn 't includes 3 ; Initially to reach 3 stairs by taking 3 steps can be reached by 1 way ; Loop to find the number the number of ways to reach Nth stair ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int number_of_ways ( int n ) { int [ ] includes_3 = new int [ n + 1 ] ; int [ ] not_includes_3 = new int [ n + 1 ] ; includes_3 [ 3 ] = 1 ; not_includes_3 [ 1 ] = 1 ; not_includes_3 [ 2 ] = 2 ; not_includes_3 [ 3 ] = 3 ; for ( int i = 4 ; i <= n ; i ++ ) { includes_3 [ i ] = includes_3 [ i - 1 ] + includes_3 [ i - 2 ] + not_includes_3 [ i - 3 ] ; not_includes_3 [ i ] = not_includes_3 [ i - 1 ] + not_includes_3 [ i - 2 ] ; } return includes_3 [ n ] ; } public static void main ( String [ ] args ) { int n = 7 ; System . out . print ( number_of_ways ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximum score possible by removing substrings made up of single distinct character | C ++ program for the above approach ; Initialize a dictionary to store the precomputed results ; Function to calculate the maximum score possible by removing substrings ; If s is present in dp [ ] array ; Base Cases : ; If length of string is 0 ; If length of string is 1 ; Put head pointer at start ; Initialize the max variable ; Generate the substrings using two pointers ; If s [ head ] and s [ tail ] are different ; Move head to tail and break ; Store the substring ; Update the maximum ; Move the tail ; Store the score ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; map < string , int > dp ; int maxScore ( string s , vector < int > a ) { if ( dp . find ( s ) != dp . end ( ) ) return dp [ s ] ; int n = s . size ( ) ; if ( n == 0 ) return 0 ; if ( n == 1 ) return a [ 0 ] ; int head = 0 ; int mx = -1 ; while ( head < n ) { int tail = head ; while ( tail < n ) { if ( s [ tail ] != s [ head ] ) { head = tail ; break ; } string sub = s . substr ( head , tail + 1 ) ; mx = max ( mx , a [ sub . size ( ) - 1 ] + maxScore ( s . substr ( 0 , head ) + s . substr ( tail + 1 , s . size ( ) ) , a ) ) ; tail += 1 ; } if ( tail == n ) break ; } dp [ s ] = mx ; return mx ; } int main ( ) { string s = \\\" abb \\\" ; vector < int > a = { 1 , 3 , 1 } ; cout << ( maxScore ( s , a ) - 1 ) ; }\",\"language\":\"python\",\"split\":\"train\",\"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\":\"#include \\n#include \\nint isPowerOf2 ( char * str ) { int len_str = strlen ( str ) ; 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 ; for ( int i = 0 , j = 0 ; i < len_str ; i ++ ) { num = num * 10 + str [ i ] - '0' ; if ( num < 2 ) { if ( i != 0 ) str [ j ++ ] = '0' ; continue ; } str [ j ++ ] = ( int ) ( num \\/ 2 ) + '0' ; num = ( num ) - ( num \\/ 2 ) * 2 ; } str [ j ] = ' \\\\0' ; len_str = j ; } return 1 ; } int main ( ) { char str1 [ ] = \\\"12468462246684202468024\\\" \\\"6842024662202000002\\\" ; char str2 [ ] = \\\"1\\\" ; char str3 [ ] = \\\"128\\\" ; printf ( \\\" % d % d % d \\\" , isPowerOf2 ( str1 ) , isPowerOf2 ( str2 ) , isPowerOf2 ( str3 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Sort the biotonic doubly linked list | Node of a doubly linked list ; Function to reverse a Doubly Linked List ; swap next and prev for all nodes of doubly linked list ; Before changing head , check for the cases like empty list and list with only one node ; Function to merge two sorted doubly linked lists ; If first linked list is empty ; If second linked list is empty ; Pick the smaller value ; function to sort a biotonic doubly linked list ; if list is empty or if it contains a single node only ; if true , then ' current ' is the first node which is smaller than its previous node ; move to the next node ; if true , then list is already sorted ; spilt into two lists , one starting with ' head ' and other starting with ' current ' ; reverse the list starting with ' current ' ; merge the two lists and return the final merged doubly linked list ; Function to insert a node at the beginning of the Doubly Linked List ; allocate node ; put in the data ; since we are adding at the beginning , prev is always None ; link the old list off the new node ; change prev of head node to new node ; move the head to point to the new node ; Function to print nodes in a given doubly linked list ; if list is empty ; Driver Code ; Create the doubly linked list : 2 < .5 < .7 < .12 < .10 < .6 < .4 < .1 ; sort the biotonic DLL\\\"\\nHow can the above be solved in Python?\",\"targets\":\"class Node :\\n\\tdef __init__ ( self , next = None , prev = None , data = None ) :\\n\\t\\tself . next = next\\n\\t\\tself . prev = prev\\n\\t\\tself . data = data\\ndef reverse ( head_ref ) :\\n\\ttemp = None\\n\\tcurrent = head_ref\\n\\twhile ( current != None ) :\\n\\t\\ttemp = current . prev\\n\\t\\tcurrent . prev = current . next\\n\\t\\tcurrent . next = temp\\n\\t\\tcurrent = current . prev\\n\\tif ( temp != None ) :\\n\\t\\thead_ref = temp . prev\\n\\t\\treturn head_ref\\ndef merge ( first , second ) :\\n\\tif ( first == None ) :\\n\\t\\treturn second\\n\\tif ( second == None ) :\\n\\t\\treturn first\\n\\tif ( first . data < second . data ) :\\n\\t\\tfirst . next = merge ( first . next , second )\\n\\t\\tfirst . next . prev = first\\n\\t\\tfirst . prev = None\\n\\t\\treturn first\\n\\telse :\\n\\t\\tsecond . next = merge ( first , second . next )\\n\\t\\tsecond . next . prev = second\\n\\t\\tsecond . prev = None\\n\\t\\treturn second\\ndef sort ( head ) :\\n\\tif ( head == None or head . next == None ) :\\n\\t\\treturn head\\n\\tcurrent = head . next\\n\\twhile ( current != None ) :\\n\\t\\tif ( current . data < current . prev . data ) :\\n\\t\\t\\tbreak\\n\\t\\tcurrent = current . next\\n\\tif ( current == None ) :\\n\\t\\treturn head\\n\\tcurrent . prev . next = None\\n\\tcurrent . prev = None\\n\\tcurrent = reverse ( current )\\n\\treturn merge ( head , current )\\ndef push ( head_ref , new_data ) :\\n\\tnew_node = Node ( )\\n\\tnew_node . data = new_data\\n\\tnew_node . prev = None\\n\\tnew_node . next = ( head_ref )\\n\\tif ( ( head_ref ) != None ) :\\n\\t\\t( head_ref ) . prev = new_node\\n\\t( head_ref ) = new_node\\n\\treturn head_ref\\ndef printList ( head ) :\\n\\tif ( head == None ) :\\n\\t\\tprint ( \\\" Doubly ▁ Linked ▁ list ▁ empty \\\" )\\n\\twhile ( head != None ) :\\n\\t\\tprint ( head . data , end = \\\" ▁ \\\" )\\n\\t\\thead = head . next\\nhead = None\\nhead = push ( head , 1 )\\nhead = push ( head , 4 )\\nhead = push ( head , 6 )\\nhead = push ( head , 10 )\\nhead = push ( head , 12 )\\nhead = push ( head , 7 )\\nhead = push ( head , 5 )\\nhead = push ( head , 2 )\\nprint ( \\\" Original ▁ Doubly ▁ linked ▁ list : n \\\" )\\nprintList ( head )\\nhead = sort ( head )\\nprint ( \\\" Doubly linked list after sorting : \\\" )\\nprintList ( head )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Change in Median of given array after deleting given elements | C # program for the above approach ; Function to find the median change after removing elements from arr2 [ ] ; To store the median ; If N is odd ; If N is even ; Find the current element in arr1 ; Erase the element ; Decrement N ; If N is odd ; If N is even ; Print the corresponding difference of median ; Driver Code ; Given arrays ; Function Call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void medianChange ( List < int > arr1 , List < int > arr2 ) { int N = arr1 . Count ; List < double > median = new List < double > ( ) ; if ( ( N & 1 ) != 0 ) { median . Add ( arr1 [ N \\/ 2 ] * 1.0 ) ; } else { median . Add ( ( arr1 [ N \\/ 2 ] + arr1 [ ( N - 1 ) \\/ 2 ] ) \\/ 2.0 ) ; } foreach ( int x in arr2 ) { int it = arr1 . IndexOf ( x ) ; arr1 . RemoveAt ( it ) ; N -- ; if ( ( N & 1 ) != 0 ) { median . Add ( arr1 [ N \\/ 2 ] * 1.0 ) ; } else { median . Add ( ( arr1 [ N \\/ 2 ] + arr1 [ ( N - 1 ) \\/ 2 ] ) \\/ 2.0 ) ; } } for ( int i = 0 ; i < median . Count - 1 ; i ++ ) { Console . Write ( median [ i + 1 ] - median [ i ] + \\\" ▁ \\\" ) ; } } static void Main ( ) { List < int > arr1 = new List < int > ( new int [ ] { 2 , 4 , 6 , 8 , 10 } ) ; List < int > arr2 = new List < int > ( new int [ ] { 4 , 6 } ) ; medianChange ( arr1 , arr2 ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find a point that lies inside exactly K given squares | C ++ implementation of the approach ; Driver Program to test above function\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int PointInKSquares ( int n , int a [ ] , int k ) { sort ( a , a + n ) ; return a [ n - k ] ; } int main ( ) { int k = 2 ; int a [ ] = { 1 , 2 , 3 , 4 } ; int n = sizeof ( a ) \\/ sizeof ( a [ 0 ] ) ; int x = PointInKSquares ( n , a , k ) ; cout << \\\" ( \\\" << x << \\\" , ▁ \\\" << x << \\\" ) \\\" ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the count of coins of each type from the given ratio | function to calculate coin ; Converting each of them in rupees . As we are given totalRupees = 1800 ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function coin ( $ totalRupees , $ X , $ Y , $ Z ) { $ one = 0 ; $ fifty = 0 ; $ twentyfive = 0 ; $ result = 0 ; $ total = 0 ; $ one = $ X * 1 ; $ fifty = ( ( $ Y * 1 ) \\/ 2.0 ) ; $ twentyfive = ( ( $ Z * 1 ) \\/ 4.0 ) ; $ total = $ one + $ fifty + $ twentyfive ; $ result = ( ( $ totalRupees ) \\/ $ total ) ; return $ result ; } $ totalRupees = 1800 ; $ X = 1 ; $ Y = 2 ; $ Z = 4 ; $ Rupees = coin ( $ totalRupees , $ X , $ Y , $ Z ) ; echo \\\"1 ▁ rupess ▁ coins ▁ = ▁ \\\" , $ Rupees * 1 , \\\" \\n \\\" ; echo \\\"50 ▁ paisa ▁ coins ▁ = ▁ \\\" , $ Rupees * 2 , \\\" \\n \\\" ; echo \\\"25 ▁ paisa ▁ coins ▁ = ▁ \\\" , $ Rupees * 4 , \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count of cyclic permutations having XOR with other binary string as 0 | Implementation of Z - algorithm for linear time pattern searching ; Function to get the count of the cyclic permutations of b that given 0 when XORed with a ; concatenate b with b ; new b now contains all the cyclic permutations of old b as it 's sub-strings ; concatenate pattern with text ; Fill z array used in Z algorithm ; pattern occurs at index i since z value of i equals pattern length ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def compute_z ( s , z ) :\\n\\tl = 0\\n\\tr = 0\\n\\tn = len ( s )\\n\\tfor i in range ( 1 , n , 1 ) :\\n\\t\\tif ( i > r ) :\\n\\t\\t\\tl = i\\n\\t\\t\\tr = i\\n\\t\\t\\twhile ( r < n and s [ r - l ] == s [ r ] ) :\\n\\t\\t\\t\\tr += 1\\n\\t\\t\\tz [ i ] = r - l\\n\\t\\t\\tr -= 1\\n\\t\\telse :\\n\\t\\t\\tk = i - l\\n\\t\\t\\tif ( z [ k ] < r - i + 1 ) :\\n\\t\\t\\t\\tz [ i ] = z [ k ]\\n\\t\\t\\telse :\\n\\t\\t\\t\\tl = i\\n\\t\\t\\t\\twhile ( r < n and s [ r - l ] == s [ r ] ) :\\n\\t\\t\\t\\t\\tr += 1\\n\\t\\t\\t\\tz [ i ] = r - l\\n\\t\\t\\t\\tr -= 1\\ndef countPermutation ( a , b ) :\\n\\tb = b + b\\n\\tb = b [ 0 : len ( b ) - 1 ]\\n\\tans = 0\\n\\ts = a + \\\" $ \\\" + b\\n\\tn = len ( s )\\n\\tz = [ 0 for i in range ( n ) ]\\n\\tcompute_z ( s , z )\\n\\tfor i in range ( 1 , n , 1 ) :\\n\\t\\tif ( z [ i ] == len ( a ) ) :\\n\\t\\t\\tans += 1\\n\\treturn ans\\nif __name__ == ' _ _ main _ _ ' :\\n\\ta = \\\"101\\\"\\n\\tb = \\\"101\\\"\\n\\tprint ( countPermutation ( a , b ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Print K 'th element in spiral form of matrix | Java program for Kth element in spiral form of matrix ; function for Kth element ; Element is in first row ; Element is in last column ; Element is in last row ; Element is in first column ; Recursion for sub - matrix . & A [ 1 ] [ 1 ] is address to next inside sub matrix . ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int MAX = 100 ; static int findK ( int A [ ] [ ] , int i , int j , int n , int m , int k ) { if ( n < 1 m < 1 ) return - 1 ; if ( k <= m ) return A [ i + 0 ] [ j + k - 1 ] ; if ( k <= ( m + n - 1 ) ) return A [ i + ( k - m ) ] [ j + m - 1 ] ; if ( k <= ( m + n - 1 + m - 1 ) ) return A [ i + n - 1 ] [ j + m - 1 - ( k - ( m + n - 1 ) ) ] ; if ( k <= ( m + n - 1 + m - 1 + n - 2 ) ) return A [ i + n - 1 - ( k - ( m + n - 1 + m - 1 ) ) ] [ j + 0 ] ; return findK ( A , i + 1 , j + 1 , n - 2 , m - 2 , k - ( 2 * n + 2 * m - 4 ) ) ; } public static void main ( String args [ ] ) { int a [ ] [ ] = { { 1 , 2 , 3 , 4 , 5 , 6 } , { 7 , 8 , 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 , 17 , 18 } } ; int k = 17 ; System . out . println ( findK ( a , 0 , 0 , 3 , 6 , k ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count ways to obtain given sum by repeated throws of a dice | Function to find the number of ways to get the sum N with throw of dice ; Base case ; Stores the count of total number of ways to get sum N ; Recur for all 6 states ; Return answer ; Driver Code ; Function call\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findWays ( N ) :\\n\\tif ( N == 0 ) :\\n\\t\\treturn 1\\n\\tcnt = 0\\n\\tfor i in range ( 1 , 7 ) :\\n\\t\\tif ( N - i >= 0 ) :\\n\\t\\t\\tcnt = cnt + findWays ( N - i )\\n\\treturn cnt\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 4\\n\\tprint ( findWays ( N ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimum characters required to make a password strong | Python3 program to find minimum number of characters required to be added to make a password strong ; Function to count minimum number of characters ; Create the patterns to search digit , upper case alphabet , lower case alphabet and special character ; If no digits are present ; If no upper case alphabet is present ; If no lower case alphabet is present ; If no special character is is present ; Check if the string length after adding the required characters is less than 8 ; Add the number of characters to be added ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import re\\ndef countCharacters ( password ) :\\n\\tcount = 0\\n\\tdigit = re . compile ( \\\" ( \\\\\\\\d ) \\\" )\\n\\tupper = re . compile ( \\\" ( [ A - Z ] ) \\\" )\\n\\tlower = re . compile ( \\\" ( [ a - z ] ) \\\" )\\n\\tspChar = re . compile ( \\\" ( \\\\\\\\W ) \\\" )\\n\\tif ( not re . search ( digit , password ) ) :\\n\\t\\tcount += 1\\n\\tif ( not re . search ( upper , password ) ) :\\n\\t\\tcount += 1\\n\\tif ( not re . search ( lower , password ) ) :\\n\\t\\tcount += 1\\n\\tif ( not re . search ( spChar , password ) ) :\\n\\t\\tcount += 1\\n\\tif ( ( count + len ( password ) ) < 8 ) :\\n\\t\\tcount = count + 8 - ( count + len ( password ) )\\n\\treturn count\\npassword1 = \\\" Geeksforgeeks \\\"\\nprint ( countCharacters ( password1 ) )\\npassword2 = \\\" Geeks1\\\"\\nprint ( countCharacters ( password2 ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find the Nth Hogben Numbers | Function returns N - th Hogben Number ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def HogbenNumber ( a ) :\\n\\tp = ( pow ( a , 2 ) - a + 1 )\\n\\treturn p\\nN = 10\\nprint ( HogbenNumber ( N ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Number of digits in the product of two numbers | JAVA Code for Number of digits in the product of two numbers ; function to count number of digits in the product of two numbers ; if either of the number is 0 , then product will be 0 ; required count of digits ; Driver program to test above function\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { public static int countDigits ( int a , int b ) { if ( a == 0 b == 0 ) return 1 ; return ( int ) Math . floor ( Math . log10 ( Math . abs ( a ) ) + Math . log10 ( Math . abs ( b ) ) ) + 1 ; } public static void main ( String [ ] args ) { int a = 33 ; int b = - 24 ; System . out . print ( countDigits ( a , b ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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\\\"\\nHow can the above be solved 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 ▁ Obtainable ▁ Value ▁ is ▁ % dn \\\" , cutRod ( arr , size ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Threaded Binary Search Tree | Deletion | 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 .\\\"\\nSolution in Java:\",\"targets\":\"static Node caseB ( Node root , Node par , Node ptr ) { Node child ; if ( ptr . lthread == false ) child = ptr . left ; else child = ptr . right ; if ( par == null ) root = child ; else if ( ptr == par . left ) par . left = child ; else par . right = child ; Node s = inSucc ( ptr ) ; Node p = inPred ( ptr ) ; if ( ptr . lthread == false ) p . right = s ; else { if ( ptr . rthread == false ) s . left = p ; } return root ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find the light bulb with maximum glowing time | C ++ program for the above approach ; Function to find the bulb having maximum glow ; Initialize variables ; Traverse the array consisting of glowing time of the bulbs ; For 1 st bulb ; Calculate the glowing time ; Update the maximum glow ; Find lexicographically largest bulb ; Bulb with maximum time ; Return the resultant bulb ; Driver Code ; Function call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; char longestLastingBulb ( vector < int > onTime , string s ) { char ans ; int n = onTime . size ( ) ; int maxDur = INT_MIN ; int maxPos = INT_MIN ; int currentDiff = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == 0 ) { currentDiff = onTime [ i ] ; maxDur = currentDiff ; maxPos = i ; } else { currentDiff = onTime [ i ] - onTime [ i - 1 ] ; if ( maxDur < currentDiff ) { maxDur = currentDiff ; maxPos = i ; } else { if ( maxDur == currentDiff ) { char one = s [ i ] ; char two = s [ maxPos ] ; if ( one > two ) { maxDur = currentDiff ; maxPos = i ; } } } } } ans = s [ maxPos ] ; return ans ; } int main ( ) { string S = \\\" spuda \\\" ; vector < int > arr = { 12 , 23 , 36 , 46 , 62 } ; cout << longestLastingBulb ( arr , S ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"How to check if a given array represents a Binary Heap ? | Java program to check whether a given array represents a max - heap or not ; Returns true if arr [ i . . n - 1 ] represents a max - heap ; If a leaf node ; If an internal node and is greater than its children , and same is recursively true for the children ; Driver program\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static boolean isHeap ( int arr [ ] , int i , int n ) { if ( i >= ( n - 2 ) \\/ 2 ) { return true ; } if ( arr [ i ] >= arr [ 2 * i + 1 ] && arr [ i ] >= arr [ 2 * i + 2 ] && isHeap ( arr , 2 * i + 1 , n ) && isHeap ( arr , 2 * i + 2 , n ) ) { return true ; } return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 90 , 15 , 10 , 7 , 12 , 2 , 7 , 3 } ; int n = arr . length - 1 ; if ( isHeap ( arr , 0 , 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\":\"\\\"Final state of the string after modification | Function to return final positions of the boxes ; Populate forces going from left to right ; Populate forces going from right to left ; return final state of boxes ; Driver code ; Function call to print answer\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def pushBoxes ( S ) :\\n\\tN = len ( S )\\n\\tforce = [ 0 ] * N\\n\\tf = 0\\n\\tfor i in range ( 0 , N ) :\\n\\t\\tif S [ i ] == ' R ' :\\n\\t\\t\\tf = N\\n\\t\\telif S [ i ] == ' L ' :\\n\\t\\t\\tf = 0\\n\\t\\telse :\\n\\t\\t\\tf = max ( f - 1 , 0 )\\n\\t\\tforce [ i ] += f\\n\\tf = 0\\n\\tfor i in range ( N - 1 , - 1 , - 1 ) :\\n\\t\\tif S [ i ] == ' L ' :\\n\\t\\t\\tf = N\\n\\t\\telif S [ i ] == ' R ' :\\n\\t\\t\\tf = 0\\n\\t\\telse :\\n\\t\\t\\tf = max ( f - 1 , 0 )\\n\\t\\tforce [ i ] -= f\\n\\treturn \\\" \\\" . join ( ' . ' if f == 0 else ' R ' if f > 0 else ' L ' for f in force )\\nS = \\\" . L . R . . . LR . . L . . \\\"\\nprint ( pushBoxes ( S ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimum increment and decrement by K of each pair elements required to make all array elements equal | Function to check if its possible to make all array elements equal or not ; Stores the sum of the array ; Traverse the array ; If sum is divisible by N ; Otherwise , not possible to make all array elements equal ; Given array ; Size of the array\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def arrayElementEqual ( arr , N ) :\\n\\tsum = 0\\n\\tfor i in range ( N ) :\\n\\t\\tsum += arr [ i ]\\n\\tif ( sum % N == 0 ) :\\n\\t\\tprint ( ' Yes ' )\\n\\telse :\\n\\t\\tprint ( \\\" No \\\" )\\narr = [ 1 , 5 , 6 , 4 ]\\nN = len ( arr )\\narrayElementEqual ( arr , N )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Largest Sum Contiguous Subarray | PHP program to print largest contiguous array sum ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function maxSubArraySum ( $ a , $ size ) { $ max_so_far = PHP_INT_MIN ; $ max_ending_here = 0 ; $ start = 0 ; $ end = 0 ; $ s = 0 ; for ( $ i = 0 ; $ i < $ size ; $ i ++ ) { $ max_ending_here += $ a [ $ i ] ; if ( $ max_so_far < $ max_ending_here ) { $ max_so_far = $ max_ending_here ; $ start = $ s ; $ end = $ i ; } if ( $ max_ending_here < 0 ) { $ max_ending_here = 0 ; $ s = $ i + 1 ; } } echo \\\" Maximum ▁ contiguous ▁ sum ▁ is ▁ \\\" . $ max_so_far . \\\" \\n \\\" ; echo \\\" Starting ▁ index ▁ \\\" . $ start . \\\" \\\" . \\n \\t \\t \\t \\\" Ending index \\\" ▁ . ▁ $ end ▁ . ▁ \\\" \\\" } $ a = array ( -2 , -3 , 4 , -1 , -2 , 1 , 5 , -3 ) ; $ n = sizeof ( $ a ) ; $ max_sum = maxSubArraySum ( $ a , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Remove minimum numbers from the array to get minimum OR value | Java 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\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int findMinDel ( int [ ] arr , int n ) { int min_num = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) min_num = Math . min ( arr [ i ] , min_num ) ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] == min_num ) cnt ++ ; return n - cnt ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 3 , 2 } ; int n = arr . length ; System . out . print ( findMinDel ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum score possible for a player by selecting one or two consecutive array elements from given binary array | Java program for the above approach ; Stores the minimum score for each states as map < pair < pos , myturn > , ans > ; Function to find the minimum score after choosing element from array ; Return the stored state ; Base Case ; Player A 's turn ; Find the minimum score ; Store the current state ; Return the result ; Player B 's turn ; Find minimum score ; Store the current state ; Return the result ; Function that finds the minimum penality after choosing element from the given binary array ; Starting position of choosing element from array ; 0 denotes player A turn 1 denotes player B turn ; Function Call ; Function to print the answer ; Minimum penalty ; Calculate sum of all arr elements ; Print the minimum score ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { static class R { int x , y ; public R ( int x , int y ) { this . x = x ; this . y = y ; } } static HashMap < R , Integer > m = new HashMap < > ( ) ; public static int findMinimum ( int [ ] arr , int N , int pos , int turn ) { R x = new R ( pos , turn ) ; if ( m . containsKey ( x ) ) { return m . get ( x ) ; } if ( pos >= N - 1 ) { return 0 ; } if ( turn == 0 ) { int ans = Math . min ( findMinimum ( arr , N , pos + 1 , 1 ) + arr [ pos ] , findMinimum ( arr , N , pos + 2 , 1 ) + arr [ pos ] + arr [ pos + 1 ] ) ; R v = new R ( pos , turn ) ; m . put ( v , ans ) ; return ans ; } if ( turn != 0 ) { int ans = Math . min ( findMinimum ( arr , N , pos + 1 , 0 ) , findMinimum ( arr , N , pos + 2 , 0 ) ) ; R v = new R ( pos , turn ) ; m . put ( v , ans ) ; return ans ; } return 0 ; } public static int countPenality ( int [ ] arr , int N ) { int pos = 0 ; int turn = 0 ; return findMinimum ( arr , N , pos , turn ) + 1 ; } public static void printAnswer ( int [ ] arr , int N ) { int a = countPenality ( arr , N ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } System . out . println ( a ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 1 , 1 , 0 , 1 , 1 , 1 } ; int N = 8 ; printAnswer ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if a Binary Tree is an Even | Tree node ; Function to return new tree node ; Function to check if the tree is even - odd tree ; Stores nodes of each level ; Store the current level of the binary tree ; Traverse until the queue is empty ; Stores the number of nodes present in the current level ; Check if the level is even or odd ; Add the nodes of the next level into the queue ; Increment the level count ; Construct a Binary Tree ; Check if the binary tree is even - odd tree or not\\\"\\nSolution in Javascript:\",\"targets\":\"class Node { constructor ( data ) { this . left = null ; this . right = null ; this . val = data ; } } function newNode ( data ) { let temp = new Node ( data ) ; return temp ; } function isEvenOddBinaryTree ( root ) { if ( root == null ) return true ; let q = [ ] ; q . push ( root ) ; let level = 0 ; while ( q . length > 0 ) { let size = q . length ; for ( let i = 0 ; i < size ; i ++ ) { let node = q [ 0 ] ; q . shift ( ) ; if ( level % 2 == 0 ) { if ( node . val % 2 == 1 ) return false ; } else if ( level % 2 == 1 ) { if ( node . val % 2 == 0 ) return false ; } if ( node . left != null ) { q . push ( node . left ) ; } if ( node . right != null ) { q . push ( node . right ) ; } } level ++ ; } return true ; } let root = null ; root = newNode ( 2 ) ; root . left = newNode ( 3 ) ; root . right = newNode ( 9 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 10 ) ; root . right . right = newNode ( 6 ) ; if ( isEvenOddBinaryTree ( root ) ) { document . write ( \\\" \\\" ) ; } else { document . write ( \\\" \\\" ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program for Area Of Square after N | CPP program to find the area of the square ; Function to calculate area of square after given number of folds ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; double areaSquare ( double side , double fold ) { double area = side * side ; return area * 1.0 \\/ pow ( 2 , fold ) ; } int main ( ) { double side = 4 , fold = 2 ; cout << areaSquare ( side , fold ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Largest number in BST which is less than or equal to N | C # code to find the largest value smaller than or equal to N ; Node structure ; To create new BST Node ; To insert a new node in BST ; if tree is empty return new node ; if key is less then or greater then node value then recur down the tree ; return the ( unchanged ) node pointer ; function to find max value less then N ; Base cases ; If root 's value is smaller, try in right subtree ; If root 's key is greater, return value from left subtree. ; Driver code ; creating following BST 5 \\/ \\\\ 2 12 \\/ \\\\ \\/ \\\\ 1 3 9 21 \\/ \\\\ 19 25\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { class Node { public int key ; public Node left , right ; } static Node newNode ( int item ) { Node temp = new Node ( ) ; temp . key = item ; temp . left = null ; temp . right = null ; return temp ; } static Node insert ( Node node , int key ) { if ( node == null ) return newNode ( key ) ; if ( key < node . key ) node . left = insert ( node . left , key ) ; else if ( key > node . key ) node . right = insert ( node . right , key ) ; return node ; } static int findMaxforN ( Node root , int N ) { if ( root == null ) return - 1 ; if ( root . key == N ) return N ; else if ( root . key < N ) { int k = findMaxforN ( root . right , N ) ; if ( k == - 1 ) return root . key ; else return k ; } else if ( root . key > N ) return findMaxforN ( root . left , N ) ; return - 1 ; } public static void Main ( String [ ] args ) { int N = 4 ; Node root = null ; root = insert ( root , 25 ) ; insert ( root , 2 ) ; insert ( root , 1 ) ; insert ( root , 3 ) ; insert ( root , 12 ) ; insert ( root , 9 ) ; insert ( root , 21 ) ; insert ( root , 19 ) ; insert ( root , 25 ) ; Console . WriteLine ( findMaxforN ( root , N ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Compute maximum of the function efficiently over all sub | JavaScript implementation of the above approach ; Function to return maximum sum of a sub - array ; Function to return maximum value of function F ; Compute arrays B [ ] and C [ ] ; Find maximum sum sub - array of both of the arrays and take maximum among them ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"const MAX = 100005 ; function kadaneAlgorithm ( ar , n ) { let sum = 0 , maxSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += ar [ i ] ; if ( sum < 0 ) sum = 0 ; maxSum = Math . max ( maxSum , sum ) ; } return maxSum ; } function maxFunction ( arr , n ) { let b = new Array ( MAX ) , c = new Array ( MAX ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( i & 1 ) { b [ i ] = Math . abs ( arr [ i + 1 ] - arr [ i ] ) ; c [ i ] = - b [ i ] ; } else { c [ i ] = Math . abs ( arr [ i + 1 ] - arr [ i ] ) ; b [ i ] = - c [ i ] ; } } let ans = kadaneAlgorithm ( b , n - 1 ) ; ans = Math . max ( ans , kadaneAlgorithm ( c , n - 1 ) ) ; return ans ; } let arr = [ 1 , 5 , 4 , 7 ] ; let n = arr . length ; document . write ( maxFunction ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Perfect Sum Problem | Function to print the subsets whose sum is equal to the given target K ; Create the new array with length equal to array set [ ] to create binary array as per n ( decimal number ) ; Convert the array into binary array ; Calculate the sum of this subset ; Check whether sum is equal to target if it is equal , then print the subset ; Function to find the subsets with sum K ; Calculate the total no . of subsets ; Run loop till total no . of subsets and call the function for each subset ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function sumSubsets ( set , n , target ) { let x = new Array ( set . length ) ; let j = set . length - 1 ; while ( n > 0 ) { x [ j ] = n % 2 ; n = Math . floor ( n \\/ 2 ) ; j -- ; } let sum = 0 ; for ( let i = 0 ; i < set . length ; i ++ ) if ( x [ i ] == 1 ) sum = sum + set [ i ] ; if ( sum == target ) { document . write ( \\\" \\\" ) ; for ( let i = 0 ; i < set . length ; i ++ ) if ( x [ i ] == 1 ) document . write ( set [ i ] + \\\" \\\" ) ; document . write ( \\\" \\\" ) ; } } function findSubsets ( arr , K ) { let x = Math . pow ( 2 , arr . length ) ; for ( let i = 1 ; i < x ; i ++ ) sumSubsets ( arr , i , K ) ; } let arr = [ 5 , 10 , 12 , 13 , 15 , 18 ] ; let K = 30 ; findSubsets ( arr , K ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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 ▁ seed ▁ exists \\n \\\" ; return ; } for ( $ i = 0 ; $ i < count ( $ res ) ; $ i ++ ) echo $ res [ $ i ] . \\\" ▁ \\\" ; } $ n = 138 ; findSeed ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find the smallest number whose sum of digits is N | Function to get sum of digits ; Function to find the smallest number whose sum of digits is also N ; Checking if number has sum of digits = N ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function getSum ( n ) { let sum = 0 ; while ( n != 0 ) { sum = sum + n % 10 ; n = Math . floor ( n \\/ 10 ) ; } return sum ; } function smallestNumber ( N ) { let i = 1 ; while ( 1 ) { if ( getSum ( i ) == N ) { document . write ( i ) ; break ; } i ++ ; } } let N = 10 ; smallestNumber ( N ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count of unordered pairs ( x , y ) of Array which satisfy given equation | Java Program to find the number of unordered pairs ( x , y ) which satisfy the given equation for the array ; Return the number of unordered pairs satisfying the conditions ; ans stores the number of unordered pairs ; Making each value of array to positive ; Sort the array ; For each index calculating the right boundary for the unordered pairs ; Return the final result ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . Arrays ; class GFG { static int numPairs ( int a [ ] , int n ) { int ans , i , index ; ans = 0 ; for ( i = 0 ; i < n ; i ++ ) a [ i ] = Math . abs ( a [ i ] ) ; Arrays . sort ( a ) ; for ( i = 0 ; i < n ; i ++ ) { index = 2 ; ans += index - i - 1 ; } return ans ; } public static void main ( String [ ] args ) { int a [ ] = new int [ ] { 3 , 6 } ; int n = a . length ; System . out . println ( numPairs ( a , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Print reverse of a string using recursion | Function to print reverse of the passed string ; Driver program to test above function\\\"\\nSolution in Python:\",\"targets\":\"def reverse ( string ) :\\n\\tif len ( string ) == 0 :\\n\\t\\treturn\\n\\ttemp = string [ 0 ]\\n\\treverse ( string [ 1 : ] )\\n\\tprint ( temp , end = ' ' )\\nstring = \\\" Geeks ▁ for ▁ Geeks \\\"\\nreverse ( string )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sort even | Javascript Program to separately sort even - placed and odd placed numbers and place them together in sorted array . ; create evenArr [ ] and oddArr [ ] ; Put elements in oddArr [ ] and evenArr [ ] as per their position ; sort evenArr [ ] in ascending order sort oddArr [ ] in descending order ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function bitonicGenerator ( arr , n ) { let evenArr = [ ] ; let oddArr = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 != 1 ) { evenArr . push ( arr [ i ] ) ; } else { oddArr . push ( arr [ i ] ) ; } } evenArr . sort ( function ( a , b ) { return a - b ; } ) ; oddArr . sort ( function ( a , b ) { return b - a ; } ) ; let i = 0 ; for ( let j = 0 ; j < evenArr . length ; j ++ ) { arr [ i ++ ] = evenArr [ j ] ; } for ( let j = 0 ; j < oddArr . length ; j ++ ) { arr [ i ++ ] = oddArr [ j ] ; } } let arr = [ 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 ] ; let n = arr . length ; bitonicGenerator ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + \\\" \\\" ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program to find the common ratio of three numbers | Utility function ; Function to print a : b : c ; To print the given proportion in simplest form . ; Get the ratios ; Get ratio a : b1 ; Get ratio b2 : c ; Find the ratio a : b : c\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } function solveProportion ( a , b1 , b2 , c ) { let A = a * b2 ; let B = b1 * b2 ; let C = b1 * c ; let gcd = __gcd ( __gcd ( A , B ) , C ) ; document . write ( A \\/ gcd + \\\" \\\" + B \\/ gcd + \\\" \\\" + C \\/ gcd ) ; } let a , b1 , b2 , c ; a = 3 ; b1 = 4 ; b2 = 8 ; c = 9 ; solveProportion ( a , b1 , b2 , c ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sum of Fibonacci Numbers with alternate negatives | 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 ; Get n ; Find the alternating sum\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function calculateAlternateSum ( $ n ) { if ( $ n <= 0 ) return 0 ; $ fibo = array ( ) ; $ fibo [ 0 ] = 0 ; $ fibo [ 1 ] = 1 ; $ sum = pow ( $ fibo [ 0 ] , 2 ) + pow ( $ fibo [ 1 ] , 2 ) ; for ( $ 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 ; } $ n = 8 ; echo ( \\\" Alternating ▁ Fibonacci ▁ Sum ▁ upto ▁ \\\" ) ; echo $ n ; echo \\\" ▁ terms : ▁ \\\" ; echo ( calculateAlternateSum ( $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Probability of A winning the match when individual probabilities of hitting the target given | C # implementation of the approach ; 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 C-Sharp?\",\"targets\":\"using System ; class GFG { public static double getProbability ( int a , int b , int c , int d ) { double p = ( double ) a \\/ ( double ) b ; double q = ( double ) c \\/ ( double ) d ; double ans = p * ( 1 \\/ ( 1 - ( 1 - q ) * ( 1 - p ) ) ) ; return ans ; } public static void Main ( string [ ] args ) { int a = 1 , b = 2 , c = 10 , d = 11 ; Console . Write ( \\\" { 0 : F5 } \\\" , getProbability ( a , b , c , d ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximum sum from a tree with adjacent levels not allowed | C # code for max sum with adjacent levels not allowed ; Tree node class for Binary Tree representation ; Recursive function to find the maximum sum returned for a root node and its grandchildren ; Returns maximum sum with adjacent levels not allowed . This function mainly uses getSumAlternate ( ) ; We compute sum of alternate levels starting first level and from second level . And return maximum of two values . ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public static int getSumAlternate ( Node root ) { if ( root == null ) return 0 ; int sum = root . data ; if ( root . left != null ) { sum += getSum ( root . left . left ) ; sum += getSum ( root . left . right ) ; } if ( root . right != null ) { sum += getSum ( root . right . left ) ; sum += getSum ( root . right . right ) ; } return sum ; } public static int getSum ( Node root ) { if ( root == null ) return 0 ; return Math . Max ( getSumAlternate ( root ) , ( getSumAlternate ( root . left ) + getSumAlternate ( root . right ) ) ) ; } public static void Main ( ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . right . left = new Node ( 4 ) ; root . right . left . right = new Node ( 5 ) ; root . right . left . right . left = new Node ( 6 ) ; Console . WriteLine ( getSum ( root ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"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 ▁ 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\":\"\\\"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\\\"\\nSolution 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 ▁ appears ▁ more ▁ than ▁ % d ▁ times ▁ in ▁ arr [ ] \\\" , x , n \\/ 2 ) ; else printf ( \\\" % d ▁ does ▁ not ▁ appear ▁ more ▁ than ▁ % d ▁ times ▁ in ▁ arr [ ] \\\" , x , n \\/ 2 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Shell | Function to swap two elements ; Function to sort arr [ ] using Shell Metzner sort ; Declare variables ; Set initial step size to the size of the array ; Step size decreases by half each time ; k is the upper limit for j ; j is the starting point ; i equals to smaller value ; l equals to larger value ; Compare and swap arr [ i ] with arr [ l ] ; Decrease smaller value by step size ; Increment the lower limit of i ; Function to print the contents of an array ; Driver code ; Sort the array using Shell Metzner Sort ; Print the sorted array\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function swap ( arr , i , j ) { let temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } function sort_shell_metzner ( arr , n ) { let i , j , k , l , m , temp ; m = n ; while ( m > 0 ) { m = Math . floor ( m \\/ 2 ) ; k = n - m ; j = 0 ; do { i = j ; do { l = i + m ; if ( l < n && arr [ i ] > arr [ l ] ) { swap ( arr , i , l ) ; i -= m ; } else { break ; } } while ( i >= 0 ) ; j ++ ; } while ( j <= k ) ; } } function printArray ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + \\\" \\\" ) ; } } let arr = [ 0 , - 2 , 8 , 5 , 1 ] ; let n = arr . length ; sort_shell_metzner ( arr , n ) ; printArray ( arr , n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if a given circle lies completely inside the ring formed by two concentric circles | Function to check if circle lies in the ring ; distance between center of circle center of concentric circles ( origin ) using Pythagoras theorem ; Condition to check if circle is strictly inside the ring ; Both circle with radius ' r ' and ' R ' have center ( 0 , 0 )\\\"\\nSolution in php:\",\"targets\":\"< ? php function checkcircle ( $ r , $ R , $ r1 , $ x1 , $ y1 ) { $ dis = sqrt ( $ x1 * $ x1 + $ y1 * $ y1 ) ; return ( $ dis - $ r1 >= $ R && $ dis + $ r1 <= $ r ) ; } $ r = 8 ; $ R = 4 ; $ r1 = 2 ; $ x1 = 6 ; $ y1 = 0 ; if ( checkcircle ( $ r , $ R , $ r1 , $ x1 , $ y1 ) ) 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\":\"\\\"Minimum swaps required to make a binary string divisible by 2 ^ k | Java implementation of the approach ; Function to return the minimum swaps required ; To store the final answer ; To store the count of one and zero ; Loop from end of the string ; If s [ i ] = 1 ; If s [ i ] = 0 ; If c_zero = k ; If the result can 't be achieved ; Return the final answer ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int findMinSwaps ( String s , int k ) { int ans = 0 ; int c_one = 0 , c_zero = 0 ; for ( int i = s . length ( ) - 1 ; i >= 0 ; i -- ) { if ( s . charAt ( i ) == '1' ) c_one ++ ; if ( s . charAt ( i ) == '0' ) { c_zero ++ ; ans += c_one ; } if ( c_zero == k ) break ; } if ( c_zero < k ) return - 1 ; return ans ; } public static void main ( String [ ] args ) { String s = \\\"100111\\\" ; int k = 2 ; System . out . println ( findMinSwaps ( s , k ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Summation of GCD of all the pairs up to N | PHP approach of finding sum of GCD of all pairs ; phi [ i ] stores euler totient function for i result [ j ] stores result for value j ; Precomputation of phi [ ] numbers . Refer link for details : https : goo . gl \\/ LUqdtY ; Refer https : goo . gl \\/ LUqdtY ; Precomputes result for all numbers till MAX ; Precompute all phi value ; Iterate throght all the divisors of i . ; Add summation of previous calculated sum ; Function to calculate sum of all the GCD pairs\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ MAX = 100001 ; $ phi = array_fill ( 0 , $ MAX , 0 ) ; $ result = array_fill ( 0 , $ MAX , 0 ) ; function computeTotient ( ) { global $ MAX , $ phi ; $ phi [ 1 ] = 1 ; for ( $ i = 2 ; $ i < $ MAX ; $ i ++ ) { if ( ! $ phi [ $ i ] ) { $ phi [ $ i ] = $ i - 1 ; for ( $ j = ( $ i << 1 ) ; $ j < $ MAX ; $ j += $ i ) { if ( ! $ phi [ $ j ] ) $ phi [ $ j ] = $ j ; $ phi [ $ j ] = ( $ phi [ $ j ] \\/ $ i ) * ( $ i - 1 ) ; } } } } function sumOfGcdPairs ( ) { global $ MAX , $ phi , $ result ; computeTotient ( ) ; for ( $ i = 1 ; $ i < $ MAX ; ++ $ i ) { for ( $ j = 2 ; $ i * $ j < $ MAX ; ++ $ j ) $ result [ $ i * $ j ] += $ i * $ phi [ $ j ] ; } for ( $ i = 2 ; $ i < $ MAX ; $ i ++ ) $ result [ $ i ] += $ result [ $ i - 1 ] ; } sumOfGcdPairs ( ) ; $ N = 4 ; echo \\\" Summation ▁ of ▁ \\\" . $ N . \\\" ▁ = ▁ \\\" . $ result [ $ N ] . \\\" \\n \\\" ; $ N = 12 ; echo \\\" Summation ▁ of ▁ \\\" . $ N . \\\" ▁ = ▁ \\\" . $ result [ $ N ] . \\\" \\n \\\" ; $ N = 5000 ; echo \\\" Summation ▁ of ▁ \\\" . $ N . \\\" ▁ = ▁ \\\" . $ result [ $ N ] . \\\" \\n \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Assembly Line Scheduling | DP | A C # program to find minimum possible time by the car chassis to complete ; Utility function to find minimum of two numbers ; time taken to leave first station in line 1 ; time taken to leave first station in line 2 ; Fill tables T1 [ ] and T2 [ ] using the above given recursive relations ; Consider exit times and retutn minimum ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int NUM_STATION = 4 ; static int min ( int a , int b ) { return a < b ? a : b ; } static int carAssembly ( int [ , ] a , int [ , ] t , int [ ] e , int [ ] x ) { int [ ] T1 = new int [ NUM_STATION ] ; int [ ] T2 = new int [ NUM_STATION ] ; int i ; T1 [ 0 ] = e [ 0 ] + a [ 0 , 0 ] ; T2 [ 0 ] = e [ 1 ] + a [ 1 , 0 ] ; for ( i = 1 ; i < NUM_STATION ; ++ i ) { T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 , i ] , T2 [ i - 1 ] + t [ 1 , i ] + a [ 0 , i ] ) ; T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 , i ] , T1 [ i - 1 ] + t [ 0 , i ] + a [ 1 , i ] ) ; } return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ; } public static void Main ( ) { int [ , ] a = { { 4 , 5 , 3 , 2 } , { 2 , 10 , 1 , 4 } } ; int [ , ] t = { { 0 , 7 , 4 , 5 } , { 0 , 9 , 2 , 8 } } ; int [ ] e = { 10 , 12 } ; int [ ] x = { 18 , 7 } ; Console . Write ( carAssembly ( a , t , e , x ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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 ▁ number ▁ of ▁ groups ▁ are ▁ % 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\":\"\\\"Sum of numbers from 1 to N which are divisible by 3 or 4 | C # program to find 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 C#:\",\"targets\":\"using System ; class GFG { static int sum ( int N ) { int 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 ; } public static void Main ( ) { int N = 20 ; Console . WriteLine ( sum ( 12 ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Reverse String according to the number of words | C ++ program to reverse string according to the number of words ; Reverse the letters of the word ; Temporary variable to store character ; Swapping the first and last character ; This function forms the required string ; Checking the number of words present in string to reverse ; Reverse the letter of the words ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void reverse ( char str [ ] , int start , int end ) { char temp ; while ( start <= end ) { temp = str [ start ] ; str [ start ] = str [ end ] ; str [ end ] = temp ; start ++ ; end -- ; } } void reverseletter ( char str [ ] , int start , int end ) { int wstart , wend ; for ( wstart = wend = start ; wend < end ; wend ++ ) { if ( str [ wend ] == ' ▁ ' ) continue ; while ( str [ wend ] != ' ▁ ' && wend <= end ) wend ++ ; wend -- ; reverse ( str , wstart , wend ) ; } } int main ( ) { char str [ 1000 ] = \\\" Ashish ▁ Yadav ▁ Abhishek ▁ Rajput ▁ Sunil ▁ Pundir \\\" ; reverseletter ( str , 0 , strlen ( str ) - 1 ) ; cout << str ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Sort a Bitonic Array | C ++ program for the above approach ; Function to Sort a Bitonic array in constant space ; Initialize the value of k ; In each iteration compare elements k distance apart and swap if they are not in order ; k is reduced to half after every iteration ; Print the array elements ; Driver Code ; Given array arr [ ] ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void sortArr ( int a [ ] , int n ) { int i , k ; k = ( int ) log2 ( n ) ; k = pow ( 2 , k ) ; while ( k > 0 ) { for ( i = 0 ; i + k < n ; i ++ ) if ( a [ i ] > a [ i + k ] ) swap ( a [ i ] , a [ i + k ] ) ; k = k \\/ 2 ; } for ( i = 0 ; i < n ; i ++ ) { cout << a [ i ] << \\\" ▁ \\\" ; } } int main ( ) { int arr [ ] = { 5 , 20 , 30 , 40 , 36 , 33 , 25 , 15 , 10 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; sortArr ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find pairs in array whose sums already exist in array | A simple C # program to find pair whose sum already exists in array ; Function to find pair whose sum exists in arr [ ] ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GFG { static void findPair ( int [ ] arr , int n ) { bool found = false ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { if ( arr [ i ] + arr [ j ] == arr [ k ] ) { Console . WriteLine ( arr [ i ] + \\\" ▁ \\\" + arr [ j ] ) ; found = true ; } } } } if ( found == false ) Console . WriteLine ( \\\" Not ▁ exist \\\" ) ; } static public void Main ( String [ ] args ) { int [ ] arr = { 10 , 4 , 8 , 13 , 5 } ; int n = arr . Length ; findPair ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"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\":\"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 ▁ of ▁ no . ▁ is ▁ % d \\\" , reversDigits ( num ) ) ; getchar ( ) ; 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 program to test getParity ( )\\\"\\nSolution 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 ▁ of ▁ no ▁ % d ▁ = ▁ % s \\\" , n , ( getParity ( n ) ? \\\" odd \\\" : \\\" even \\\" ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Interesting facts about Fibonacci numbers | C # program to demonstrate that Fibonacci numbers that are divisible by their indexes have indexes as either power of 5 or multiple of 12. ; storing Fibonacci numbers\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int MAX = 100 ; static void Main ( ) { long [ ] arr = new long [ MAX ] ; arr [ 0 ] = 0 ; arr [ 1 ] = 1 ; for ( int i = 2 ; i < MAX ; i ++ ) arr [ i ] = arr [ i - 1 ] + arr [ i - 2 ] ; Console . Write ( \\\" Fibonacci ▁ numbers ▁ divisible ▁ by ▁ \\\" + \\\" their ▁ indexes ▁ are ▁ : \\n \\\" ) ; for ( int i = 1 ; i < MAX ; i ++ ) if ( arr [ i ] % i == 0 ) System . Console . Write ( i + \\\" ▁ \\\" ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Print the middle nodes of each level of a Binary Tree | Structure Node of Binary Tree ; Function to create a new node ; Return the created node ; Function that performs the DFS traversal on Tree to store all the nodes at each level in map M ; Base Case ; Push the current level node ; Left Recursion ; Right Recursion ; Function that print all the middle nodes for each level in Binary Tree ; Stores all node in each level ; Perform DFS traversal ; Traverse the map M ; Get the size of vector ; For odd number of elements ; Print ( M \\/ 2 ) th Element ; Otherwise ; Print ( M \\/ 2 ) th and ( M \\/ 2 + 1 ) th Element ; Driver Code ; Given Tree ; Function Call\\\"\\nSolution in Python:\",\"targets\":\"class node :\\n\\tdef __init__ ( self , data ) :\\n\\t\\tself . data = data\\n\\t\\tself . left = None\\n\\t\\tself . right = None\\ndef newnode ( d ) :\\n\\ttemp = node ( d )\\n\\treturn temp\\ndef dfs ( root , l , M ) :\\n\\tif ( root == None ) :\\n\\t\\treturn\\n\\tif l not in M :\\n\\t\\tM [ l ] = [ ]\\n\\tM [ l ] . append ( root . data )\\n\\tdfs ( root . left , l + 1 , M )\\n\\tdfs ( root . right , l + 1 , M )\\ndef printMidNodes ( root ) :\\n\\tM = dict ( )\\n\\tdfs ( root , 0 , M )\\n\\tfor it in M . values ( ) :\\n\\t\\tsize = len ( it )\\n\\t\\tif ( size & 1 ) :\\n\\t\\t\\tprint ( it [ ( size - 1 ) \\/\\/ 2 ] )\\n\\t\\telse :\\n\\t\\t\\tprint ( str ( it [ ( size - 1 ) \\/\\/ 2 ] ) + ' ▁ ' + str ( it [ ( size - 1 ) \\/\\/ 2 + 1 ] ) )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\troot = newnode ( 1 )\\n\\troot . left = newnode ( 2 )\\n\\troot . right = newnode ( 3 )\\n\\troot . left . left = newnode ( 4 )\\n\\troot . left . right = newnode ( 5 )\\n\\troot . left . right . left = newnode ( 11 )\\n\\troot . left . right . right = newnode ( 6 )\\n\\troot . left . right . right . left = newnode ( 7 )\\n\\troot . left . right . right . right = newnode ( 9 )\\n\\troot . right . left = newnode ( 10 )\\n\\troot . right . right = newnode ( 8 )\\n\\tprintMidNodes ( root )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count numbers having GCD with N equal to the number itself | Function to count numbers whose GCD with N is the number itself ; Stores the count of factors of N ; Iterate over the range [ 1 , sqrt ( N ) ] ; If i is divisible by i ; Increment count ; Avoid counting the same factor twice ; Return the resultant count ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def countNumbers ( N ) :\\n\\tcount = 0\\n\\tfor i in range ( 1 , N + 1 ) :\\n\\t\\tif i * i > N :\\n\\t\\t\\tbreak\\n\\t\\tif ( N % i == 0 ) :\\n\\t\\t\\tcount += 1\\n\\t\\t\\tif ( N \\/\\/ i != i ) :\\n\\t\\t\\t\\tcount += 1\\n\\treturn count\\nif __name__ == ' _ _ main _ _ ' :\\n\\tN = 10\\n\\tprint ( countNumbers ( N ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Date after adding given number of days to the given date | Return if year is leap year or not . ; Given a date , returns number of days elapsed from the beginning of the current year ( 1 stjan ) . ; Given a year and days elapsed in it , finds date by storing results in d and m . ; Add x days to the given date . ; y2 is going to store result year and offset2 is going to store offset days in result year . ; x may store thousands of days . We find correct year and offset in the year . ; Find values of day and month from offset of result year . ; Driven Program\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def isLeap ( y ) :\\n\\tif ( y % 100 != 0 and y % 4 == 0 or y % 400 == 0 ) :\\n\\t\\treturn True\\n\\treturn False\\ndef offsetDays ( d , m , y ) :\\n\\toffset = d\\n\\tswitcher = { 10 : 30 , 9 : 31 , 8 : 30 , 7 : 31 , 6 : 31 , 5 : 30 , 4 : 31 , 3 : 30 , 2 : 31 , 1 : 28 , 0 : 31 }\\n\\tif ( isLeap ( y ) and m > 1 ) :\\n\\t\\toffset += 1\\n\\toffset += switcher . get ( m )\\n\\treturn offset\\ndef revoffsetDays ( offset , y , d , m ) :\\n\\tmonth = [ 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ]\\n\\tif ( isLeap ( y ) ) :\\n\\t\\tmonth [ 2 ] = 29\\n\\tfor i in range ( 1 , 13 ) :\\n\\t\\tif ( offset <= month [ i ] ) :\\n\\t\\t\\tbreak\\n\\t\\toffset = offset - month [ i ]\\n\\td [ 0 ] = offset\\n\\tm [ 0 ] = i + 1\\ndef addDays ( d1 , m1 , y1 , x ) :\\n\\toffset1 = offsetDays ( d1 , m1 , y1 )\\n\\tif isLeap ( y1 ) :\\n\\t\\tremDays = 366 - offset1\\n\\telse :\\n\\t\\tremDays = 365 - offset1\\n\\tif ( x <= remDays ) :\\n\\t\\ty2 = y1\\n\\t\\toffset2 = offset1 + x\\n\\telse :\\n\\t\\tx -= remDays\\n\\t\\ty2 = y1 + 1\\n\\t\\tif isLeap ( y2 ) :\\n\\t\\t\\ty2days = 366\\n\\t\\telse :\\n\\t\\t\\ty2days = 365\\n\\t\\twhile ( x >= y2days ) :\\n\\t\\t\\tx -= y2days\\n\\t\\t\\ty2 += 1\\n\\t\\t\\tif isLeap ( y2 ) :\\n\\t\\t\\t\\ty2days = 366\\n\\t\\t\\telse :\\n\\t\\t\\t\\ty2days = 365\\n\\t\\toffset2 = x\\n\\tm2 = [ 0 ]\\n\\td2 = [ 0 ]\\n\\trevoffsetDays ( offset2 , y2 , d2 , m2 )\\n\\tprint ( \\\" d2 ▁ = ▁ \\\" , * d2 , \\\" , ▁ m2 ▁ = ▁ \\\" , * m2 , \\\" , ▁ y2 ▁ = ▁ \\\" , y2 , sep = \\\" \\\" )\\nd = 14\\nm = 3\\ny = 2015\\nx = 366\\naddDays ( d , m , y , x )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Distinct powers of a number N such that the sum is equal to K | C ++ implementation to find out the powers of N that add upto K ; Initializing the PowerArray with all 0 's ; Function to find the powers of N that add up to K ; Initializing the counter ; Executing the while loop until K is greater than 0 ; If K % N == 1 , then the power array is incremented by 1 ; Checking if any power is occurred more than once ; For any other value , the sum of powers cannot be added up to K ; Printing the powers of N that sum up to K ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int b [ 50 ] = { 0 } ; int PowerArray ( int n , int k ) { int count = 0 ; while ( k ) { if ( k % n == 0 ) { k \\/= n ; count ++ ; } else if ( k % n == 1 ) { k -= 1 ; b [ count ] ++ ; if ( b [ count ] > 1 ) { cout << -1 ; return 0 ; } } else { cout << -1 ; return 0 ; } } for ( int i = 0 ; i < 50 ; i ++ ) { if ( b [ i ] ) { cout << i << \\\" , ▁ \\\" ; } } } int main ( ) { int N = 3 ; int K = 40 ; PowerArray ( N , K ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Decimal to Binary using recursion and without using power operator | Java implementation of the approach ; Recursive function to convert n to its binary equivalent ; Base case ; Recursive call ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static void decimalToBinary ( int n ) { if ( n == 0 ) { System . out . print ( \\\"0\\\" ) ; return ; } decimalToBinary ( n \\/ 2 ) ; System . out . print ( n % 2 ) ; } public static void main ( String [ ] args ) { int n = 13 ; decimalToBinary ( n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"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 | Java 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 Java?\",\"targets\":\"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 . charAt ( right ) == c ) { cnt ++ ; } while ( cnt > k ) { if ( str . charAt ( 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 ) ) ; } int main ( ) { return 0 ; } public static void main ( String [ ] args ) { String S = \\\"1001\\\" ; int K = 1 ; System . out . println ( maxConsecutiveSegment ( S , K ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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\":\"\\\"Maximize sum of second minimums in all quadruples of a given array | C # program for the above approach ; Function to find maximum possible sum of second minimums in each quadruple ; Sort the array ; Add the second minimum ; Print maximum possible sum ; Driver Code ; Given array ; Size of the array\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; public class GFG { public static void maxPossibleSum ( int [ ] arr , int N ) { Array . Sort ( arr ) ; int sum = 0 ; int j = N - 3 ; while ( j >= 0 ) { sum += arr [ j ] ; j -= 3 ; } Console . WriteLine ( sum ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 7 , 4 , 5 , 2 , 3 , 1 , 5 , 9 } ; int N = arr . Length ; maxPossibleSum ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check if the string contains consecutive letters and each letter occurs exactly once | C # 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\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static bool check ( string str ) { int min = Int32 . MaxValue ; int max = Int32 . MinValue ; int sum = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { int ascii = ( int ) str [ i ] ; if ( ascii < 96 ascii > 122 ) return false ; sum += ascii ; if ( min > ascii ) min = ascii ; if ( max < ascii ) max = ascii ; } min -= 1 ; int eSum = ( ( max * ( max + 1 ) ) \\/ 2 ) - ( ( min * ( min + 1 ) ) \\/ 2 ) ; return sum == eSum ; } static void Main ( ) { string str = \\\" dcef \\\" ; if ( check ( str ) ) Console . WriteLine ( \\\" Yes \\\" ) ; else Console . WriteLine ( \\\" No \\\" ) ; string str1 = \\\" xyza \\\" ; if ( check ( str1 ) ) 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\":\"\\\"Generate all rotations of a number | C # implementation of the approach ; Function to return the count of digits of n ; Function to print the left shift numbers ; Formula to calculate left shift from previous number ; Update the original number ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; public class GFG { static int numberOfDigits ( int n ) { int cnt = 0 ; while ( n > 0 ) { cnt ++ ; n \\/= 10 ; } return cnt ; } static void cal ( int num ) { int digits = numberOfDigits ( num ) ; int powTen = ( int ) Math . Pow ( 10 , digits - 1 ) ; for ( int i = 0 ; i < digits - 1 ; i ++ ) { int firstDigit = num \\/ powTen ; int left = ( ( num * 10 ) + firstDigit ) - ( firstDigit * powTen * 10 ) ; Console . Write ( left + \\\" ▁ \\\" ) ; num = left ; } } static public void Main ( ) { int num = 1445 ; cal ( num ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count numbers with unit digit k in given range | Efficient Java program to count numbers with last digit as k in given range . ; Returns count of numbers with k as last digit . ; Driver function\\\"\\nSolution in C#:\",\"targets\":\"using System ; public class GfG { public static int counLastDigitK ( int low , int high , int k ) { int mlow = 10 * Convert . ToInt32 ( Math . Ceiling ( low \\/ 10.0 ) ) ; int mhigh = 10 * Convert . ToInt32 ( Math . Floor ( high \\/ 10.0 ) ) ; int count = ( mhigh - mlow ) \\/ 10 ; if ( high % 10 >= k ) count ++ ; if ( low % 10 <= k && ( low % 10 ) > 0 ) count ++ ; return count ; } public static void Main ( ) { int low = 3 , high = 35 , k = 3 ; Console . WriteLine ( counLastDigitK ( low , high , k ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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 ▁ largest ▁ power ▁ of ▁ % d ▁ that ▁ divides ▁ % d ! ▁ is ▁ % 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\":\"\\\"A Space Optimized Solution of LCS | Returns length of LCS for X [ 0. . m - 1 ] , Y [ 0. . n - 1 ] ; Find lengths of two strings ; 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 ]\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { public static int lcs ( String X , String Y ) { int m = X . length ( ) , n = Y . length ( ) ; int L [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int 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 ] ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Average of first n odd naturals numbers | CPP Program to find the average of sum of first n odd numbers ; Return the average of sum of first n odd numbers ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int avg_of_odd_num ( int n ) { return n ; } int main ( ) { int n = 8 ; cout << avg_of_odd_num ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"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\\\"\\nHow can the above be solved 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\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find the sum of the first Nth Centered Pentadecagonal Number | C # program to find the sum of the first N centered pentadecagonal number ; Function to find the centered pentadecagonal number ; Formula to calculate N - th centered pentadecagonal number ; Function to find the sum of the first N centered pentadecagonal numbers ; Variable to store the sum ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int Centered_Pentadecagonal_num ( int n ) { return ( 15 * n * n - 15 * n + 2 ) \\/ 2 ; } static int sum_Centered_Pentadecagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += Centered_Pentadecagonal_num ( i ) ; } return summ ; } public static void Main ( String [ ] args ) { int n = 5 ; Console . WriteLine ( sum_Centered_Pentadecagonal_num ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of subsets with distinct elements | A hashing based solution to find the minimum number of subsets of a set such that every subset contains distinct elements . ; Function to count subsets such that all subsets have distinct elements . ; Traverse the input array and store frequencies of elements ; Find the maximum value in map . ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int subset ( int [ ] arr , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( arr [ i ] ) ) { var val = mp [ arr [ i ] ] ; mp . Remove ( arr [ i ] ) ; mp . Add ( arr [ i ] , val + 1 ) ; } else { mp . Add ( arr [ i ] , 1 ) ; } } int res = 0 ; foreach ( KeyValuePair < int , int > entry in mp ) res = Math . Max ( res , entry . Value ) ; return res ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 6 , 9 , 3 , 4 , 3 , 4 } ; int n = arr . Length ; Console . WriteLine ( subset ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Construct a Tree whose sum of nodes of all the root to leaf path is not divisible by the count of nodes in that path | C ++ program for the above approach ; Function to assign values to nodes of the tree s . t . sum of values of nodes of path between any 2 nodes is not divisible by length of path ; Stores the adjacency list ; Create a adjacency list ; Stores whether node is visited or not ; Stores the node values ; Variable used to assign values to the nodes alternatively to the parent child ; Declare a queue ; Push the 1 st node ; Assign K value to this node ; Dequeue the node ; Mark it as visited ; Upgrade the value of K ; Assign K to the child nodes ; If the child is unvisited ; Enqueue the child ; Assign K to the child ; Print the value assigned to the nodes ; Driver Code ; Function Call\\\"\\nSolution in C++:\",\"targets\":\"#include \\\" bits \\/ stdc + + . h \\\"\\nusing namespace std ; void assignValues ( int Edges [ ] [ 2 ] , int n ) { vector < int > tree [ n + 1 ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int u = Edges [ i ] [ 0 ] ; int v = Edges [ i ] [ 1 ] ; tree [ u ] . push_back ( v ) ; tree [ v ] . push_back ( u ) ; } vector < bool > visited ( n + 1 , false ) ; vector < int > answer ( n + 1 ) ; int K = 1 ; queue < int > q ; q . push ( 1 ) ; answer [ 1 ] = K ; while ( ! q . empty ( ) ) { int node = q . front ( ) ; q . pop ( ) ; visited [ node ] = true ; K = ( ( answer [ node ] == 1 ) ? 2 : 1 ) ; for ( auto child : tree [ node ] ) { if ( ! visited [ child ] ) { q . push ( child ) ; answer [ child ] = K ; } } } for ( int i = 1 ; i <= n ; i ++ ) { cout << answer [ i ] << \\\" ▁ \\\" ; } } int main ( ) { int N = 11 ; int Edges [ ] [ 2 ] = { { 1 , 2 } , { 1 , 3 } , { 1 , 4 } , { 1 , 5 } , { 2 , 6 } , { 2 , 10 } , { 10 , 11 } , { 3 , 7 } , { 4 , 8 } , { 5 , 9 } } ; assignValues ( Edges , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Largest palindromic number by permuting digits | JAVA program to print the largest palindromic number by permuting digits of a number ; Function to check if a number can be permuted to form a palindrome number ; counts the occurrence of number which is odd ; if occurrence is odd ; if number exceeds 1 ; function to print the largest palindromic number by permuting digits of a number ; String length ; map that marks the occurrence of a number ; check the possibility of a palindromic number ; String array that stores the largest permuted palindromic number ; pointer of front ; greedily start from 9 to 0 and place the greater number in front and odd in the middle ; if the occurrence of number is odd ; place one odd occurring number in the middle ; decrease the count ; place the rest of numbers greedily ; if all numbers occur even times , then place greedily ; place greedily at front ; 2 numbers are placed , so decrease the count ; increase placing position ; print the largest String thus formed ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static boolean possibility ( HashMap < Integer , Integer > m , int length , String s ) { int countodd = 0 ; for ( int i = 0 ; i < length ; i ++ ) { if ( m . get ( s . charAt ( i ) - '0' ) % 2 == 1 ) countodd ++ ; if ( countodd > 1 ) return false ; } return true ; } static void largestPalindrome ( String s ) { int l = s . length ( ) ; HashMap < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < l ; i ++ ) if ( m . containsKey ( s . charAt ( i ) - '0' ) ) m . put ( s . charAt ( i ) - '0' , m . get ( s . charAt ( i ) - '0' ) + 1 ) ; else m . put ( s . charAt ( i ) - '0' , 1 ) ; if ( possibility ( m , l , s ) == false ) { System . out . print ( \\\" Palindrome ▁ cannot ▁ be ▁ formed \\\" ) ; return ; } char [ ] largest = new char [ l ] ; int front = 0 ; for ( int i = 9 ; i >= 0 ; i -- ) { if ( m . containsKey ( i ) && m . get ( i ) % 2 == 1 ) { largest [ l \\/ 2 ] = ( char ) ( i + 48 ) ; m . put ( i , m . get ( i ) - 1 ) ; while ( m . get ( i ) > 0 ) { largest [ front ] = ( char ) ( i + 48 ) ; largest [ l - front - 1 ] = ( char ) ( i + 48 ) ; m . put ( i , m . get ( i ) - 2 ) ; front ++ ; } } else { while ( m . containsKey ( i ) && m . get ( i ) > 0 ) { largest [ front ] = ( char ) ( i + 48 ) ; largest [ l - front - 1 ] = ( char ) ( i + 48 ) ; m . put ( i , m . get ( i ) - 2 ) ; front ++ ; } } } for ( int i = 0 ; i < l ; i ++ ) System . out . print ( largest [ i ] ) ; } public static void main ( String [ ] args ) { String s = \\\"313551\\\" ; largestPalindrome ( s ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Maximize boxes required to keep at least one black and one white shirt | Java program for the above approach ; Function to find the maximum number of boxes such that each box contains three shirts comprising of at least one white and black shirt ; Stores the low and high pointers for binary search ; Store the required answer ; Loop while low <= high ; Store the mid value ; Check if the mid number of boxes can be used ; Update answer and recur for the right half ; Else , recur for the left half ; Print the result ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void numberofBoxes ( int W , int B , int O ) { int low = 0 , high = Math . min ( W , B ) ; int ans = 0 ; while ( low <= high ) { int mid = low + ( high - low ) \\/ 2 ; if ( ( ( W >= mid ) && ( B >= mid ) ) && ( ( W - mid ) + ( B - mid ) + O ) >= mid ) { ans = mid ; low = mid + 1 ; } else high = mid - 1 ; } System . out . println ( ans ) ; } public static void main ( String args [ ] ) { int W = 3 , B = 3 , O = 1 ; numberofBoxes ( W , B , O ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Middle of three using minimum comparisons | C # program to find middle of three distinct numbers ; Function to find the middle of three number ; x is positive if a is greater than b . x is negative if b is greater than a . ; Similar to x ; Similar to x and y . ; Checking if b is middle ( x and y both are positive ) ; Checking if c is middle ( x and z both are positive ) ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class Middle { public static int middleOfThree ( int a , int b , int c ) { int x = a - b ; int y = b - c ; int z = a - c ; if ( x * y > 0 ) return b ; else if ( x * z > 0 ) return c ; else return a ; } public static void Main ( ) { int a = 20 , b = 30 , c = 40 ; Console . WriteLine ( middleOfThree ( a , b , c ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Length of diagonals of a Rhombus using length of Side and vertex Angle | Python Program to implement the above approach ; Function to calculate the length of diagonals of a rhombus using length of sides and vertex angle ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"import math\\ndef Length_Diagonals ( a , theta ) :\\n\\tp = a * math . sqrt ( 2 + ( 2 * math . cos ( math . radians ( theta ) ) ) )\\n\\tq = a * math . sqrt ( 2 - ( 2 * math . cos ( math . radians ( theta ) ) ) )\\n\\treturn [ p , q ]\\nA = 6\\ntheta = 45\\nans = Length_Diagonals ( A , theta )\\nprint ( round ( ans [ 0 ] , 2 ) , round ( ans [ 1 ] , 2 ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sum of absolute differences of indices of occurrences of each array element | C ++ program for the above approach ; Function to find sum of differences of indices of occurrences of each unique array element ; Stores indices of each array element ; Store the indices ; Stores the sums ; Traverse the array ; Find sum for each element ; Iterate over the Map ; Calculate sum of occurrences of arr [ i ] ; Store sum for current element ; Print answer for each element ; Driver Code ; Given array ; Given size ; Function call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void sum ( int arr [ ] , int n ) { map < int , vector < int > > mp ; for ( int i = 0 ; i < n ; i ++ ) { mp [ arr [ i ] ] . push_back ( i ) ; } int ans [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; for ( auto it : mp [ arr [ i ] ] ) { sum += abs ( it - i ) ; } ans [ i ] = sum ; } for ( int i = 0 ; i < n ; i ++ ) { cout << ans [ i ] << \\\" ▁ \\\" ; } return ; } int main ( ) { int arr [ ] = { 1 , 3 , 1 , 1 , 2 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; sum ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Counting Sort | The main function that sort the given string arr [ ] in alphabetical 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\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def countSort ( arr ) :\\n\\toutput = [ 0 for i in range ( len ( arr ) ) ]\\n\\tcount = [ 0 for i in range ( 256 ) ]\\n\\tfor i in arr :\\n\\t\\tcount [ ord ( i ) ] += 1\\n\\tfor i in range ( 256 ) :\\n\\t\\tcount [ i ] += count [ i - 1 ]\\n\\tfor i in range ( len ( arr ) ) :\\n\\t\\toutput [ count [ ord ( arr [ i ] ) ] - 1 ] = arr [ i ]\\n\\t\\tcount [ ord ( arr [ i ] ) ] -= 1\\n\\tans = [ \\\" \\\" for _ in arr ]\\n\\tfor i in range ( len ( arr ) ) :\\n\\t\\tans [ i ] = output [ i ]\\n\\treturn ans\\narr = \\\" geeksforgeeks \\\"\\nans = countSort ( arr )\\nprint ( \\\" Sorted ▁ character ▁ array ▁ is ▁ % ▁ s \\\" % ( \\\" \\\" . join ( ans ) ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Program to find remainder when large number is divided by 11 | Function to return remainder ; len is variable to store the length of number string . ; loop that find remainder ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def remainder ( st ) :\\n\\tln = len ( st )\\n\\trem = 0\\n\\tfor i in range ( 0 , ln ) :\\n\\t\\tnum = rem * 10 + ( int ) ( st [ i ] )\\n\\t\\trem = num % 11\\n\\treturn rem\\nst = \\\"3435346456547566345436457867978\\\"\\nprint ( remainder ( st ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\nHow can the above be solved 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 ▁ Point ▁ is ▁ % d \\\" , binarySearch ( arr , 0 , n - 1 ) ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Program for Goldbachâ €™ 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 ▁ Input ▁ \\n \\\" ) ; return ; } for ( $ i = 0 ; $ primes [ $ i ] <= $ n \\/ 2 ; $ i ++ ) { $ diff = $ n - $ primes [ $ i ] ; if ( in_array ( $ diff , $ primes ) ) { print ( $ primes [ $ i ] . \\\" + \\\" ▁ . ▁ $ diff ▁ . ▁ \\\" = \\\" ▁ . ▁ $ n ▁ . ▁ \\\" \\\" 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\":\"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\":\"\\\"Count words in a given string | Python3 program to count words in a given string ; Returns number of words in string ; 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 ; Return the number of words ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"OUT = 0\\nIN = 1\\ndef countWords ( string ) :\\n\\tstate = OUT\\n\\twc = 0\\n\\tfor i in range ( len ( string ) ) :\\n\\t\\tif ( string [ i ] == ' ▁ ' or string [ i ] == ' ' ▁ or ▁ string [ i ] ▁ = = ▁ ' \\t ' ) :\\n\\t\\t\\tstate = OUT\\n\\t\\telif state == OUT :\\n\\t\\t\\tstate = IN\\n\\t\\t\\twc += 1\\n\\treturn wc\\nstring = \\\" One two three\\n\\tfour five \\\"\\nprint ( \\\" No . ▁ of ▁ words ▁ : ▁ \\\" + str ( countWords ( string ) ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findCandidate ( A ) :\\n\\tmaj_index = 0\\n\\tcount = 1\\n\\tfor i in range ( len ( A ) ) :\\n\\t\\tif A [ maj_index ] == A [ i ] :\\n\\t\\t\\tcount += 1\\n\\t\\telse :\\n\\t\\t\\tcount -= 1\\n\\t\\tif count == 0 :\\n\\t\\t\\tmaj_index = i\\n\\t\\t\\tcount = 1\\n\\treturn A [ maj_index ]\\ndef isMajority ( A , cand ) :\\n\\tcount = 0\\n\\tfor i in range ( len ( A ) ) :\\n\\t\\tif A [ i ] == cand :\\n\\t\\t\\tcount += 1\\n\\tif count > len ( A ) \\/ 2 :\\n\\t\\treturn True\\n\\telse :\\n\\t\\treturn False\\ndef printMajority ( A ) :\\n\\tcand = findCandidate ( A )\\n\\tif isMajority ( A , cand ) == True :\\n\\t\\tprint ( cand )\\n\\telse :\\n\\t\\tprint ( \\\" No ▁ Majority ▁ Element \\\" )\\nA = [ 1 , 3 , 3 , 1 , 2 ]\\nprintMajority ( A )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Largest sub | C ++ implementation of the approach ; Function to return the largest substring divisible by 2 ; While the last character of the string is '1' , pop it ; If the original string had no '0' ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; string largestSubStr ( string s ) { while ( s . size ( ) and s [ s . size ( ) - 1 ] == '1' ) s . pop_back ( ) ; if ( s . size ( ) == 0 ) return \\\" - 1\\\" ; else return s ; } int main ( ) { string s = \\\"11001\\\" ; cout << largestSubStr ( s ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum profit after buying and selling the stocks with transaction fees | Set 2 | Function to find the maximum profit with transaction fee ; Traversing the stocks for each day ; Update buy and sell ; Return the maximum profit ; Given Input ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function MaxProfit ( arr , n , transactionFee ) { let buy = - arr [ 0 ] ; let sell = 0 ; for ( let i = 1 ; i < n ; i ++ ) { let temp = buy ; buy = Math . max ( buy , sell - arr [ i ] ) ; sell = Math . max ( sell , temp + arr [ i ] - transactionFee ) ; } return Math . max ( sell , buy ) ; } let arr = [ 6 , 1 , 7 , 2 , 8 , 4 ] ; let n = arr . length ; let transactionFee = 2 ; document . write ( MaxProfit ( arr , n , transactionFee ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Rearrange an array to maximize sum of Bitwise AND of same | C # program for the above approach ; Function to implement recursive DP ; If i is equal to N ; If dp [ i ] [ mask ] is not equal to - 1 ; Iterate over the array B [ ] ; If current element is not yet selected ; Update dp [ i ] [ mask ] ; Return dp [ i ] [ mask ] ; Function to obtain maximum sum of Bitwise AND of same - indexed elements from the arrays A [ ] and B [ ] ; Stores all dp - states ; Returns the maximum value returned by the function maximizeAnd ( ) ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int maximizeAnd ( int i , int mask , int [ ] A , int [ ] B , int N , int [ , ] dp ) { if ( i == N ) return 0 ; if ( dp [ i , mask ] != - 1 ) return dp [ i , mask ] ; for ( int j = 0 ; j < N ; ++ j ) { if ( ( mask & ( 1 << j ) ) == 0 ) { dp [ i , mask ] = Math . Max ( dp [ i , mask ] , ( A [ i ] & B [ j ] ) + maximizeAnd ( i + 1 , mask | ( 1 << j ) , A , B , N , dp ) ) ; } } return dp [ i , mask ] ; } static int maximizeAndUtil ( int [ ] A , int [ ] B , int N ) { int [ , ] dp = new int [ N , ( 1 << N ) + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < ( 1 << N ) + 1 ; j ++ ) { dp [ i , j ] = - 1 ; } } return maximizeAnd ( 0 , 0 , A , B , N , dp ) ; } static void Main ( ) { int [ ] A = { 3 , 5 , 7 , 11 } ; int [ ] B = { 2 , 6 , 10 , 12 } ; int N = A . Length ; Console . Write ( maximizeAndUtil ( A , B , N ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"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\\\"\\nSolution 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 ▁ \\\" , 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\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Distance between two parallel lines | C # program find the distance between two parallel lines ; Function to find the distance between parallel lines ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static double dist ( double m , double b1 , double b2 ) { double d = Math . Abs ( b2 - b1 ) \\/ ( ( m * m ) - 1 ) ; return d ; } public static void Main ( ) { double m = 2 , b1 = 4 , b2 = 3 ; Console . Write ( dist ( m , b1 , b2 ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find most significant set bit of a number | CPP program to find MSB number for given n . ; Suppose n is 273 ( binary is 100010001 ) . It does following 100010001 | 010001000 = 110011001 ; This makes sure 4 bits ( From MSB and including MSB ) are set . It does following 110011001 | 001100110 = 111111111 ; Increment n by 1 so that there is only one set bit which is just before original MSB . n now becomes 1000000000 ; Return original MSB after shifting . n now becomes 100000000 ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int setBitNumber ( int n ) { n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; n = n + 1 ; return ( n >> 1 ) ; } int main ( ) { int n = 273 ; cout << setBitNumber ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"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 | 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 Python:\",\"targets\":\"def postfix ( a , n ) :\\n\\tfor i in range ( n - 1 , 1 , - 1 ) :\\n\\t\\ta [ i - 1 ] = a [ i - 1 ] + a [ i ]\\ndef modify ( a , n ) :\\n\\tfor i in range ( 1 , n ) :\\n\\t\\ta [ i - 1 ] = i * a [ i ] ;\\ndef allCombination ( a , n ) :\\n\\tsum = 0\\n\\tfor i in range ( 1 , n + 1 ) :\\n\\t\\tsum += i\\n\\tprint ( \\\" f ( 1 ) ▁ - - > ▁ \\\" , sum )\\n\\tfor i in range ( 1 , n ) :\\n\\t\\tpostfix ( a , n - i + 1 )\\n\\t\\tsum = 0\\n\\t\\tfor j in range ( 1 , n - i + 1 ) :\\n\\t\\t\\tsum += ( j * a [ j ] )\\n\\t\\tprint ( \\\" f ( \\\" , i + 1 , \\\" ) ▁ - - > ▁ \\\" , sum )\\n\\t\\tmodify ( a , n )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tn = 5\\n\\ta = [ 0 ] * n\\n\\tfor i in range ( n ) :\\n\\t\\ta [ i ] = i + 1\\n\\tallCombination ( a , n )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of replacement done of substring \\\"01\\\" with \\\"110\\\" to remove it completely | Function to find the minimum number of replacement of \\\"01\\\" with \\\"110\\\" s . t . S doesn 't contain substring \\\"10\\\" ; Stores the number of operations performed ; Stores the resultant count of substrings ; Traverse the string S from end ; If the current character is 0 ; If the current character is 1 ; Print the result ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def minimumOperations ( S , N ) :\\n\\tans = 0\\n\\tcntOne = 0\\n\\ti = N - 1\\n\\twhile ( i >= 0 ) :\\n\\t\\tif ( S [ i ] == '0' ) :\\n\\t\\t\\tans += cntOne\\n\\t\\t\\tcntOne *= 2\\n\\t\\telse :\\n\\t\\t\\tcntOne += 1\\n\\t\\ti -= 1\\n\\tprint ( ans )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tS = \\\"001\\\"\\n\\tN = len ( S )\\n\\tminimumOperations ( S , N )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find the subsequence with given sum in a superincreasing sequence | C # implementation of the approach ; Function to find the required subsequence ; Current element cannot be a part of the required subsequence ; Include current element in the required subsequence So update the sum ; Print the elements of the required subsequence ; If the current element was included in the subsequence ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void findSubSeq ( int [ ] arr , int n , int sum ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( sum < arr [ i ] ) arr [ i ] = - 1 ; else sum -= arr [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != - 1 ) Console . Write ( arr [ i ] + \\\" ▁ \\\" ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 17 , 25 , 46 , 94 , 201 , 400 } ; int n = arr . Length ; int sum = 272 ; findSubSeq ( arr , n , sum ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"gOOGLE cASE of a given sentence | Java program to convert a sentence to gOOGLE cASE . ; empty strings ; convert input string to upper case ; checki if character is not a space and adding it to string w ; converting first character to lower case and subsequent initial letter of another word to lower case ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static String convert ( String str ) { String w = \\\" \\\" , z = \\\" \\\" ; str = str . toUpperCase ( ) + \\\" ▁ \\\" ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char ch = str . charAt ( i ) ; if ( ch != ' ▁ ' ) w = w + ch ; else { z = z + ( Character . toLowerCase ( w . charAt ( 0 ) ) ) + w . substring ( 1 ) + \\\" ▁ \\\" ; w = \\\" \\\" ; } } return z ; } public static void main ( String [ ] args ) { String str = \\\" I ▁ got ▁ intern ▁ at ▁ geeksforgeeks \\\" ; System . out . println ( convert ( str ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum cost to reach a point N from 0 with two different operations allowed | Function to return minimum cost to reach destination ; Initialize cost to 0 ; going backwards until we reach initial position ; if 2 * X jump is better than X + 1 ; if X + 1 jump is better ; Driver program\\\"\\nSolution in Python:\",\"targets\":\"def minCost ( N , P , Q ) :\\n\\tcost = 0\\n\\twhile ( N > 0 ) :\\n\\t\\tif ( N & 1 ) :\\n\\t\\t\\tcost += P\\n\\t\\t\\tN -= 1\\n\\t\\telse :\\n\\t\\t\\ttemp = N \\/\\/ 2 ;\\n\\t\\t\\tif ( temp * P > Q ) :\\n\\t\\t\\t\\tcost += Q\\n\\t\\t\\telse :\\n\\t\\t\\t\\tcost += P * temp\\n\\t\\t\\tN \\/\\/= 2\\n\\treturn cost\\nN = 9\\nP = 5\\nQ = 1\\nprint ( minCost ( N , P , Q ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Power of a prime number ‘ r ’ in n ! | C ++ program to find power of a prime number r in n ! ; Function to return power of a no . ' r ' in factorial of n ; Keep dividing n by powers of ' r ' and update count ; Driver program to test above function\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int power ( int n , int r ) { int count = 0 ; for ( int i = r ; ( n \\/ i ) >= 1 ; i = i * r ) count += n \\/ i ; return count ; } int main ( ) { int n = 6 , r = 3 ; printf ( \\\" ▁ % d ▁ \\\" , power ( n , r ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Program to find Normal and Trace of a matrix | Size of given matrix ; Returns Normal of a matrix of size n x n ; Returns trace of a matrix of size n x n ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"var MAX = 100 ; function findNormal ( mat , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = 0 ; j < n ; j ++ ) sum += mat [ i ] [ j ] * mat [ i ] [ j ] ; return parseInt ( Math . sqrt ( sum ) ) ; } function findTrace ( mat , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum += mat [ i ] [ i ] ; return sum ; } var 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 ] ] ; document . write ( \\\" \\\" + findTrace ( mat , 5 ) + \\\" \\\" ) ; document . write ( \\\" \\\" + findNormal ( mat , 5 ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Largest number made up of X and Y with count of X divisible by Y and of Y by X | Function to generate and return the largest number ; Store the smaller in Y ; Store the larger in X ; Stores respective counts ; If N is divisible by Y ; Append X , N times to the answer ; Reduce N to zero ; Reduce N by x ; Append Y , X times to the answer ; If number can be formed ; Otherwise ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def largestNumber ( n , X , Y ) :\\n\\tmaxm = max ( X , Y )\\n\\tY = X + Y - maxm\\n\\tX = maxm\\n\\tXs = 0\\n\\tYs = 0\\n\\twhile ( n > 0 ) :\\n\\t\\tif ( n % Y == 0 ) :\\n\\t\\t\\tXs += n\\n\\t\\t\\tn = 0\\n\\t\\telse :\\n\\t\\t\\tn -= X\\n\\t\\t\\tYs += X\\n\\tif ( n == 0 ) :\\n\\t\\twhile ( Xs > 0 ) :\\n\\t\\t\\tXs -= 1\\n\\t\\t\\tprint ( X , end = ' ' )\\n\\t\\twhile ( Ys > 0 ) :\\n\\t\\t\\tYs -= 1\\n\\t\\t\\tprint ( Y , end = ' ' )\\n\\telse :\\n\\t\\tprint ( \\\" - 1\\\" )\\nn = 19\\nX = 7\\nY = 5\\nlargestNumber ( n , X , Y )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Icositetragonal Number | Function to find icositetragonal number ; Formula to calculate nth icositetragonal number ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function Icositetragonal_num ( n ) { return ( 22 * n * n - 20 * n ) \\/ 2 ; } let n = 3 ; document . write ( Icositetragonal_num ( n ) + \\\" \\\" ) ; n = 10 ; document . write ( Icositetragonal_num ( n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"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\\nHow can the above be solved 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 ▁ is ▁ not ▁ present ▁ in ▁ array \\\" ) : printf ( \\\" Element ▁ is ▁ present ▁ at ▁ index ▁ % d \\\" , result ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"Extract ' k ' bits from a given position in a number . | C 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\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint bitExtracted ( int number , int k , int p ) { return ( ( ( 1 << k ) - 1 ) & ( number >> ( p - 1 ) ) ) ; } int main ( ) { int number = 171 , k = 5 , p = 2 ; printf ( \\\" The ▁ extracted ▁ number ▁ is ▁ % d \\\" , bitExtracted ( number , k , p ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Bubble Sort | Optimized C # implementation of Bubble sort ; An optimized version of Bubble Sort ; swap arr [ j ] and arr [ j + 1 ] ; IF no two elements were swapped by inner loop , then break ; Function to print an array ; Driver method\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void bubbleSort ( int [ ] arr , int n ) { int i , j , temp ; bool swapped ; for ( i = 0 ; i < n - 1 ; i ++ ) { swapped = false ; for ( j = 0 ; j < n - i - 1 ; j ++ ) { if ( arr [ j ] > arr [ j + 1 ] ) { temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; swapped = true ; } } if ( swapped == false ) break ; } } static void printArray ( int [ ] arr , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) Console . Write ( arr [ i ] + \\\" ▁ \\\" ) ; Console . WriteLine ( ) ; } public static void Main ( ) { int [ ] arr = { 64 , 34 , 25 , 12 , 22 , 11 , 90 } ; int n = arr . Length ; bubbleSort ( arr , n ) ; Console . WriteLine ( \\\" Sorted ▁ array \\\" ) ; printArray ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Product of nodes at k | Function to find product of digits of elements at k - th level ; Initialize result ; increasing level number ; decreasing level number ; check if current level is the desired level or not ; required product ; Driver program\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def productAtKthLevel ( tree , k ) :\\n\\tlevel = - 1\\n\\tproduct = 1\\n\\tn = len ( tree )\\n\\tfor i in range ( 0 , n ) :\\n\\t\\tif ( tree [ i ] == ' ( ' ) :\\n\\t\\t\\tlevel += 1\\n\\t\\telif ( tree [ i ] == ' ) ' ) :\\n\\t\\t\\tlevel -= 1\\n\\t\\telse :\\n\\t\\t\\tif ( level == k ) :\\n\\t\\t\\t\\tproduct *= ( int ( tree [ i ] ) - int ( '0' ) )\\n\\treturn product\\ntree = \\\" ( 0(5(6 ( ) ( ) ) ( 4 ( ) (9 ( ) ( ) ) ) ) ( 7(1 ( ) ( ) ) ( 3 ( ) ( ) ) ) ) \\\"\\nk = 2\\nprint ( productAtKthLevel ( tree , k ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sum of all divisors from 1 to n | C program to find sum of all divisor of number up to ' n ' ; Utility function to find sum of all divisor of number up to ' n ' ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\nint divisorSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; ++ i ) sum += ( n \\/ i ) * i ; return sum ; } int main ( ) { int n = 4 ; printf ( \\\" % d \\n \\\" , divisorSum ( n ) ) ; n = 5 ; printf ( \\\" % d \\\" , divisorSum ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Count of permutations such that sum of K numbers from given range is even | Java program for the above approach ; Function to return the number of all permutations such that sum of K numbers in range is even ; Find total count of even and odd number in given range ; Iterate loop k times and update even_sum & odd_sum using previous values ; Update the prev_even and odd_sum ; Even sum ; Odd sum ; Return even_sum ; Driver Code ; Given ranges ; Length of permutation ; Function call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { public static void countEvenSum ( int low , int high , int k ) { int even_count = high \\/ 2 - ( low - 1 ) \\/ 2 ; int odd_count = ( high + 1 ) \\/ 2 - low \\/ 2 ; long even_sum = 1 ; long odd_sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) { long prev_even = even_sum ; long prev_odd = odd_sum ; even_sum = ( prev_even * even_count ) + ( prev_odd * odd_count ) ; odd_sum = ( prev_even * odd_count ) + ( prev_odd * even_count ) ; } System . out . println ( even_sum ) ; } public static void main ( String [ ] args ) { int low = 4 ; int high = 5 ; int K = 3 ; countEvenSum ( low , high , K ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 ▁ Point ▁ is ▁ % 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\":\"\\\"Divide a string in N equal parts | C program to divide a string in n equal parts ; Function to print n equal parts of str ; Check if string can be divided in n equal parts ; Calculate the size of parts to find the division points ; length od string is 28 ; Print 4 equal parts of the string\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\nvoid divideString ( char * str , int n ) { int str_size = strlen ( str ) ; int i ; int part_size ; if ( str_size % n != 0 ) { printf ( \\\" Invalid ▁ Input : ▁ String ▁ size \\\" ) ; printf ( \\\" ▁ is ▁ not ▁ divisible ▁ by ▁ n \\\" ) ; return ; } part_size = str_size \\/ n ; for ( i = 0 ; i < str_size ; i ++ ) { if ( i % part_size == 0 ) printf ( \\\" \\n \\\" ) ; printf ( \\\" % c \\\" , str [ i ] ) ; } } int main ( ) { char * str = \\\" a _ simple _ divide _ string _ quest \\\" ; divideString ( str , 4 ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximum element between two nodes of BST | Java 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\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class Solution { static class Node { Node left , right ; int data ; } static Node createNode ( int x ) { Node p = new Node ( ) ; p . data = x ; p . left = p . right = null ; return p ; } 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 ) ; } } 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 ) ; } 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 [ ] = { 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 ] ) ; System . out . println ( maximumElement ( root , a , b ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Number of subarrays have bitwise OR >= K | Java implementation of the above approach ; Function which builds the segment tree ; Function that returns bitwise OR of segment [ L . . R ] ; Function to count requisite number of subarrays ; Check for subarrays starting with index i ; If OR of subarray [ i . . mid ] >= K , then all subsequent subarrays will have OR >= K therefore reduce high to mid - 1 to find the minimal length subarray [ i . . mid ] having OR >= K ; Increase count with number of subarrays having OR >= K and starting with index i ; Driver code ; Build segment tree .\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int N = 100002 ; static int tree [ ] = new int [ 4 * N ] ; static void build ( int [ ] arr , int node , int start , int end ) { if ( start == end ) { tree [ node ] = arr [ start ] ; return ; } int mid = ( start + end ) >> 1 ; build ( arr , 2 * node , start , mid ) ; build ( arr , 2 * node + 1 , mid + 1 , end ) ; tree [ node ] = tree [ 2 * node ] | tree [ 2 * node + 1 ] ; } static int query ( int node , int start , int end , int l , int r ) { if ( start > end start > r end < l ) { return 0 ; } if ( start >= l && end <= r ) { return tree [ node ] ; } int mid = ( start + end ) >> 1 ; int q1 = query ( 2 * node , start , mid , l , r ) ; int q2 = query ( 2 * node + 1 , mid + 1 , end , l , r ) ; return q1 | q2 ; } static int countSubArrays ( int [ ] arr , int n , int K ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int low = i , high = n - 1 , index = Integer . MAX_VALUE ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; if ( query ( 1 , 0 , n - 1 , i , mid ) >= K ) { index = Math . min ( index , mid ) ; high = mid - 1 ; } else { low = mid + 1 ; } } if ( index != Integer . MAX_VALUE ) { count += n - index ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 5 } ; int n = arr . length ; build ( arr , 1 , 0 , n - 1 ) ; int k = 6 ; System . out . println ( countSubArrays ( arr , n , k ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sum of leaf nodes at minimum level | Java implementation to find the sum of leaf nodes at minimum level ; structure of a node of binary tree ; function to get a new node ; allocate space ; put in the data ; function to find the sum of leaf nodes at minimum level ; if tree is empty ; if there is only one node ; queue used for level order traversal ; push root node in the queue ' q ' ; count number of nodes in the current level ; traverse the current level nodes ; get front element from ' q ' ; if it is a leaf node ; accumulate data to ' sum ' ; set flag ' f ' to 1 , to signify minimum level for leaf nodes has been encountered ; if top ' s ▁ left ▁ and ▁ right ▁ child ▁ ▁ ▁ exists , ▁ then ▁ push ▁ them ▁ to ▁ ' q ' ; required sum ; Driver Code ; binary tree creation\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } ; static Node getNode ( int data ) { Node newNode = new Node ( ) ; newNode . data = data ; newNode . left = newNode . right = null ; return newNode ; } static int sumOfLeafNodesAtMinLevel ( Node root ) { if ( root == null ) return 0 ; if ( root . left == null && root . right == null ) return root . data ; Queue < Node > q = new LinkedList < > ( ) ; int sum = 0 ; boolean f = false ; q . add ( root ) ; while ( f == false ) { int nc = q . size ( ) ; while ( nc -- > 0 ) { Node top = q . peek ( ) ; q . remove ( ) ; if ( top . left == null && top . right == null ) { sum += top . data ; f = true ; } else { if ( top . left != null ) q . add ( top . left ) ; if ( top . right != null ) q . add ( top . right ) ; } } } return sum ; } public static void main ( String [ ] args ) { Node root = getNode ( 1 ) ; root . left = getNode ( 2 ) ; root . right = getNode ( 3 ) ; root . left . left = getNode ( 4 ) ; root . left . right = getNode ( 5 ) ; root . right . left = getNode ( 6 ) ; root . right . right = getNode ( 7 ) ; root . left . right . left = getNode ( 8 ) ; root . right . left . right = getNode ( 9 ) ; System . out . println ( \\\" Sum ▁ = ▁ \\\" + sumOfLeafNodesAtMinLevel ( root ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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\":\"\\\"Queries to check whether bitwise AND of a subarray is even or odd | Java implementation of the approach ; Function to precompute the count of even and odd numbers ; If the current element is odd then put 1 at odd [ i ] ; If the current element is even then put 1 at even [ i ] ; Taking the prefix sums of these two arrays so we can get the count of even and odd numbers in a range [ L , R ] in O ( 1 ) ; Function that returns true if the bitwise AND of the subarray a [ L ... R ] is odd ; cnt will store the count of odd numbers in the range [ L , R ] ; Check if all the numbers in the range are odd or not ; Function to perform the queries ; Perform queries ; Driver code ; Queries\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static final int MAXN = 1000005 ; static int even [ ] = new int [ MAXN ] ; static int odd [ ] = new int [ MAXN ] ; static void precompute ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 1 ) odd [ i ] = 1 ; if ( arr [ i ] % 2 == 0 ) even [ i ] = 1 ; } for ( int i = 1 ; i < n ; i ++ ) { even [ i ] = even [ i ] + even [ i - 1 ] ; odd [ i ] = odd [ i ] + odd [ i - 1 ] ; } } static boolean isOdd ( int L , int R ) { int cnt = odd [ R ] ; if ( L > 0 ) cnt -= odd [ L - 1 ] ; if ( cnt == R - L + 1 ) return true ; return false ; } static void performQueries ( int a [ ] , int n , int q [ ] [ ] , int m ) { precompute ( a , n ) ; for ( int i = 0 ; i < m ; i ++ ) { int L = q [ i ] [ 0 ] , R = q [ i ] [ 1 ] ; if ( isOdd ( L , R ) ) System . out . println ( \\\" Odd \\\" ) ; else System . out . println ( \\\" Even \\\" ) ; } } public static void main ( String args [ ] ) { int [ ] a = { 2 , 1 , 5 , 7 , 6 , 8 , 9 } ; int n = a . length ; int q [ ] [ ] = { { 0 , 2 } , { 1 , 2 } , { 2 , 3 } , { 3 , 6 } } ; int m = q . length ; performQueries ( a , n , q , m ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Subtraction in the Array | Java implementation of the approach ; Function to perform the given operation on arr [ ] ; Skip elements which are 0 ; Pick smallest non - zero element ; If all the elements of arr [ ] are 0 ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static void operations ( int arr [ ] , int n , int k ) { Arrays . sort ( arr ) ; int i = 0 , sum = 0 ; while ( k -- > 0 ) { while ( i < n && arr [ i ] - sum == 0 ) i ++ ; if ( i < n && arr [ i ] - sum > 0 ) { System . out . print ( arr [ i ] - sum + \\\" ▁ \\\" ) ; sum = arr [ i ] ; } else System . out . println ( \\\"0\\\" ) ; } } public static void main ( String args [ ] ) { int k = 5 ; int arr [ ] = { 3 , 6 , 4 , 2 } ; int n = arr . length ; operations ( arr , n , k ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Print all permutations in sorted ( lexicographic ) order | Program to print all permutations of a string in sorted order . ; Following function is needed for library function qsort ( ) . Refer http : www . cplusplus . com \\/ reference \\/ clibrary \\/ cstdlib \\/ qsort \\/ ; A utility function two swap two characters a and b ; This function finds the index of the smallest character which is greater than ' first ' and is present in str [ l . . h ] ; initialize index of ceiling element ; Now iterate through rest of the elements and find the smallest character greater than ' first ' ; Print all permutations of str in sorted order ; Get size of string ; Sort the string in increasing order ; Print permutations one by one ; print this permutation ; Find the rightmost character which is smaller than its next character . Let us call it ' first ▁ char ' ; If there is no such character , all are sorted in decreasing order , means we just printed the last permutation and we are done . ; Find the ceil of ' first ▁ char ' in right of first character . Ceil of a character is the smallest character greater than it ; Swap first and second characters ; Sort the string on right of ' first ▁ char ' ; Driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\n#include \\n#include \\nint compare ( const void * a , const void * b ) { return ( * ( char * ) a - * ( char * ) b ) ; } void swap ( char * a , char * b ) { char t = * a ; * a = * b ; * b = t ; } int findCeil ( char str [ ] , char first , int l , int h ) { int ceilIndex = l ; for ( int i = l + 1 ; i <= h ; i ++ ) if ( str [ i ] > first && str [ i ] < str [ ceilIndex ] ) ceilIndex = i ; return ceilIndex ; } void sortedPermutations ( char str [ ] ) { int size = strlen ( str ) ; qsort ( str , size , sizeof ( str [ 0 ] ) , compare ) ; bool isFinished = false ; while ( ! isFinished ) { printf ( \\\" % s ▁ \\n \\\" , str ) ; int i ; for ( i = size - 2 ; i >= 0 ; -- i ) if ( str [ i ] < str [ i + 1 ] ) break ; if ( i == -1 ) isFinished = true ; else { int ceilIndex = findCeil ( str , str [ i ] , i + 1 , size - 1 ) ; swap ( & str [ i ] , & str [ ceilIndex ] ) ; qsort ( str + i + 1 , size - i - 1 , sizeof ( str [ 0 ] ) , compare ) ; } } } int main ( ) { char str [ ] = \\\" ABCD \\\" ; sortedPermutations ( str ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if sum of divisors of two numbers are same | Python3 program to find if two numbers are equivalent or not ; Function to calculate sum of all proper divisors num -- > given natural number ; To store sum of divisors ; Find all divisors and add them ; Function to check if both numbers are equivalent or not ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"import math\\ndef divSum ( n ) :\\n\\tsum = 1 ;\\n\\ti = 2 ;\\n\\twhile ( i * i <= n ) :\\n\\t\\tif ( n % i == 0 ) :\\n\\t\\t\\tsum = ( sum + i + math . floor ( n \\/ i ) ) ;\\n\\t\\ti += 1 ;\\n\\treturn sum ;\\ndef areEquivalent ( num1 , num2 ) :\\n\\treturn divSum ( num1 ) == divSum ( num2 ) ;\\nnum1 = 559 ;\\nnum2 = 703 ;\\nif ( areEquivalent ( num1 , num2 ) == True ) :\\n\\tprint ( \\\" Equivalent \\\" ) ;\\nelse :\\n\\tprint ( \\\" Not ▁ Equivalent \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\\"\\nSolution in Python:\",\"targets\":\"from math import *\\ndef printDivisors ( n ) :\\n\\ti = 1\\n\\twhile ( i * i < n ) :\\n\\t\\tif ( n % i == 0 ) :\\n\\t\\t\\tprint ( i , end = \\\" ▁ \\\" )\\n\\t\\ti += 1\\n\\tfor i in range ( int ( sqrt ( n ) ) , 0 , - 1 ) :\\n\\t\\tif ( n % i == 0 ) :\\n\\t\\t\\tprint ( n \\/\\/ i , end = \\\" ▁ \\\" )\\nprint ( \\\" The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ \\\" )\\nprintDivisors ( 100 )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Range Query on array whose each element is XOR of index value and previous element | function return derived formula value . ; finding xor value of range [ y ... x ] ; function to solve query for l and r . ; if l or r is 0. ; finding x is divisible by 2 or not . ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function fun ( $ x ) { $ y = ( ( int ) ( $ x \\/ 4 ) * 4 ) ; $ ans = 0 ; for ( $ i = $ y ; $ i <= $ x ; $ i ++ ) $ ans ^= $ i ; return $ ans ; } function query ( $ x ) { if ( $ x == 0 ) return 0 ; $ k = ( int ) ( ( $ x + 1 ) \\/ 2 ) ; return ( $ x %= 2 ) ? 2 * fun ( $ k ) : ( ( fun ( $ k - 1 ) * 2 ) ^ ( $ k & 1 ) ) ; } function allQueries ( $ q , $ l , $ r ) { for ( $ i = 0 ; $ i < $ q ; $ i ++ ) echo ( query ( $ r [ $ i ] ) ^ query ( $ l [ $ i ] - 1 ) ) , \\\" \\n \\\" ; } $ q = 3 ; $ l = array ( 2 , 2 , 5 ) ; $ r = array ( 4 , 8 , 9 ) ; allQueries ( $ q , $ l , $ r ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Print modified array after multiple array range increment operations | structure to store the ( start , end ) index pair for each query ; function to increment values in the given range by a value d for multiple queries ; for each ( start , end ) index pair , perform the following operations on ' sum [ ] ' ; increment the value at index ' start ' by the given value ' d ' in ' sum [ ] ' ; if the index ' ( end + 1 ) ' exists then decrement the value at index ' ( end + 1 ) ' by the given value ' d ' in ' sum [ ] ' ; Now , perform the following operations : accumulate values in the ' sum [ ] ' array and then add them to the corresponding indexes in ' arr [ ] ' ; function to print the elements of the given array ; Driver code ; modifying the array for multiple queries\\\"\\nHow can the above be solved in JS?\",\"targets\":\"class query { constructor ( start , end ) { this . start = start ; this . end = end ; } } function incrementByD ( arr , q_arr , n , m , d ) { let sum = new Array ( n ) ; for ( let i = 0 ; i < sum . length ; i ++ ) { sum [ i ] = 0 ; } for ( let i = 0 ; i < m ; i ++ ) { sum [ q_arr [ i ] . start ] += d ; if ( ( q_arr [ i ] . end + 1 ) < n ) sum [ q_arr [ i ] . end + 1 ] -= d ; } arr [ 0 ] += sum [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { sum [ i ] += sum [ i - 1 ] ; arr [ i ] += sum [ i ] ; } } function printArray ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + \\\" \\\" ) ; } let arr = [ 3 , 5 , 4 , 8 , 6 , 1 ] ; let q_arr = new Array ( 5 ) ; q_arr [ 0 ] = new query ( 0 , 3 ) ; q_arr [ 1 ] = new query ( 4 , 5 ) ; q_arr [ 2 ] = new query ( 1 , 4 ) ; q_arr [ 3 ] = new query ( 0 , 1 ) ; q_arr [ 4 ] = new query ( 2 , 5 ) ; let n = arr . length ; let m = q_arr . length ; let d = 2 ; document . write ( \\\" \\\" ) ; printArray ( arr , n ) ; incrementByD ( arr , q_arr , n , m , d ) ; document . write ( \\\" \\\" ) ; printArray ( arr , n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Number of occurrences of 2 as a digit in numbers from 0 to n | Counts the number of 2 s in a number at d - th digit ; if the digit in spot digit is ; Counts the number of '2' digits between 0 and n ; Convert integer to String to find its length ; Traverse every digit and count for every digit ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function count2sinRangeAtDigit ( $ number , $ d ) { $ powerOf10 = ( int ) pow ( 10 , $ d ) ; $ nextPowerOf10 = $ powerOf10 * 10 ; $ right = $ number % $ powerOf10 ; $ roundDown = $ number - $ number % $ nextPowerOf10 ; $ roundup = $ roundDown + $ nextPowerOf10 ; $ digit = ( $ number \\/ $ powerOf10 ) % 10 ; if ( $ digit < 2 ) return $ roundDown \\/ 10 ; if ( $ digit == 2 ) return $ roundDown \\/ 10 + $ right + 1 ; return $ roundup \\/ 10 ; } function numberOf2sinRange ( $ number ) { $ s = strval ( $ number ) ; $ len = strlen ( $ s ) ; $ count = 0 ; for ( $ digit = 0 ; $ digit < $ len ; $ digit ++ ) $ count += count2sinRangeAtDigit ( $ number , $ digit ) ; return $ count ; } print ( numberOf2sinRange ( 22 ) . \\\" \\n \\\" ) ; print ( numberOf2sinRange ( 100 ) . \\\" \\n \\\" ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to find amount of water in a given glass | Program to find the amount of water in j - th glass of i - th row ; Returns the amount of water in jth glass of ith row ; A row number i has maximum i columns . So input column number must be less than i ; There will be i * ( i + 1 ) \\/ 2 glasses till ith row ( including ith row ) ; Initialize all glasses as empty ; Put all water in first glass ; Now let the water flow to the downward glasses till the row number is less than or \\/ equal to i ( given row ) correction : X can be zero for side glasses as they have lower rate to fill ; Fill glasses in a given row . Number of columns in a row is equal to row number ; Get the water from current glass ; Keep the amount less than or equal to capacity in current glass ; Get the remaining amount ; Distribute the remaining amount to the down two glasses ; The index of jth glass in ith row will be i * ( i - 1 ) \\/ 2 + j - 1 ; Driver program to test above function ; Total amount of water\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#include \\n#include \\nfloat findWater ( int i , int j , float X ) { if ( j > i ) { printf ( \\\" Incorrect ▁ Inputn \\\" ) ; exit ( 0 ) ; } float glass [ i * ( i + 1 ) \\/ 2 ] ; memset ( glass , 0 , sizeof ( glass ) ) ; int index = 0 ; glass [ index ] = X ; for ( int row = 1 ; row <= i ; ++ row ) { for ( int col = 1 ; col <= row ; ++ col , ++ index ) { X = glass [ index ] ; glass [ index ] = ( X >= 1.0f ) ? 1.0f : X ; X = ( X >= 1.0f ) ? ( X - 1 ) : 0.0f ; glass [ index + row ] += X \\/ 2 ; glass [ index + row + 1 ] += X \\/ 2 ; } } return glass [ i * ( i - 1 ) \\/ 2 + j - 1 ] ; } int main ( ) { int i = 2 , j = 2 ; float X = 2.0 ; printf ( \\\" Amount ▁ of ▁ water ▁ in ▁ jth ▁ glass ▁ of ▁ ith ▁ row ▁ is : ▁ % f \\\" , findWater ( i , j , X ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Smallest and Largest N | Function to find n digit largest number starting and ending with n ; Corner Case when n = 1 ; Result will store the n - 2 * length ( n ) digit largest number ; Find the number of digits in number n ; Append 9 ; To make it largest n digit number starting and ending with n , we just need to append n at start and end ; Return the largest number ; Function to find n digit smallest number starting and ending with n ; Corner Case when n = 1 ; Result will store the n - 2 * length ( n ) digit smallest number ; Find the number of digits in number n ; To make it smallest n digit number starting and ending with n , we just need to append n at start and end ; Return the smallest number ; Given Number ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function findNumberL ( n ) { if ( n == 1 ) return \\\" \\\" ; let result = \\\" \\\" ; let length = Math . floor ( Math . log10 ( n ) + 1 ) ; for ( let i = 1 ; i <= n - ( 2 * length ) ; i ++ ) { result += ' ' ; } result = n . toString ( ) + result + n . toString ( ) ; return result ; } function findNumberS ( n ) { if ( n == 1 ) return \\\" \\\" ; let result = \\\" \\\" ; let length = Math . floor ( Math . log10 ( n ) + 1 ) ; for ( let i = 1 ; i <= n - ( 2 * length ) ; i ++ ) { result += ' ' ; } result = n . toString ( ) + result + n . toString ( ) ; return result ; } let N = 3 ; document . write ( \\\" \\\" + findNumberS ( N ) + \\\" \\\" ) ; document . write ( \\\" \\\" + findNumberL ( N ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count the number of pairs ( i , j ) such that either arr [ i ] is divisible by arr [ j ] or arr [ j ] is divisible by arr [ i ] | Function to find number of unordered pairs ; Maximum element from the array ; Array to store the frequency of each element ; Stores the number of unordered pairs ; Store the frequency of each element ; Find the number of unordered pairs ; If the number j divisible by ith element is present in the array ; If the ith element of the array has frequency more than one ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def freqPairs ( arr , n ) :\\n\\tmax = arr [ 0 ]\\n\\tfor i in range ( len ( arr ) ) :\\n\\t\\tif arr [ i ] > max :\\n\\t\\t\\tmax = arr [ i ]\\n\\tfreq = [ 0 for i in range ( max + 1 ) ]\\n\\tcount = 0\\n\\tfor i in range ( n ) :\\n\\t\\tfreq [ arr [ i ] ] += 1\\n\\tfor i in range ( n ) :\\n\\t\\tfor j in range ( 2 * arr [ i ] , max + 1 , arr [ i ] ) :\\n\\t\\t\\tif ( freq [ j ] >= 1 ) :\\n\\t\\t\\t\\tcount += freq [ j ]\\n\\t\\tif ( freq [ arr [ i ] ] > 1 ) :\\n\\t\\t\\tcount += freq [ arr [ i ] ] - 1\\n\\t\\t\\tfreq [ arr [ i ] ] -= 1\\n\\treturn count\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 3 , 2 , 4 , 2 , 6 ]\\n\\tn = len ( arr )\\n\\tprint ( freqPairs ( arr , n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Maximize minimum distance between repetitions from any permutation of the given Array | C ++ 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\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int findMaxLen ( vector < int > & a ) { int n = a . size ( ) ; int freq [ n + 1 ] ; memset ( freq , 0 , sizeof freq ) ; for ( int i = 0 ; i < n ; ++ i ) { freq [ a [ i ] ] ++ ; } int maxFreqElement = INT_MIN ; int maxFreqCount = 1 ; for ( int i = 1 ; i <= n ; ++ i ) { if ( freq [ i ] > maxFreqElement ) { maxFreqElement = freq [ i ] ; maxFreqCount = 1 ; } else if ( freq [ i ] == maxFreqElement ) maxFreqCount ++ ; } int ans ; if ( maxFreqElement == 1 ) ans = 0 ; else { ans = ( ( n - maxFreqCount ) \\/ ( maxFreqElement - 1 ) ) ; } return ans ; } int main ( ) { vector < int > a = { 1 , 2 , 1 , 2 } ; cout << findMaxLen ( a ) << endl ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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 php:\",\"targets\":\"< ? php function gcd ( $ a , $ b ) { if ( $ b == 0 ) return $ a ; else return gcd ( $ b , $ a % $ b ) ; } function lcmOfArray ( & $ arr , $ n ) { if ( $ n < 1 ) return 0 ; $ lcm = $ arr [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) $ lcm = ( $ lcm * $ arr [ $ i ] ) \\/ gcd ( $ lcm , $ arr [ $ i ] ) ; return $ lcm ; } function minPerfectCube ( & $ arr , $ n ) { $ lcm = lcmOfArray ( $ arr , $ n ) ; $ minPerfectCube = $ lcm ; $ cnt = 0 ; while ( $ lcm > 1 && $ lcm % 2 == 0 ) { $ cnt ++ ; $ lcm \\/= 2 ; } if ( $ cnt % 3 == 2 ) $ minPerfectCube *= 2 ; else if ( $ cnt % 3 == 1 ) $ minPerfectCube *= 4 ; $ i = 3 ; while ( $ lcm > 1 ) { $ cnt = 0 ; while ( $ lcm % $ i == 0 ) { $ cnt ++ ; $ lcm \\/= $ i ; } if ( $ cnt % 3 == 1 ) $ minPerfectCube *= $ i * $ i ; else if ( $ cnt % 3 == 2 ) $ minPerfectCube *= $ i ; $ i += 2 ; } return $ minPerfectCube ; } $ arr = array ( 10 , 125 , 14 , 42 , 100 ) ; $ n = sizeof ( $ arr ) ; echo ( minPerfectCube ( $ arr , $ n ) ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Queries to find the last non | Maximum distinct characters possible ; To store the frequency of the characters ; Function to pre - calculate the frequency array ; Only the first character has frequency 1 till index 0 ; Starting from the second character of the string ; For every possible character ; Current character under consideration ; If it is equal to the character at the current index ; Function to return the frequency of the given character in the sub - string $str [ $l ... $r ] ; Function to return the last non - repeating character ; Starting from the last character ; Current character ; If frequency of the current character is 1 then return the character ; All the characters of the sub - string are repeating ; Driver code ; Pre - calculate the frequency array\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php $ MAX = 256 ; $ freq = array_fill ( 0 , 256 , array_fill ( 0 , 1000 , 0 ) ) ; function preCalculate ( $ str , $ n ) { global $ freq ; global $ MAX ; $ freq [ ord ( $ str [ 0 ] ) ] [ 0 ] = 1 ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { $ ch = $ str [ $ i ] ; for ( $ j = 0 ; $ j < $ MAX ; $ j ++ ) { $ charToUpdate = chr ( $ j ) ; if ( $ charToUpdate == $ ch ) $ freq [ $ j ] [ $ i ] = $ freq [ $ j ] [ $ i - 1 ] + 1 ; else $ freq [ $ j ] [ $ i ] = $ freq [ $ j ] [ $ i - 1 ] ; } } } function getFrequency ( $ ch , $ l , $ r ) { global $ freq ; if ( $ l == 0 ) return $ freq [ ord ( $ ch ) ] [ $ r ] ; else return ( $ freq [ ord ( $ ch ) ] [ $ r ] - $ freq [ ord ( $ ch ) ] [ $ l - 1 ] ) ; } function lastNonRepeating ( $ str , $ n , $ l , $ r ) { for ( $ i = $ r ; $ i >= $ l ; $ i -- ) { $ ch = $ str [ $ i ] ; if ( getFrequency ( $ ch , $ l , $ r ) == 1 ) return $ ch ; } return \\\" - 1\\\" ; } $ str = \\\" GeeksForGeeks \\\" ; $ n = strlen ( $ str ) ; $ queries = array ( array ( 2 , 9 ) , array ( 2 , 3 ) , array ( 0 , 12 ) ) ; $ q = 3 ; preCalculate ( $ str , $ n ) ; for ( $ i = 0 ; $ i < $ q ; $ i ++ ) { echo ( lastNonRepeating ( $ str , $ n , $ queries [ $ i ] [ 0 ] , $ queries [ $ i ] [ 1 ] ) ) , \\\" \\n \\\" ; } ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to print binomial expansion 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 ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def series ( A , X , n ) :\\n\\tterm = pow ( A , n )\\n\\tprint ( term , end = \\\" ▁ \\\" )\\n\\tfor i in range ( 1 , n + 1 ) :\\n\\t\\tterm = int ( term * X * ( n - i + 1 ) \\/ ( i * A ) )\\n\\t\\tprint ( term , end = \\\" ▁ \\\" )\\nA = 3 ; X = 4 ; n = 5\\nseries ( A , X , n )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"Three numbers in a BST that adds upto zero | A C program to check if there is a triplet with sum equal to 0 in a given BST ; A BST node has key , and left and right pointers ; A function to convert given BST to Doubly Linked List . left pointer is used as previous pointer and right pointer is used as next pointer . The function sets * head to point to first and * tail to point to last node of converted DLL ; Base case ; First convert the left subtree ; Then change left of current root as last node of left subtree ; If tail is not NULL , then set right of tail as root , else current node is head ; Update tail ; Finally , convert right subtree ; This function returns true if there is pair in DLL with sum equal to given sum . The algorithm is similar to hasArrayTwoCandidates ( ) tinyurl . com \\/ dy6palr in method 1 of http : ; The main function that returns true if there is a 0 sum triplet in BST otherwise returns false ; Check if the given BST is empty ; Convert given BST to doubly linked list . head and tail store the pointers to first and last nodes in DLLL ; Now iterate through every node and find if there is a pair with sum equal to - 1 * heaf -> key where head is current node ; If there is a pair with sum equal to - 1 * head -> key , then return true else move forward ; If we reach here , then there was no 0 sum triplet ; A utility function to create a new BST node with key as given num ; A utility function to insert a given key to BST ; Driver program to test above functions\\nHow can the above be solved in C?\",\"targets\":\"#include \\nstruct node { int key ; struct node * left ; struct node * right ; } ; void convertBSTtoDLL ( node * root , node * * head , node * * tail ) { if ( root == NULL ) return ; if ( root -> left ) convertBSTtoDLL ( root -> left , head , tail ) ; root -> left = * tail ; if ( * tail ) ( * tail ) -> right = root ; else * head = root ; * tail = root ; if ( root -> right ) convertBSTtoDLL ( root -> right , head , tail ) ; } bool isPresentInDLL ( node * head , node * tail , int sum ) { while ( head != tail ) { int curr = head -> key + tail -> key ; if ( curr == sum ) return true ; else if ( curr > sum ) tail = tail -> left ; else head = head -> right ; } return false ; } bool isTripletPresent ( node * root ) { if ( root == NULL ) return false ; node * head = NULL ; node * tail = NULL ; convertBSTtoDLL ( root , & head , & tail ) ; while ( ( head -> right != tail ) && ( head -> key < 0 ) ) { if ( isPresentInDLL ( head -> right , tail , -1 * head -> key ) ) return true ; else head = head -> right ; } return false ; } node * newNode ( int num ) { node * temp = new node ; temp -> key = num ; temp -> left = temp -> right = NULL ; return temp ; } node * insert ( node * root , int key ) { if ( root == NULL ) return newNode ( key ) ; if ( root -> key > key ) root -> left = insert ( root -> left , key ) ; else root -> right = insert ( root -> right , key ) ; return root ; } int main ( ) { node * root = NULL ; root = insert ( root , 6 ) ; root = insert ( root , -13 ) ; root = insert ( root , 14 ) ; root = insert ( root , -8 ) ; root = insert ( root , 15 ) ; root = insert ( root , 13 ) ; root = insert ( root , 7 ) ; if ( isTripletPresent ( root ) ) printf ( \\\" Present \\\" ) ; else printf ( \\\" Not ▁ Present \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Ways to write N as sum of two or more positive integers | Set | Function to find the number of partitions of N ; Base case ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function partitions ( n ) { var p = Array ( n + 1 ) . fill ( 0 ) ; p [ 0 ] = 1 ; for ( i = 1 ; i <= n ; ++ i ) { var k = 1 ; while ( ( k * ( 3 * k - 1 ) ) \\/ 2 <= i ) { p [ i ] += ( k % 2 != 0 ? 1 : - 1 ) * p [ i - ( k * ( 3 * k - 1 ) ) \\/ 2 ] ; if ( k > 0 ) { k *= - 1 ; } else { k = 1 - k ; } } } return p [ n ] ; } var N = 20 ; document . write ( partitions ( N ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Count of indices in an array that satisfy the given condition | C # implementation of the approach ; Function to return the count of indices that satisfy the given condition ; To store the result ; To store the current maximum Initialized to 0 since there are only positive elements in the array ; i is a valid index ; Update the maximum so far ; Increment the counter ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int countIndices ( int [ ] arr , int n ) { int cnt = 0 ; int max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( max < arr [ i ] ) { max = arr [ i ] ; cnt ++ ; } } return cnt ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 } ; int n = arr . Length ; Console . WriteLine ( countIndices ( arr , n ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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 ▁ obtained ▁ value ▁ is ▁ % d ▁ \\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\":\"\\\"Number of permutation with K inversions | Set 2 | Function to count permutations with K inversions ; Store number of permutations with K inversions ; If N = 1 only 1 permutation with no inversion ; For K = 0 only 1 permutation with no inversion ; Otherwise Update each dp state as per the reccurrance relation formed ; Print final count ; Given N and K ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function numberOfPermWithKInversion ( N , K ) { let dp = new Array ( 2 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } let mod = 1000000007 ; for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = 0 ; j <= K ; j ++ ) { if ( i == 1 ) { dp [ i % 2 ] [ j ] = ( j == 0 ) ? 1 : 0 ; } else if ( j == 0 ) dp [ i % 2 ] [ j ] = 1 ; else dp [ i % 2 ] [ j ] = ( dp [ i % 2 ] [ j - 1 ] % mod + ( dp [ 1 - i % 2 ] [ j ] - ( ( Math . max ( j - ( i - 1 ) , 0 ) == 0 ) ? 0 : dp [ 1 - i % 2 ] [ Math . max ( j - ( i - 1 ) , 0 ) - 1 ] ) + mod ) % mod ) % mod ; } } document . write ( dp [ N % 2 ] [ K ] ) ; } let N = 3 , K = 2 ; numberOfPermWithKInversion ( N , K ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Missing occurrences of a number in an array such that maximum absolute difference of adjacent elements is minimum | C ++ implementation of the missing number such that maximum absolute difference between adjacent element is minimum ; Function to find the missing number such that maximum absolute difference is minimum ; Loop to find the maximum and minimum adjacent element to missing number ; Driver Code ; Function Call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int missingnumber ( int n , int arr [ ] ) { int mn = INT_MAX , mx = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { if ( i > 0 && arr [ i ] == -1 && arr [ i - 1 ] != -1 ) { mn = min ( mn , arr [ i - 1 ] ) ; mx = max ( mx , arr [ i - 1 ] ) ; } if ( i < ( n - 1 ) && arr [ i ] == -1 && arr [ i + 1 ] != -1 ) { mn = min ( mn , arr [ i + 1 ] ) ; mx = max ( mx , arr [ i + 1 ] ) ; } } long long int res = ( mx + mn ) \\/ 2 ; return res ; } int main ( ) { int n = 5 ; int arr [ 5 ] = { -1 , 10 , -1 , 12 , -1 } ; int ans = 0 ; int res = missingnumber ( n , arr ) ; cout << res ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Coin Change | DP | Dynamic Programming C # implementation of Coin Change problem ; table [ i ] will be storing the number of solutions for value i . We need n + 1 rows as the table is constructed in bottom up manner using the base case ( n = 0 ) ; Base case ( If given value is 0 ) ; Pick all coins one by one and update the table [ ] values after the index greater than or equal to the value of the picked coin ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int count ( int [ ] S , int m , int n ) { int [ ] table = new int [ n + 1 ] ; table [ 0 ] = 1 ; for ( int i = 0 ; i < m ; i ++ ) for ( int j = S [ i ] ; j <= n ; j ++ ) table [ j ] += table [ j - S [ i ] ] ; return table [ n ] ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 } ; int m = arr . Length ; int n = 4 ; Console . Write ( count ( arr , m , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find Prime number just less than and just greater each element of given Array | Python3 program for the above approach ; Utility function to check for primality of a number X by checking whether X haACCs any factors other than 1 and itself . ; Factor found ; Function to print primes just less than and just greater than of each element in an array ; Traverse the array ; Traverse for finding prime just less than A [ i ] ; Prime just less than A [ i ] found ; Traverse for finding prime just greater than A [ i ] ; Prime just greater than A [ i ] found ; Driver code ; Input ; Function call\\\"\\nSolution in Python:\",\"targets\":\"from math import sqrt\\ndef isPrime ( X ) :\\n\\tfor i in range ( 2 , int ( sqrt ( X ) ) + 1 , 1 ) :\\n\\t\\tif ( X % i == 0 ) :\\n\\t\\t\\treturn False\\n\\treturn True\\ndef printPrimes ( A , N ) :\\n\\tfor i in range ( N ) :\\n\\t\\tj = A [ i ] - 1\\n\\t\\twhile ( 1 ) :\\n\\t\\t\\tif ( isPrime ( j ) ) :\\n\\t\\t\\t\\tprint ( j , end = \\\" ▁ \\\" )\\n\\t\\t\\t\\tbreak\\n\\t\\t\\tj -= 1\\n\\t\\tj = A [ i ] + 1\\n\\t\\twhile ( 1 ) :\\n\\t\\t\\tif ( isPrime ( j ) ) :\\n\\t\\t\\t\\tprint ( j , end = \\\" ▁ \\\" )\\n\\t\\t\\t\\tbreak\\n\\t\\t\\tj += 1\\n\\t\\tprint ( \\\" \\\" , ▁ end ▁ = ▁ \\\" \\\" )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tA = [ 17 , 28 ]\\n\\tN = len ( A )\\n\\tprintPrimes ( A , N )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"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\\\"\\nSolution 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\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if string is right to left diagonal or not | Python3 program to Check if the given is right to left diagonal or not ; Function to check if the given 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 Python?\",\"targets\":\"from math import sqrt , floor , ceil\\ndef is_rtol ( s ) :\\n\\ttmp = floor ( sqrt ( len ( s ) ) ) - 1\\n\\tfirst = s [ tmp ]\\n\\tfor pos in range ( tmp , len ( s ) - 1 , tmp ) :\\n\\t\\tif ( s [ pos ] != first ) :\\n\\t\\t\\treturn False\\n\\treturn True\\nif __name__ == ' _ _ main _ _ ' :\\n\\tstr = \\\" abcxabxcaxbcxabc \\\"\\n\\tif ( is_rtol ( str ) ) :\\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\":\"\\\"Find the longest sub | Function to find longest prefix suffix ; To store longest prefix suffix ; Length of the previous longest prefix suffix ; lps [ 0 ] is always 0 ; Loop calculates lps [ i ] for i = 1 to n - 1 ; ( pat [ i ] != pat [ len ] ) ; If len = 0 ; Function to find the longest substring which is prefix as well as a sub - string of s [ 1. . . n - 2 ] ; Find longest prefix suffix ; If lps of n - 1 is zero ; At any position lps [ i ] equals to lps [ n - 1 ] ; If answer is not possible ; Driver code ; function call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function compute_lps ( s ) { var n = s . length ; var lps = Array ( n ) ; var len = 0 ; lps [ 0 ] = 0 ; var i = 1 ; 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 ; } function Longestsubstring ( s ) { var lps = compute_lps ( s ) ; var n = s . length ; if ( lps [ n - 1 ] == 0 ) { document . write ( - 1 ) ; return ; } for ( var i = 0 ; i < n - 1 ; i ++ ) { if ( lps [ i ] == lps [ n - 1 ] ) { document . write ( s . substring ( 0 , lps [ i ] ) ) ; return ; } } if ( lps [ lps [ n - 1 ] - 1 ] == 0 ) document . write ( - 1 ) ; else document . write ( s . substr ( 0 , lps [ lps [ n - 1 ] - 1 ] ) ) ; } var s = \\\" \\\" ; Longestsubstring ( s ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Longest subsequence where each character occurs at least k times | C # Program to find the subsequence with each character occurring at least k times in string s ; 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\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int MAX_CHAR = 26 ; static void findSubsequence ( string str , int k ) { int [ ] a = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < str . Length ; i ++ ) a [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < str . Length ; i ++ ) if ( a [ str [ i ] - ' a ' ] >= k ) Console . Write ( str [ i ] ) ; } public static void Main ( ) { int k = 2 ; findSubsequence ( \\\" geeksforgeeks \\\" , k ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Queries for counts of array elements with values in given range | Simple java program to count number of elements with values in given range . ; function to count elements within given range ; initialize result ; check if element is in range ; driver function ; Answer queries\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; class GFG { static int countInRange ( int arr [ ] , int n , int x , int y ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 4 , 9 , 10 , 3 } ; int n = arr . length ; int i = 1 , j = 4 ; System . out . println ( countInRange ( arr , n , i , j ) ) ; i = 9 ; j = 12 ; System . out . println ( countInRange ( arr , n , i , j ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check if number can be displayed using seven segment led | Pre - computed values of segment used by digit 0 to 9. ; Check if it is possible to display the number ; Finding sum of the segments used by each digit of the number ; Driver Code ; Function call to print required answer\\\"\\nSolution in php:\",\"targets\":\"< ? php $ seg = array ( 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ) ; function LedRequired ( $ s , $ led ) { $ count = 0 ; global $ seg ; for ( $ i = 0 ; $ i < strlen ( $ s ) ; ++ $ i ) { $ count += $ seg [ ord ( $ s [ $ i ] ) - 48 ] ; } if ( $ count <= $ led ) return \\\" YES \\\" ; else return \\\" NO \\\" ; } $ S = \\\"123456789\\\" ; $ led = 20 ; echo LedRequired ( $ S , $ led ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Next Greater Element | Simple C program to print next greater elements in a given array ; prints element and NGE pair for all elements of arr [ ] of size n ; Driver Code\\\"\\nSolution in C:\",\"targets\":\"#include \\nvoid printNGE ( int arr [ ] , int n ) { int next , i , j ; for ( i = 0 ; i < n ; i ++ ) { next = -1 ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] < arr [ j ] ) { next = arr [ j ] ; break ; } } printf ( \\\" % d ▁ - - ▁ % dn \\\" , arr [ i ] , next ) ; } } int main ( ) { int arr [ ] = { 11 , 13 , 21 , 3 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; printNGE ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Snake case of a given sentence | Function to replace spaces and convert into snake case ; Converting space to underscor ; If not space , convert into lower character ; Driver Code ; Calling function\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function convert ( $ str ) { $ n = strlen ( $ str ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ str [ $ i ] == ' ▁ ' ) $ str [ $ i ] = ' _ ' ; else $ str [ $ i ] = strtolower ( $ str [ $ i ] ) ; } echo $ str ; } $ str = \\\" I ▁ got ▁ intern ▁ at ▁ geeksforgeeks \\\" ; convert ( $ str ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count removal of pairs required to be empty all Balanced Parenthesis subsequences | Function to find the maximum count of pairs required to be removed such that subsequence of string does not contain any valid parenthesis ; Stores count of pairs of balanced parenthesis ; Stores count of curly balanced parenthesis ; Stores count of small balanced parenthesis ; Stores count of square balanced parenthesis ; Iterate over characters of the string ; Update cntCurly ; Update cntSml ; Update cntSqr ; Update cntCurly ; Update cntPairs ; Update cntSml ; Update cntPairs ; Update cntSml ; Update cntPairs ; Given String ; Function call\\\"\\nSolution in Javascript:\",\"targets\":\"function cntBalancedParenthesis ( s , N ) { var cntPairs = 0 ; var cntCurly = 0 ; var cntSml = 0 ; var cntSqr = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { cntCurly ++ ; } else if ( s . charAt ( i ) == ' ' ) { cntSml ++ ; } else if ( s . charAt ( i ) == ' ' ) { cntSqr ++ ; } else if ( s . charAt ( i ) == ' ' && cntCurly > 0 ) { cntCurly -- ; cntPairs ++ ; } else if ( s . charAt ( i ) == ' ' && cntSml > 0 ) { cntSml -- ; cntPairs ++ ; } else if ( s . charAt ( i ) == ' ' && cntSqr > 0 ) { cntSqr -- ; cntPairs ++ ; } } document . write ( cntPairs ) ; } var s = \\\" \\\" ; var N = s . length ; cntBalancedParenthesis ( s , N ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\\\"\\nHow can the above be solved 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\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Sqrt ( or Square Root ) Decomposition | Set 2 ( LCA of Tree in O ( sqrt ( height ) ) time ) | Naive Javascrit implementation to find LCA in a tree . ; Stores depth for each node ; Stores first parent for each node ; Marking parent for each node ; Marking depth for each node ; Propogating marking down the tree ; A dummy node ; Precalclating 1 ) depth . 2 ) parent . for each node ; Time Complexity : O ( Height of tree ) recursively jumps one node above till both the nodes become equal ; Driver Code ; Adding edges to the tree\\\"\\nHow can the above be solved in JS?\",\"targets\":\"var MAXN = 1001 ; var depth = Array ( MAXN ) ; var parent = Array ( MAXN ) ; var adj = Array . from ( Array ( MAXN ) , ( ) => Array ( ) ) ; function addEdge ( u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } function dfs ( cur , prev ) { parent [ cur ] = prev ; depth [ cur ] = depth [ prev ] + 1 ; for ( var i = 0 ; i < adj [ cur ] . length ; i ++ ) if ( adj [ cur ] [ i ] != prev ) dfs ( adj [ cur ] [ i ] , cur ) ; } function preprocess ( ) { depth [ 0 ] = - 1 ; dfs ( 1 , 0 ) ; } function LCANaive ( u , v ) { if ( u == v ) return u ; if ( depth [ u ] > depth [ v ] ) { var temp = u ; u = v ; v = temp ; } v = parent [ v ] ; return LCANaive ( u , v ) ; } for ( var i = 0 ; i < MAXN ; i ++ ) adj [ i ] = [ ] ; addEdge ( 1 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 1 , 4 ) ; addEdge ( 2 , 5 ) ; addEdge ( 2 , 6 ) ; addEdge ( 3 , 7 ) ; addEdge ( 4 , 8 ) ; addEdge ( 4 , 9 ) ; addEdge ( 9 , 10 ) ; addEdge ( 9 , 11 ) ; addEdge ( 7 , 12 ) ; addEdge ( 7 , 13 ) ; preprocess ( ) ; document . write ( \\\" \\\" + LCANaive ( 11 , 8 ) + \\\" \\\" ) ; document . write ( \\\" \\\" + LCANaive ( 3 , 13 ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\\nHow can the above be solved in C?\",\"targets\":\"#include \\nbool isSubsetSum ( int set [ ] , int n , int sum ) { bool subset [ n + 1 ] [ sum + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) subset [ i ] [ 0 ] = true ; for ( int i = 1 ; i <= sum ; i ++ ) subset [ 0 ] [ i ] = false ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( j < set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ; if ( j >= set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - set [ i - 1 ] ] ; } } for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= sum ; j ++ ) printf ( \\\" % 4d \\\" , subset [ i ] [ j ] ) ; printf ( \\\" \\n \\\" ) ; } return subset [ n ] [ sum ] ; } 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 ) printf ( \\\" Found ▁ a ▁ subset ▁ with ▁ given ▁ sum \\\" ) ; else printf ( \\\" No ▁ subset ▁ with ▁ given ▁ sum \\\" ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Left rotate digits of node values of all levels of a Binary Tree in increasing order | TreeNode class ; Function to check if the nodes are in increasing order or not ; Perform Level Order Traversal ; Current len of queue ; If queue is empty ; Level order traversal ; Pop element from front of the queue ; If previous value exceeds current value , return false ; Function to print the Tree after modification ; Performs level order traversal ; Calculate size of the queue ; Iterate until queue is empty ; Function to arrange node values of each level in increasing order ; Perform level order traversal ; Calculate len of queue ; If queue is empty ; Level order traversal ; Pop element from front of the queue ; Initialize the optimal element by the initial element ; Check for all left shift operations ; Left shift ; If the current shifting gives optimal solution ; Replacing initial element by the optimal element ; Push the LST ; Push the RST ; Print the result ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"class Node { constructor ( v ) { this . val = v ; this . left = this . right = null ; } } function isInc ( root ) { let que = [ ] ; que . push ( root ) ; while ( true ) { let len = que . length ; if ( len == 0 ) break ; let pre = que [ 0 ] ; while ( len > 0 ) { let temp = que [ 0 ] ; que . shift ( ) ; if ( pre . val > temp . val ) return false ; pre = temp ; if ( temp . left != null ) que . push ( temp . left ) ; if ( temp . right != null ) que . push ( temp . right ) ; len -= 1 ; } } return true ; } function levelOrder ( root ) { let que = [ ] ; que . push ( root ) ; while ( true ) { let len = que . length ; if ( len == 0 ) break ; while ( len > 0 ) { let temp = que [ 0 ] ; que . shift ( ) ; document . write ( temp . val + \\\" \\\" ) ; if ( temp . left != null ) que . push ( temp . left ) ; if ( temp . right != null ) que . push ( temp . right ) ; len -= 1 ; } document . write ( \\\" \\\" ) ; } document . write ( \\\" \\\" ) ; } function makeInc ( root ) { let que = [ ] ; que . push ( root ) ; while ( true ) { let len = que . length ; if ( len == 0 ) break ; let prev = - 1 ; while ( len > 0 ) { let temp = que [ 0 ] ; que . shift ( ) ; let optEle = temp . val ; let strEle = ( optEle ) . toString ( ) ; let flag = true ; let yy = strEle . length ; for ( let idx = 0 ; idx < strEle . length ; idx ++ ) { let s1 = strEle . substring ( idx , yy ) ; let s2 = strEle . substring ( 0 , idx ) ; let s = s1 + s2 ; let ls = parseInt ( s ) ; if ( ls >= prev && flag ) { optEle = ls ; flag = false ; } if ( ls >= prev ) optEle = Math . min ( optEle , ls ) ; } temp . val = optEle ; prev = temp . val ; if ( temp . left != null ) que . push ( temp . left ) ; if ( temp . right != null ) que . push ( temp . right ) ; len -= 1 ; } } if ( isInc ( root ) == true ) levelOrder ( root ) ; else document . write ( - 1 ) ; } let root = new Node ( 341 ) ; root . left = new Node ( 241 ) ; root . right = new Node ( 123 ) ; root . left . left = new Node ( 324 ) ; root . left . right = new Node ( 235 ) ; root . right . right = new Node ( 161 ) ; makeInc ( root ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program to print numbers from N to 1 in reverse order | Java program to print all numbers between 1 to N in reverse order ; Recursive function to print from N to 1 ; If N is less than 1 then return static void function ; Recursive call of the function ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static void PrintReverseOrder ( int N ) { if ( N <= 0 ) { return ; } else { System . out . print ( N + \\\" ▁ \\\" ) ; PrintReverseOrder ( N - 1 ) ; } } public static void main ( String [ ] args ) { int N = 5 ; PrintReverseOrder ( N ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Delete alternate nodes of a Linked List | deletes alternate nodes of a list starting with head ; Change the next link of head ; free memory allocated for node ; Recursively call for the new next of head\\\"\\nSolution in C:\",\"targets\":\"void deleteAlt ( struct Node * head ) { if ( head == NULL ) return ; struct Node * node = head -> next ; if ( node == NULL ) return ; head -> next = node -> next ; free ( node ) ; deleteAlt ( head -> next ) ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Check if sum of arr [ i ] \\/ j for all possible pairs ( i , j ) in an array is 0 or not | C ++ program for the above approach ; Function to check if sum of all values of ( arr [ i ] \\/ j ) for all 0 < i <= j < ( N - 1 ) is 0 or not ; Stores the required sum ; Traverse the array ; If the sum is equal to 0 ; Otherwise ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void check ( int arr [ ] , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; if ( sum == 0 ) cout << \\\" Yes \\\" ; else cout << \\\" No \\\" ; } int main ( ) { int arr [ ] = { 1 , -1 , 3 , -2 , -1 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; check ( arr , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Icositetragonal Number | Function to find icositetragonal number ; Formula to calculate nth icositetragonal number ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function Icositetragonal_num ( n ) { return ( 22 * n * n - 20 * n ) \\/ 2 ; } let n = 3 ; document . write ( Icositetragonal_num ( n ) + \\\" \\\" ) ; n = 10 ; document . write ( Icositetragonal_num ( n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Sum of absolute differences of indices of occurrences of each array element | Java program for the above approach ; Function to find sum of differences of indices of occurrences of each unique array element ; Stores indices of each array element ; Store the indices ; Stores the sums ; Traverse the array ; Find sum for each element ; Iterate over the Map ; Calculate sum of occurrences of arr [ i ] ; Store sum for current element ; Print answer for each element ; Driver Code ; Given array ; Given size ; Function call\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static void sum ( int arr [ ] , int n ) { HashMap < Integer , Vector < Integer > > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Vector < Integer > v = new Vector < > ( ) ; v . add ( i ) ; if ( mp . containsKey ( arr [ i ] ) ) v . addAll ( mp . get ( arr [ i ] ) ) ; mp . put ( arr [ i ] , v ) ; } int [ ] ans = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; for ( int it : mp . get ( arr [ i ] ) ) { sum += Math . abs ( it - i ) ; } ans [ i ] = sum ; } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( ans [ i ] + \\\" ▁ \\\" ) ; } return ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 1 , 1 , 2 } ; int n = arr . length ; sum ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Remove characters from a String that appears exactly K times | C ++ program to remove characters from a String that appears exactly K times ; Function to reduce the string by removing the characters which appears exactly k times ; Hash table initialised to 0 ; Increment the frequency of the character ; To store answer ; Next index in reduced string ; Append the characters which appears exactly k times ; Driver code ; Function call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; const int MAX_CHAR = 26 ; string removeChars ( char arr [ ] , int k ) { int hash [ MAX_CHAR ] = { 0 } ; int n = strlen ( arr ) ; for ( int i = 0 ; i < n ; ++ i ) hash [ arr [ i ] - ' a ' ] ++ ; string ans = \\\" \\\" ; int index = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( hash [ arr [ i ] - ' a ' ] != k ) { ans += arr [ i ] ; } } return ans ; } int main ( ) { char str [ ] = \\\" geeksforgeeks \\\" ; int k = 2 ; cout << removeChars ( str , k ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Largest gap in an array | A Python 3 program to find largest gap between two elements in an array . ; function to solve the given problem ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"import sys\\ndef solve ( a , n ) :\\n\\tmax1 = - sys . maxsize - 1\\n\\tfor i in range ( 0 , n , 1 ) :\\n\\t\\tfor j in range ( 0 , n , 1 ) :\\n\\t\\t\\tif ( abs ( a [ i ] - a [ j ] ) > max1 ) :\\n\\t\\t\\t\\tmax1 = abs ( a [ i ] - a [ j ] )\\n\\treturn max1\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ - 1 , 2 , 3 , - 4 , - 10 , 22 ]\\n\\tsize = len ( arr )\\n\\tprint ( \\\" Largest ▁ gap ▁ is ▁ : \\\" , solve ( arr , size ) )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count pairs ( i , j ) from arrays arr [ ] & brr [ ] such that arr [ i ] | Java program for the above approach ; Function to find the minimum number needed to be added so that the sum of the digits does not exceed K ; Stores the sum of element at each corresponding index ; Find the sum of each index of both array ; Stores frequency of each element present in sumArr map < int , int > freqCount ; ; Initialize number of pairs ; Add possible vaid pairs ; Return Number of Pairs ; Driver Code ; Given array arr [ ] and brr [ ] ; Size of given array ; Function calling\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; import java . io . * ; class GFG { static void CountPairs ( int a [ ] , int b [ ] , int n ) { int C [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { C [ i ] = a [ i ] + b [ i ] ; } HashMap < Integer , Integer > freqCount = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! freqCount . containsKey ( C [ i ] ) ) freqCount . put ( C [ i ] , 1 ) ; else freqCount . put ( C [ i ] , freqCount . get ( C [ i ] ) + 1 ) ; } int NoOfPairs = 0 ; for ( Map . Entry < Integer , Integer > x : freqCount . entrySet ( ) ) { int y = x . getValue ( ) ; NoOfPairs = NoOfPairs + y * ( y - 1 ) \\/ 2 ; } System . out . println ( NoOfPairs ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 4 , 20 , 3 , 10 , 5 } ; int brr [ ] = { 9 , 6 , 1 , 7 , 11 , 6 } ; int N = arr . length ; CountPairs ( arr , brr , N ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Next Number with distinct digits | C # program to find next consecutive Number with all distinct digits ; Function to count distinct digits in a number ; To count the occurrence of digits in number from 0 to 9 ; Iterate over the digits of the number Flag those digits as found in the array ; Traverse the array arr and count the distinct digits in the array ; Function to return the total number of digits in the number ; Iterate over the digits of the number ; Function to return the next number with distinct digits ; Count the distinct digits in N + 1 ; Count the total number of digits in N + 1 ; Return the next consecutive number ; Increment Number by 1 ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { readonly static int INT_MAX = int . MaxValue ; static int countDistinct ( int n ) { int [ ] arr = new int [ 10 ] ; int count = 0 ; while ( n != 0 ) { int r = n % 10 ; arr [ r ] = 1 ; n \\/= 10 ; } for ( int i = 0 ; i < 10 ; i ++ ) { if ( arr [ i ] != 0 ) count ++ ; } return count ; } static int countDigit ( int n ) { int c = 0 ; while ( n != 0 ) { int r = n % 10 ; c ++ ; n \\/= 10 ; } return c ; } static int nextNumberDistinctDigit ( int n ) { while ( n < INT_MAX ) { int distinct_digits = countDistinct ( n + 1 ) ; int total_digits = countDigit ( n + 1 ) ; if ( distinct_digits == total_digits ) { return n + 1 ; } else n ++ ; } return - 1 ; } public static void Main ( String [ ] args ) { int n = 2019 ; Console . WriteLine ( nextNumberDistinctDigit ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximum height of triangular arrangement of array values | PHP 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\\\"\\nSolution in php:\",\"targets\":\"< ? php function MaximumHeight ( $ a , $ n ) { $ result = 1 ; for ( $ i = 1 ; $ i <= $ n ; ++ $ i ) { $ y = ( $ i * ( $ i + 1 ) ) \\/ 2 ; if ( $ y < $ n ) $ result = $ i ; else break ; } return $ result ; } $ arr = array ( 40 , 100 , 20 , 30 ) ; $ n = count ( $ arr ) ; echo MaximumHeight ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Median of difference of all pairs from an Array | Java program to implement the above approach ; Function check if mid can be median index of the difference array ; Size of the array ; Total possible no of pair possible ; The index of the element in the difference of all pairs from the array ; Count the number of pairs having difference <= mid ; If the difference between end and first element is less then or equal to mid ; Checking for the no of element less than or equal to mid is greater than median or not ; Function to calculate the median of differences of all pairs from the array ; Size of the array ; Initialising the low and high ; Binary search ; Calculate mid ; If mid can be the median of the array ; Returning the median of the differences of pairs from the array ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class GFG { static boolean possible ( long mid , int [ ] a ) { long n = a . length ; long total = ( n * ( n - 1 ) ) \\/ 2 ; long need = ( total + 1 ) \\/ 2 ; long count = 0 ; long start = 0 , end = 1 ; while ( end < n ) { if ( a [ ( int ) end ] - a [ ( int ) start ] <= mid ) { end ++ ; } else { count += ( end - start - 1 ) ; start ++ ; } } if ( end == n && start < end && a [ ( int ) end - 1 ] - a [ ( int ) start ] <= mid ) { long t = end - start - 1 ; count += ( t * ( t + 1 ) \\/ 2 ) ; } if ( count >= need ) return true ; else return false ; } static long findMedian ( int [ ] a ) { long n = a . length ; long low = 0 , high = a [ ( int ) n - 1 ] - a [ 0 ] ; while ( low <= high ) { long mid = ( low + high ) \\/ 2 ; if ( possible ( mid , a ) ) high = mid - 1 ; else low = mid + 1 ; } return high + 1 ; } public static void main ( String [ ] args ) { int [ ] a = { 1 , 7 , 5 , 2 } ; Arrays . sort ( a ) ; System . out . println ( findMedian ( a ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Lengths of maximized partitions of a string such that each character of the string appears in one substring | Function to find the length of all partitions oof a String such that each characters occurs in a single subString ; Stores last index of String s ; Find the last position of each letter in the String ; Update the last index ; Iterate the given String ; Get the last index of s [ i ] ; Extend the current partition characters last pos ; Increase len of partition ; if the current pos of character equals the min pos then the end of partition ; Store the length ; Print all the partition lengths ; Given String str ; Function Call\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function partitionString ( s ) { let n = s . length ; let ans = [ ] ; if ( n == 0 ) { document . write ( \\\" \\\" ) ; return ; } let last_pos = Array ( 26 ) . fill ( - 1 ) ; for ( let i = n - 1 ; i >= 0 ; -- i ) { if ( last_pos [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] == - 1 ) { last_pos [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] = i ; } } let minp = - 1 , plen = 0 ; for ( let i = 0 ; i < n ; ++ i ) { let lp = last_pos [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ; minp = Math . max ( minp , lp ) ; ++ plen ; if ( i == minp ) { ans . push ( plen ) ; minp = - 1 ; plen = 0 ; } } for ( let i = 0 ; i < ans . length ; i ++ ) { document . write ( ans [ i ] + \\\" \\\" ) ; } } let str = \\\" \\\" ; partitionString ( str ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Array Range Queries to find the Maximum Armstrong number with updates | C # code to implement the above approach ; A utility function to get the middle index of given range . ; Function that return true if num is armstrong else return false ; A recursive function to get the sum of values in the given range of 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 segment of this node is completely part of given range , then return the max of segment . ; If segment of this node does not belong to given range ; If segment of this node is partially the part of given range ; A recursive function to update the nodes which have the given the index in their range . The following are parameters st , ss and se are same as defined above index . index of the element to be updated . ; update value in array and in segment tree ; Return max of elements in range from index l ( query start ) to r ( query end ) . ; Check for erroneous input values ; A recursive function that constructs Segment Tree for array [ ss . . se ] . si is index of current node in segment tree st ; If there is one element in array , store it in current node of segment tree and return ; If there are more than one elements , then recur for left and right subtrees and store the max of values in this node ; Function to cona segment tree from given array . This function allocates memory for segment tree . ; Height of segment tree ; Maximum size of segment tree ; Allocate memory ; Fill the allocated memory st ; Return the constructed segment tree ; Driver code ; Build segment tree from given array ; Print max of values in array from index 1 to 3 ; Update : set arr [ 1 ] = 153 and update corresponding segment tree nodes . ; Find max after the value is updated\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int getMid ( int s , int e ) { return s + ( e - s ) \\/ 2 ; } static bool isArmstrong ( int x ) { int n = String . Join ( \\\" \\\" , x ) . Length ; int sum1 = 0 ; int temp = x ; while ( temp > 0 ) { int digit = temp % 10 ; sum1 += ( int ) Math . Pow ( digit , n ) ; temp \\/= 10 ; } if ( sum1 == x ) return true ; return false ; } 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 ) , MaxUtil ( st , mid + 1 , se , l , r , 2 * node + 1 ) ) ; } static void updateValue ( int [ ] arr , int [ ] st , int ss , int se , int index , int value , int node ) { if ( index < ss index > se ) { Console . Write ( \\\" Invalid ▁ Input \\\" + \\\" \\n \\\" ) ; return ; } if ( ss == se ) { arr [ index ] = value ; if ( isArmstrong ( value ) ) st [ node ] = value ; else st [ node ] = - 1 ; } else { int mid = getMid ( ss , se ) ; if ( index >= ss && index <= mid ) updateValue ( arr , st , ss , mid , index , value , 2 * node ) ; else updateValue ( arr , st , mid + 1 , se , index , value , 2 * node + 1 ) ; st [ node ] = Math . Max ( st [ 2 * node + 1 ] , st [ 2 * node + 2 ] ) ; } return ; } static int getMax ( int [ ] st , int n , int l , int r ) { if ( l < 0 r > n - 1 l > r ) { Console . Write ( \\\" Invalid ▁ 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 ) { if ( isArmstrong ( arr [ ss ] ) ) st [ si ] = arr [ ss ] ; else st [ si ] = - 1 ; return st [ si ] ; } int mid = getMid ( ss , se ) ; st [ si ] = Math . Max ( constructSTUtil ( arr , ss , mid , st , si * 2 ) , constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 1 ) ) ; return st [ si ] ; } static int [ ] constructST ( int [ ] arr , int n ) { int x = ( int ) ( Math . Ceiling ( Math . Log ( n ) ) ) ; int max_size = 2 * ( int ) Math . Pow ( 2 ,...\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimize cost of flipping or swaps to make a Binary String balanced | C ++ program for the above approach ; Function to find the minimum cost to convert the given string into balanced string ; Stores count of 1 ' s ▁ and ▁ 0' s in the string ; Traverse the string ; Increment count1 ; Increment count 0 ; Stores absolute difference of counts of 0 ' s ▁ and ▁ 1' s ; If string consists of only 0 ' s ▁ and ▁ 1' s ; Print minimum cost ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void findMinimumCost ( string s , int N ) { int count_1 = 0 , count_0 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s [ i ] == '1' ) count_1 ++ ; else count_0 ++ ; } int k = abs ( count_0 - count_1 ) ; if ( count_1 == N count_0 == N ) cout << -1 << endl ; else cout << k \\/ 2 << endl ; } int main ( ) { string S = \\\"110110\\\" ; int N = S . length ( ) ; findMinimumCost ( S , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"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\":\"\\\"Minimum length of the shortest path of a triangle | function to get the minimum length of the shorter side of the triangle ; traversing through each points on the plane ; if sum of a points is greater than the previous one , the maximum gets replaced ; print the length ; initialize the number of points ; points on the plane\\\"\\nSolution in php:\",\"targets\":\"< ? php function shortestLength ( $ n , & $ x , & $ y ) { $ answer = 0 ; $ i = 0 ; while ( $ n -- ) { if ( $ x [ $ i ] + $ y [ $ i ] > $ answer ) $ answer = $ x [ $ i ] + $ y [ $ i ] ; $ i ++ ; } echo \\\" Length ▁ - > ▁ \\\" . $ answer . \\\" \\n \\\" ; echo \\\" Path ▁ - > ▁ \\\" . \\\" ( 1 , \\\" ▁ . $ answer ▁ . \\\" ) \\\" . \\n \\t \\t \\\" and ( \\\" ▁ . $ answer ▁ . ▁ \\\" , 1 ) \\\" ; } $ n = 4 ; $ x = array ( 1 , 4 , 2 , 1 ) ; $ y = array ( 4 , 1 , 1 , 2 ) ; shortestLength ( $ n , $ x , $ y ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-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\":\"\\\"Wedderburn – Etherington number | CPP program to find N terms of the sequence ; Stores the Wedderburn Etherington numbers ; Function to return the nth Wedderburn Etherington numbers ; Base case ; If n is even n = 2 x ; get x ; a ( 2 x ) = a ( 1 ) a ( 2 x - 1 ) + a ( 2 ) a ( 2 x - 2 ) + ... + a ( x - 1 ) a ( x + 1 ) ; a ( x ) ( a ( x ) + 1 ) \\/ 2 ; Store the ans ; Return the required answer ; If n is odd ; a ( 2 x - 1 ) = a ( 1 ) a ( 2 x - 2 ) + a ( 2 ) a ( 2 x - 3 ) + ... + a ( x - 1 ) a ( x ) , ; Store the ans ; Return the required answer ; Function to print first N Wedderburn Etherington numbers ; Store first 3 numbers ; Print N terms ; Driver code ; function call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; map < int , int > store ; int Wedderburn ( int n ) { if ( n <= 2 ) return store [ n ] ; else if ( n % 2 == 0 ) { int x = n \\/ 2 , ans = 0 ; for ( int i = 1 ; i < x ; i ++ ) { ans += store [ i ] * store [ n - i ] ; } ans += ( store [ x ] * ( store [ x ] + 1 ) ) \\/ 2 ; store [ n ] = ans ; return ans ; } else { int x = ( n + 1 ) \\/ 2 , ans = 0 ; for ( int i = 1 ; i < x ; i ++ ) { ans += store [ i ] * store [ n - i ] ; } store [ n ] = ans ; return ans ; } } void Wedderburn_Etherington ( int n ) { store [ 0 ] = 0 ; store [ 1 ] = 1 ; store [ 2 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) { cout << Wedderburn ( i ) ; if ( i != n - 1 ) cout << \\\" , ▁ \\\" ; } } int main ( ) { int n = 10 ; Wedderburn_Etherington ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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 ▁ missing ▁ element ▁ is ▁ % 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\":\"How to swap two numbers without using a temporary variable ? | C code to swap using XOR ; Code to swap ' x ' ( 1010 ) and ' y ' ( 0101 ) x now becomes 15 ( 1111 ) ; y becomes 10 ( 1010 ) ; x becomes 5 ( 0101 )\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint main ( ) { int x = 10 , y = 5 ; x = x ^ y ; y = x ^ y ; x = x ^ y ; printf ( \\\" After ▁ Swapping : ▁ x ▁ = ▁ % d , ▁ y ▁ = ▁ % d \\\" , x , y ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-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-Sharp?\",\"targets\":\"using System ; class GFG { static void conVowUpp ( char [ ] 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 ' ) { char c = char . ToUpperInvariant ( str [ i ] ) ; str [ i ] = c ; } } foreach ( char c in str ) Console . Write ( c ) ; } public static void Main ( String [ ] args ) { String str = \\\" eutopia \\\" ; conVowUpp ( str . ToCharArray ( ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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\\nHow can the above be solved in C?\",\"targets\":\"#include \\nint averageEven ( int n ) { if ( n % 2 != 0 ) { printf ( \\\" Invalid ▁ Input \\\" ) ; return -1 ; } return ( n + 2 ) \\/ 2 ; } int main ( ) { int n = 16 ; printf ( \\\" % d \\\" , averageEven ( n ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Largest and smallest Fibonacci numbers in an Array | Python 3 program to find minimum and maximum fibonacci number in given array ; Function to create hash table to check Fibonacci numbers ; Insert initial two numbers in the hash table ; Sum of previous two numbers ; Update the variable each time ; Function to find minimum and maximum fibonacci number in given array ; Find maximum value in the array ; Creating a set containing all Fibonacci numbers up to maximum value in the array ; For storing the Minimum and Maximum Fibonacci number ; Check if current element is a fibonacci number ; Update the maximum and minimum accordingly ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import sys\\ndef createHash ( hash , maxElement ) :\\n\\tprev = 0\\n\\tcurr = 1\\n\\thash . add ( prev )\\n\\thash . add ( curr )\\n\\twhile ( curr <= maxElement ) :\\n\\t\\ttemp = curr + prev\\n\\t\\thash . add ( temp )\\n\\t\\tprev = curr\\n\\t\\tcurr = temp\\ndef fibonacci ( arr , n ) :\\n\\tmax_val = max ( arr )\\n\\thash = set ( )\\n\\tcreateHash ( hash , max_val )\\n\\tminimum = sys . maxsize\\n\\tmaximum = - sys . maxsize - 1\\n\\tfor i in range ( n ) :\\n\\t\\tif ( arr [ i ] in hash ) :\\n\\t\\t\\tminimum = min ( minimum , arr [ i ] )\\n\\t\\t\\tmaximum = max ( maximum , arr [ i ] )\\n\\tprint ( minimum , end = \\\" , ▁ \\\" )\\n\\tprint ( maximum )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ]\\n\\tn = len ( arr )\\n\\tfibonacci ( arr , n )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\":\"\\\"Given an array arr [ ] , find the maximum j | Java implementation of the hashmap approach ; Function to find maximum index difference ; Initilaise unordered_map ; Iterate from 0 to n - 1 ; Sort arr ; Iterate from 0 to n - 1 ; Driver Code ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { static int maxIndexDiff ( ArrayList < Integer > arr , int n ) { Map < Integer , ArrayList < Integer > > hashmap = new HashMap < Integer , ArrayList < Integer > > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( hashmap . containsKey ( arr . get ( i ) ) ) { hashmap . get ( arr . get ( i ) ) . add ( i ) ; } else { hashmap . put ( arr . get ( i ) , new ArrayList < Integer > ( ) ) ; hashmap . get ( arr . get ( i ) ) . add ( i ) ; } } Collections . sort ( arr ) ; int maxDiff = Integer . MIN_VALUE ; int temp = n ; for ( int i = 0 ; i < n ; i ++ ) { if ( temp > hashmap . get ( arr . get ( i ) ) . get ( 0 ) ) { temp = hashmap . get ( arr . get ( i ) ) . get ( 0 ) ; } maxDiff = Math . max ( maxDiff , hashmap . get ( arr . get ( i ) ) . get ( hashmap . get ( arr . get ( i ) ) . size ( ) - 1 ) - temp ) ; } return maxDiff ; } public static void main ( String [ ] args ) { int n = 9 ; ArrayList < Integer > arr = new ArrayList < Integer > ( Arrays . asList ( 34 , 8 , 10 , 3 , 2 , 80 , 30 , 33 , 1 ) ) ; int ans = maxIndexDiff ( arr , n ) ; System . out . println ( \\\" The ▁ maxIndexDiff ▁ is ▁ : ▁ \\\" + ans ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count number of ways to convert string S to T by performing K cyclic shifts | C ++ program for the above approach ; Function to count number of ways to convert string S to string T by performing K cyclic shifts ; Calculate length of string ; ' a ' is no of good cyclic shifts ' b ' is no of bad cyclic shifts ; Iterate in the string ; Precompute the number of good and bad cyclic shifts ; dp2 [ i ] to store the no of ways to get to a bad shift in i moves ; Calculate good and bad shifts ; Return the required number of ways ; Driver Code ; Given Strings ; Given K shifts required ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; #define mod 10000000007\\nlong long countWays ( string s , string t , int k ) { int n = s . size ( ) ; int a = 0 , b = 0 ; for ( int i = 0 ; i < n ; i ++ ) { string p = s . substr ( i , n - i ) + s . substr ( 0 , i ) ; if ( p == t ) a ++ ; else b ++ ; } vector < long long > dp1 ( k + 1 ) , dp2 ( k + 1 ) ; if ( s == t ) { dp1 [ 0 ] = 1 ; dp2 [ 0 ] = 0 ; } else { dp1 [ 0 ] = 0 ; dp2 [ 0 ] = 1 ; } for ( int i = 1 ; i <= k ; i ++ ) { dp1 [ i ] = ( ( dp1 [ i - 1 ] * ( a - 1 ) ) % mod + ( dp2 [ i - 1 ] * a ) % mod ) % mod ; dp2 [ i ] = ( ( dp1 [ i - 1 ] * ( b ) ) % mod + ( dp2 [ i - 1 ] * ( b - 1 ) ) % mod ) % mod ; } return dp1 [ k ] ; } int main ( ) { string S = \\\" ab \\\" , T = \\\" ab \\\" ; int K = 2 ; cout << countWays ( S , T , K ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"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 | javascript implementation of the above approach ; Calculating total sum of given array ; For loop for beginning povar of a subarray ; initialise subarray_sum to 0 ; For loop for calculating subarray_sum and remaining_sum ; Calculating subarray_sum and corresponding remaining_sum ; Checking for the condition when subarray sum is strictly greater than the remaining sum of the array element ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"function Count_subarray ( arr , n ) { var total_sum = 0 , subarray_sum , remaining_sum , count = 0 ; for ( i = 0 ; i < n ; i ++ ) { total_sum += arr [ i ] ; } for ( i = 0 ; i < n ; i ++ ) { subarray_sum = 0 ; for ( j = i ; j < n ; j ++ ) { subarray_sum += arr [ j ] ; remaining_sum = total_sum - subarray_sum ; if ( subarray_sum > remaining_sum ) { count += 1 ; } } } return count ; } var arr = [ 10 , 9 , 12 , 6 ] ; var n = arr . length ; document . write ( Count_subarray ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find the missing digit in given product of large positive integers | C ++ program for the above approach ; Function to find the replaced digit in the product of a * b ; Keeps track of the sign of the current digit ; Stores the value of a % 11 ; Find the value of a mod 11 for large value of a as per the derived formula ; Stores the value of b % 11 ; Find the value of b mod 11 for large value of a as per the derived formula ; Stores the value of c % 11 ; Keeps track of the sign of x ; If the current digit is the missing digit , then keep the track of its sign ; Find the value of x using the derived equation ; Check if x has a negative sign ; Return positive equivaluent of x mod 11 ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int findMissingDigit ( string a , string b , string c ) { int w = 1 ; int a_mod_11 = 0 ; for ( int i = a . size ( ) - 1 ; i >= 0 ; i -- ) { a_mod_11 = ( a_mod_11 + w * ( a [ i ] - '0' ) ) % 11 ; w = w * -1 ; } int b_mod_11 = 0 ; w = 1 ; for ( int i = b . size ( ) - 1 ; i >= 0 ; i -- ) { b_mod_11 = ( b_mod_11 + w * ( b [ i ] - '0' ) ) % 11 ; w = w * -1 ; } int c_mod_11 = 0 ; bool xSignIsPositive = true ; w = 1 ; for ( int i = c . size ( ) - 1 ; i >= 0 ; i -- ) { if ( c [ i ] == ' x ' ) { xSignIsPositive = ( w == 1 ) ; } else { c_mod_11 = ( c_mod_11 + w * ( c [ i ] - '0' ) ) % 11 ; } w = w * -1 ; } int x = ( ( a_mod_11 * b_mod_11 ) - c_mod_11 ) % 11 ; if ( ! xSignIsPositive ) { x = - x ; } return ( x % 11 + 11 ) % 11 ; } int main ( ) { string A = \\\"123456789\\\" ; string B = \\\"987654321\\\" ; string C = \\\"12193263111x635269\\\" ; cout << findMissingDigit ( A , B , C ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Number of occurrences of 2 as a digit in numbers from 0 to n | C ++ program to count 2 s 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 C++?\",\"targets\":\"#include \\nusing namespace std ; int number0f2s ( int n ) { int count = 0 ; while ( n > 0 ) { if ( n % 10 == 2 ) count ++ ; n = n \\/ 10 ; } return count ; } int numberOf2sinRange ( int n ) { int count = 0 ; for ( int i = 2 ; i <= n ; i ++ ) count += number0f2s ( i ) ; return count ; } int main ( ) { cout << numberOf2sinRange ( 22 ) ; cout << endl ; cout << numberOf2sinRange ( 100 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"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 rigth ( -> ) ; 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 php:\",\"targets\":\"< ? php function getMaxGold ( $ gold , $ m , $ n ) { $ MAX = 100 ; $ goldTable = array ( array ( ) ) ; for ( $ i = 0 ; $ i < $ m ; $ i ++ ) for ( $ j = 0 ; $ j < $ n ; $ j ++ ) $ goldTable [ $ i ] [ $ j ] = 0 ; for ( $ col = $ n - 1 ; $ col >= 0 ; $ col -- ) { for ( $ row = 0 ; $ row < $ m ; $ row ++ ) { if ( $ col == $ n - 1 ) $ right = 0 ; else $ right = $ goldTable [ $ row ] [ $ col + 1 ] ; if ( $ row == 0 or $ col == $ n - 1 ) $ right_up = 0 ; else $ right_up = $ goldTable [ $ row - 1 ] [ $ col + 1 ] ; if ( $ row == $ m - 1 or $ col == $ n - 1 ) $ right_down = 0 ; else $ right_down = $ goldTable [ $ row + 1 ] [ $ col + 1 ] ; $ goldTable [ $ row ] [ $ col ] = $ gold [ $ row ] [ $ col ] + max ( $ right , $ right_up , $ right_down ) ; } } $ res = $ goldTable [ 0 ] [ 0 ] ; for ( $ i = 0 ; $ i < $ m ; $ i ++ ) $ res = max ( $ res , $ goldTable [ $ i ] [ 0 ] ) ; return $ res ; } $ gold = array ( array ( 1 , 3 , 1 , 5 ) , array ( 2 , 2 , 4 , 1 ) , array ( 5 , 0 , 2 , 3 ) , array ( 0 , 6 , 1 , 2 ) ) ; $ m = 4 ; $ n = 4 ; echo getMaxGold ( $ gold , $ m , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimize the count of adjacent pairs with different parity | Javascript implementation of above approach ; Recursive function to calculate minimum adjacent pairs with different parity ; If all the numbers are placed ; If replacement is not required ; If replacement is required ; backtracking ; backtracking ; Function to display the minimum number of adjacent elements with different parity ; Store no of even numbers not present in the array ; Store no of odd numbers not present in the array ; Erase exisiting numbers ; Store non - exisiting even and odd numbers ; Driver code\\\"\\nSolution in Javascript:\",\"targets\":\"var min = 10000 ; function parity ( even , odd , v , i ) { if ( i == v . length even . length == 0 && odd . length == 0 ) { var count = 0 ; for ( var j = 0 ; j < v . length - 1 ; j ++ ) { if ( v [ j ] % 2 != v [ j + 1 ] % 2 ) count ++ ; } if ( count < min ) min = count ; return min ; } if ( v [ i ] != - 1 ) min = parity ( even , odd , v , i + 1 ) ; else { if ( even . length != 0 ) { var x = even . back ( ) ; even . pop ( ) ; v [ i ] = x ; min = parity ( even , odd , v , i + 1 ) ; even . push ( x ) ; } if ( odd . length != 0 ) { var x = odd [ odd . length - 1 ] ; odd . pop ( ) ; v [ i ] = x ; min = parity ( even , odd , v , i + 1 ) ; odd . push ( x ) ; } } return min ; } function minDiffParity ( v , n ) { var even = [ ] ; var odd = [ ] ; var m = new Map ( ) ; for ( var i = 1 ; i <= n ; i ++ ) m . set ( i , 1 ) ; for ( var i = 0 ; i < v . length ; i ++ ) { if ( v [ i ] != - 1 ) m . delete ( v [ i ] ) ; } m . forEach ( ( value , key ) => { if ( i . first % 2 == 0 ) even . push ( key ) ; else odd . push ( key ) ; } ) ; min = parity ( even , odd , v , 0 ) ; document . write ( min ) ; } var n = 8 ; var v = [ 2 , 1 , 4 , - 1 , - 1 , 6 , - 1 , 8 ] ; minDiffParity ( v , n ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Minimum time required to print given string from a circular container based on given conditions | 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\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def minTime ( word ) :\\n\\tans = 0\\n\\tcurr = 0\\n\\tfor i in range ( len ( word ) ) :\\n\\t\\tk = ord ( word [ i ] ) - 97\\n\\t\\ta = abs ( curr - k )\\n\\t\\tb = 26 - abs ( curr - k )\\n\\t\\tans += min ( a , b )\\n\\t\\tans += 1\\n\\t\\tcurr = ord ( word [ i ] ) - 97\\n\\tprint ( ans )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tstr = \\\" zjpc \\\"\\n\\tminTime ( str )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Check whether the triangle is valid or not if angles are given | Java program to check validity of any triangle ; Function to check if sum of the three angles is 180 or not ; check condition ; Driver Code ; function calling and print output\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { public static int Valid ( int a , int b , int c ) { if ( a + b + c == 180 && a != 0 && b != 0 && c != 0 ) return 1 ; else return 0 ; } public static void main ( String args [ ] ) { int a = 60 , b = 40 , c = 80 ; if ( ( Valid ( a , b , c ) ) == 1 ) System . out . print ( \\\" Valid \\\" ) ; else System . out . print ( \\\" Invalid \\\" ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 Python:\",\"targets\":\"def nextGreater ( N ) :\\n\\tpower_of_2 = 1 ;\\n\\tshift_count = 0 ;\\n\\twhile ( True ) :\\n\\t\\tif ( ( ( N >> shift_count ) & 1 ) % 2 == 0 ) :\\n\\t\\t\\tbreak ;\\n\\t\\tshift_count += 1 ;\\n\\t\\tpower_of_2 = power_of_2 * 2 ;\\n\\treturn ( N + power_of_2 ) ;\\nN = 11 ;\\nprint ( \\\" The ▁ next ▁ number ▁ is ▁ = \\\" , nextGreater ( N ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\\"\\nSolution in Javascript:\",\"targets\":\"function polyapothem ( n , a ) { if ( a < 0 && n < 0 ) return - 1 ; return ( a \\/ ( 2 * Math . tan ( ( 180 \\/ n ) * 3.14159 \\/ 180 ) ) ) ; } var a = 9 , n = 6 ; document . write ( polyapothem ( n , a ) . toFixed ( 5 ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Rearrange positive and negative numbers with constant extra space | javascript implementation of the above approach ; Loop until arr [ i ] < 0 and still inside the array ; Loop until arr [ j ] > 0 and still inside the array ; if i is less than j ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function RearrangePosNeg ( arr ) { var i = 0 ; var j = arr . length - 1 ; while ( true ) { while ( arr [ i ] < 0 && i < arr . length ) i ++ ; while ( arr [ j ] > 0 && j >= 0 ) j -- ; if ( i < j ) { var temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } else break ; } } var arr = [ - 12 , 11 , - 13 , - 5 , 6 , - 7 , 5 , - 3 , - 6 ] ; RearrangePosNeg ( arr ) ; for ( i = 0 ; i < arr . length ; i ++ ) document . write ( arr [ i ] + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program to find largest element in an array | returns maximum in arr [ ] of size n ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function largest ( arr , n ) { arr . sort ( ) ; return arr [ n - 1 ] ; } let arr = [ 10 , 324 , 45 , 90 , 9808 ] ; let n = arr . length ; document . write ( largest ( arr , n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find the sum of the series x ( x + y ) + x ^ 2 ( x ^ 2 + y ^ 2 ) + x ^ 3 ( x ^ 3 + y ^ 3 ) + ... + x ^ n ( x ^ n + y ^ n ) | CPP program to find the sum of series ; Function to return required sum ; sum of first series ; sum of second series ; Driver Code ; function call to print sum\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int sum ( int x , int y , int n ) { int sum1 = ( pow ( x , 2 ) * ( pow ( x , 2 * n ) - 1 ) ) \\/ ( pow ( x , 2 ) - 1 ) ; int sum2 = ( x * y * ( pow ( x , n ) * pow ( y , n ) - 1 ) ) \\/ ( x * y - 1 ) ; return sum1 + sum2 ; } int main ( ) { int x = 2 , y = 2 , n = 2 ; cout << sum ( x , y , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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 code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function modInverse ( a , prime ) { a = a % prime ; for ( let x = 1 ; x < prime ; x ++ ) if ( ( a * x ) % prime == 1 ) return x ; return - 1 ; } function printModIverses ( n , prime ) { for ( let i = 1 ; i <= n ; i ++ ) document . write ( modInverse ( i , prime ) + \\\" \\\" ) ; } let n = 10 ; let prime = 17 ; printModIverses ( n , prime ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Permute a string by changing case | Function to generate permutations ; Number of permutations is 2 ^ n ; Converting string to lower case ; Using all subsequences and permuting them ; If j - th bit is set , we convert it to upper case ; Printing current combination ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function permute ( $ input ) { $ n = strlen ( $ input ) ; $ max = 1 << $ n ; $ input = strtolower ( $ input ) ; for ( $ i = 0 ; $ i < $ max ; $ i ++ ) { $ combination = $ input ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { if ( ( ( $ i >> $ j ) & 1 ) == 1 ) $ combination [ $ j ] = chr ( ord ( $ combination [ $ j ] ) - 32 ) ; } echo $ combination . \\\" \\\" ; } } permute ( \\\" ABC \\\" ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find all good indices in the given Array | Python3 program to find all good indices in the given array ; Function to find all good indices in the given array ; hash to store frequency of each element ; Storing frequency of each element and calculating sum simultaneously ; check if array is good after removing i - th index element ; print good indices ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"from collections import defaultdict\\ndef niceIndices ( A , n ) :\\n\\tSum = 0\\n\\tm = defaultdict ( lambda : 0 )\\n\\tfor i in range ( n ) :\\n\\t\\tm [ A [ i ] ] += 1\\n\\t\\tSum += A [ i ]\\n\\tfor i in range ( n ) :\\n\\t\\tk = Sum - A [ i ]\\n\\t\\tif k % 2 == 0 :\\n\\t\\t\\tk = k >> 1\\n\\t\\t\\tif k in m :\\n\\t\\t\\t\\tif ( ( A [ i ] == k and m [ k ] > 1 ) or ( A [ i ] != k ) ) :\\n\\t\\t\\t\\t\\tprint ( ( i + 1 ) , end = \\\" ▁ \\\" )\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tA = [ 8 , 3 , 5 , 2 ]\\n\\tn = len ( A )\\n\\tniceIndices ( A , n )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Product of nodes at k | C # implementation to find product of digits of elements at k - th level ; Function to find product of digits of elements at k - th level ; Initialize result ; increasing level number ; decreasing level number ; check if current level is the desired level or not ; required product ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static int productAtKthLevel ( string tree , int k ) { int level = - 1 ; int product = 1 ; int n = tree . Length ; for ( int i = 0 ; i < n ; i ++ ) { if ( tree [ i ] == ' ( ' ) level ++ ; else if ( tree [ i ] == ' ) ' ) level -- ; else { if ( level == k ) product *= ( tree [ i ] - '0' ) ; } } return product ; } static void Main ( ) { string tree = \\\" ( 0(5(6 ( ) ( ) ) ( 4 ( ) (9 ( ) ( ) ) ) ) ( 7(1 ( ) ( ) ) ( 3 ( ) ( ) ) ) ) \\\" ; int k = 2 ; Console . WriteLine ( productAtKthLevel ( tree , k ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Smallest subset with sum greater than all other elements | function to find minimum elements needed . ; calculating HALF of array sum ; sort the array in descending order . ; current sum greater than sum ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function minElements ( $ arr , $ n ) { $ halfSum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ halfSum = $ halfSum + $ arr [ $ i ] ; $ halfSum = $ halfSum \\/ 2 ; rsort ( $ arr ) ; $ res = 0 ; $ curr_sum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ curr_sum += $ arr [ $ i ] ; $ res ++ ; if ( $ curr_sum > $ halfSum ) return $ res ; } return $ res ; } $ arr = array ( 3 , 1 , 7 , 1 ) ; $ n = sizeof ( $ arr ) ; echo minElements ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximum absolute difference between sum of two contiguous sub | C ++ program to find two non - overlapping contiguous sub - arrays such that the absolute difference between the sum of two sub - array is maximum . ; Find maximum subarray sum for subarray [ 0. . i ] using standard Kadane ' s ▁ algorithm . ▁ This ▁ version ▁ of ▁ Kadane ' s Algorithm will work if all numbers are negative . ; Find maximum subarray sum for subarray [ i . . n ] using Kadane ' s ▁ algorithm . ▁ This ▁ version ▁ of ▁ Kadane ' s Algorithm will work if all numbers are negative ; The function finds two non - overlapping contiguous sub - arrays such that the absolute difference between the sum of two sub - array is maximum . ; create and build an array that stores maximum sums of subarrays that lie in arr [ 0. . . i ] ; create and build an array that stores maximum sums of subarrays that lie in arr [ i + 1. . . n - 1 ] ; Invert array ( change sign ) to find minumum sum subarrays . ; create and build an array that stores minimum sums of subarrays that lie in arr [ 0. . . i ] ; create and build an array that stores minimum sums of subarrays that lie in arr [ i + 1. . . n - 1 ] ; For each index i , take maximum of 1. abs ( max sum subarray that lies in arr [ 0. . . i ] - min sum subarray that lies in arr [ i + 1. . . n - 1 ] ) 2. abs ( min sum subarray that lies in arr [ 0. . . i ] - max sum subarray that lies in arr [ i + 1. . . n - 1 ] ) ; Driver program\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int maxLeftSubArraySum ( int a [ ] , int size , int sum [ ] ) { int max_so_far = a [ 0 ] ; int curr_max = a [ 0 ] ; sum [ 0 ] = max_so_far ; for ( int i = 1 ; i < size ; i ++ ) { curr_max = max ( a [ i ] , curr_max + a [ i ] ) ; max_so_far = max ( max_so_far , curr_max ) ; sum [ i ] = max_so_far ; } return max_so_far ; } int maxRightSubArraySum ( int a [ ] , int n , int sum [ ] ) { int max_so_far = a [ n ] ; int curr_max = a [ n ] ; sum [ n ] = max_so_far ; for ( int i = n - 1 ; i >= 0 ; i -- ) { curr_max = max ( a [ i ] , curr_max + a [ i ] ) ; max_so_far = max ( max_so_far , curr_max ) ; sum [ i ] = max_so_far ; } return max_so_far ; } int findMaxAbsDiff ( int arr [ ] , int n ) { int leftMax [ n ] ; maxLeftSubArraySum ( arr , n , leftMax ) ; int rightMax [ n ] ; maxRightSubArraySum ( arr , n - 1 , rightMax ) ; int invertArr [ n ] ; for ( int i = 0 ; i < n ; i ++ ) invertArr [ i ] = - arr [ i ] ; int leftMin [ n ] ; maxLeftSubArraySum ( invertArr , n , leftMin ) ; for ( int i = 0 ; i < n ; i ++ ) leftMin [ i ] = - leftMin [ i ] ; int rightMin [ n ] ; maxRightSubArraySum ( invertArr , n - 1 , rightMin ) ; for ( int i = 0 ; i < n ; i ++ ) rightMin [ i ] = - rightMin [ i ] ; int result = INT_MIN ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int absValue = max ( abs ( leftMax [ i ] - rightMin [ i + 1 ] ) , abs ( leftMin [ i ] - rightMax [ i + 1 ] ) ) ; if ( absValue > result ) result = absValue ; } return result ; } int main ( ) { int a [ ] = { -2 , -3 , 4 , -1 , -2 , 1 , 5 , -3 } ; int n = sizeof ( a ) \\/ sizeof ( a [ 0 ] ) ; cout << findMaxAbsDiff ( a , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Number of pairs with Pandigital Concatenation | Checks if a given is Pandigital ; digit i is not present thus not pandigital ; Returns number of pairs of strings resulting in Pandigital Concatenations ; iterate over all pair of strings ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def isPanDigital ( s ) :\\n\\tdigits = [ False ] * 10 ;\\n\\tfor i in range ( 0 , len ( s ) ) :\\n\\t\\tdigits [ int ( s [ i ] ) - int ( '0' ) ] = True\\n\\tfor i in range ( 0 , 10 ) :\\n\\t\\tif ( digits [ i ] == False ) :\\n\\t\\t\\treturn False\\n\\treturn True\\ndef countPandigitalPairs ( v ) :\\n\\tpairs = 0\\n\\tfor i in range ( 0 , len ( v ) ) :\\n\\t\\tfor j in range ( i + 1 , len ( v ) ) :\\n\\t\\t\\tif ( isPanDigital ( v [ i ] + v [ j ] ) ) :\\n\\t\\t\\t\\tpairs = pairs + 1\\n\\treturn pairs\\nv = [ \\\"123567\\\" , \\\"098234\\\" , \\\"14765\\\" , \\\"19804\\\" ]\\nprint ( countPandigitalPairs ( v ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Tetranacci Numbers | A space optimized based Java program to print the nth tetranacci number ; Function to print the N - th tetranacci number ; Initialize first four numbers to base cases ; declare a current variable ; Loop to add previous four numbers for each number starting from 4 and then assign first , second , third to second , third , fourth and curr to fourth respectively ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; import java . util . * ; import java . lang . * ; class GFG { static void printTetra ( int n ) { if ( n < 0 ) return ; int first = 0 , second = 1 ; int third = 1 , fourth = 2 ; int curr = 0 ; if ( n == 0 ) System . out . print ( first ) ; else if ( n == 1 n == 2 ) System . out . print ( second ) ; else if ( n == 3 ) System . out . print ( fourth ) ; else { for ( int i = 4 ; i <= n ; i ++ ) { curr = first + second + third + fourth ; first = second ; second = third ; third = fourth ; fourth = curr ; } System . out . print ( curr ) ; } } public static void main ( String [ ] args ) { int n = 10 ; printTetra ( n ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"DFA for Strings not ending with \\\" THE \\\" | dfa tells the number associated with the present state ; This function is for the starting state ( zeroth ) of DFA ; On receiving ' T ' or ' t ' goto first state ( 1 ) ; This function is for the first state of DFA ; On receiving ' T ' or ' t ' goto first state ( 1 ) ; On receiving ' H ' or ' h ' goto second state ( 2 ) ; else goto starting state ( 0 ) ; This function is for the second state of DFA ; On receiving ' E ' or ' e ' goto third state ( 3 ) else goto starting state ( 0 ) ; This function is for the third state of DFA ; On receiving ' T ' or ' t ' goto first state ( 1 ) else goto starting state ( 0 ) ; store length of string ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"let dfa = 0 ; function start ( c ) { if ( c == ' ' c == ' ' ) dfa = 1 ; } function state1 ( c ) { if ( c == ' ' c == ' ' ) dfa = 1 ; else if ( c == ' ' c == ' ' ) dfa = 2 ; else dfa = 0 ; } function state2 ( c ) { if ( c == ' ' c == ' ' ) dfa = 3 ; else dfa = 0 ; } function state3 ( c ) { if ( c == ' ' c == ' ' ) dfa = 1 ; else dfa = 0 ; } function isAccepted ( str ) { let len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { if ( dfa == 0 ) start ( str [ i ] ) ; else if ( dfa == 1 ) state1 ( str [ i ] ) ; else if ( dfa == 2 ) state2 ( str [ i ] ) ; else state3 ( str [ i ] ) ; } return ( dfa != 3 ) ; } let str = \\\" \\\" . split ( ' ' ) ; if ( isAccepted ( str ) == true ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function boost_hyperfactorial ( num ) { let val = 1 ; for ( let i = 1 ; i <= num ; i ++ ) { val = val * Math . pow ( i , i ) ; } return val ; } let num = 5 ; document . write ( boost_hyperfactorial ( num ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Construct original array starting with K from an array of XOR of all elements except elements at same index | C ++ program for the above approach ; Function to construct an array with each element equal to XOR of all array elements except the element at the same index ; Original array ; Stores Bitwise XOR of array ; Calculate XOR of all array elements ; Print the original array B [ ] ; Driver Code ; Function Call\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void constructArray ( int A [ ] , int N , int K ) { int B [ N ] ; int totalXOR = A [ 0 ] ^ K ; for ( int i = 0 ; i < N ; i ++ ) B [ i ] = totalXOR ^ A [ i ] ; for ( int i = 0 ; i < N ; i ++ ) { cout << B [ i ] << \\\" ▁ \\\" ; } } int main ( ) { int A [ ] = { 13 , 14 , 10 , 6 } , K = 2 ; int N = sizeof ( A ) \\/ sizeof ( A [ 0 ] ) ; constructArray ( A , N , K ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Modify string by removing vowels in between two consonants | Function to check if the character x is a vowel or not ; Returns the updated string formed after removing all the Sandwiched Vowels from the given string ; string to store the Updated String after removing the Sandwiched Vowels ; traverse the string from left to right ; if the current character is the first or the last character of the string then , this needs to be appended to the updatedString , since the corner alphabet irrespective of it being a vowel or a consonant , is never ' Sandwiched ' ; Check if the current character of the string is a vowel and both the previous and the next characters are consonants , if so then this is a sandwiched vowel , thus is ignored and not appended to the updated string ; if this character is not a sandwiched Vowel append it to the updated String ; Driver Code ; Remove all the Sandwitched Vowels\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function isVowel ( $ x ) { if ( $ x == ' a ' $ x == ' e ' $ x == ' i ' $ x == ' o ' $ x == ' u ' ) return true ; else return false ; } function updateSandwichedVowels ( $ a ) { $ n = strlen ( $ a ) ; $ updatedString = \\\" \\\" ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( ! $ i $ i == $ n - 1 ) { $ updatedString . = $ a [ $ i ] ; continue ; } if ( isVowel ( $ a [ $ i ] ) && ! isVowel ( $ a [ $ i - 1 ] ) && ! isVowel ( $ a [ $ i + 1 ] ) ) { continue ; } $ updatedString . = $ a [ $ i ] ; } return $ updatedString ; } $ str = \\\" geeksforgeeks \\\" ; $ updatedString = updateSandwichedVowels ( $ str ) ; echo $ updatedString ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Compute the minimum or maximum of two integers without branching | Java program to 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\\\"\\nHow can the above be solved in Java?\",\"targets\":\"public class AWS { static int min ( int x , int y ) { return y ^ ( ( x ^ y ) & - ( x << y ) ) ; } static int max ( int x , int y ) { return x ^ ( ( x ^ y ) & - ( x << y ) ) ; } public static void main ( String [ ] args ) { int x = 15 ; int y = 6 ; System . out . print ( \\\" Minimum ▁ of ▁ \\\" + x + \\\" ▁ and ▁ \\\" + y + \\\" ▁ is ▁ \\\" ) ; System . out . println ( min ( x , y ) ) ; System . out . print ( \\\" Maximum ▁ of ▁ \\\" + x + \\\" ▁ and ▁ \\\" + y + \\\" ▁ is ▁ \\\" ) ; System . out . println ( max ( x , y ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"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 | C # 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\\\"\\nSolution in C#:\",\"targets\":\"using System ; 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 [ j ] - '0' ] ++ ; while ( freq [ 0 ] > 0 && freq [ 1 ] > 0 && freq [ 2 ] > 0 ) { freq [ str [ i ++ ] - '0' ] -- ; } count += i ; } return count ; } public static void Main ( String [ ] args ) { string str = \\\"00021\\\" ; Console . Write ( countSubstrings ( str ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Largest palindromic number by permuting digits | CPP program to print the largest palindromic number by permuting digits of a number ; function to check if a number can be permuted to form a palindrome number ; counts the occurrence of number which is odd ; if occurrence is odd ; if number exceeds 1 ; function to print the largest palindromic number by permuting digits of a number ; string length ; map that marks the occurrence of a number ; check the possibility of a palindromic number ; string array that stores the largest permuted palindromic number ; pointer of front ; greedily start from 9 to 0 and place the greater number in front and odd in the middle ; if the occurrence of number is odd ; place one odd occurring number in the middle ; decrease the count ; place the rest of numbers greedily ; if all numbers occur even times , then place greedily ; place greedily at front ; 2 numbers are placed , so decrease the count ; increase placing position ; print the largest string thus formed ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; bool possibility ( unordered_map < int , int > m , int length , string s ) { int countodd = 0 ; for ( int i = 0 ; i < length ; i ++ ) { if ( m [ s [ i ] - '0' ] & 1 ) countodd ++ ; if ( countodd > 1 ) return false ; } return true ; } void largestPalindrome ( string s ) { int l = s . length ( ) ; unordered_map < int , int > m ; for ( int i = 0 ; i < l ; i ++ ) m [ s [ i ] - '0' ] ++ ; if ( possibility ( m , l , s ) == false ) { cout << \\\" Palindrome ▁ cannot ▁ be ▁ formed \\\" ; return ; } char largest [ l ] ; int front = 0 ; for ( int i = 9 ; i >= 0 ; i -- ) { if ( m [ i ] & 1 ) { largest [ l \\/ 2 ] = char ( i + 48 ) ; m [ i ] -- ; while ( m [ i ] > 0 ) { largest [ front ] = char ( i + 48 ) ; largest [ l - front - 1 ] = char ( i + 48 ) ; m [ i ] -= 2 ; front ++ ; } } else { while ( m [ i ] > 0 ) { largest [ front ] = char ( i + 48 ) ; largest [ l - front - 1 ] = char ( i + 48 ) ; m [ i ] -= 2 ; front ++ ; } } } for ( int i = 0 ; i < l ; i ++ ) cout << largest [ i ] ; } int main ( ) { string s = \\\"313551\\\" ; largestPalindrome ( s ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimize cost to replace all the vowels of a given String by a single vowel | C # 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\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static bool 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 [ i ] ) ) { cA += Math . Abs ( S [ i ] - ' a ' ) ; cE += Math . Abs ( S [ i ] - ' e ' ) ; cI += Math . Abs ( S [ i ] - ' i ' ) ; cO += Math . Abs ( S [ i ] - ' o ' ) ; cU += Math . Abs ( S [ 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 \\\" ; Console . WriteLine ( minCost ( S ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Final cell position in the matrix | function to find the final cell position in the given matrix ; to count up , down , left and cright movements ; to store the final coordinate position ; traverse the command array ; calculate final values ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function finalPos ( $ command , $ n , $ x , $ y ) { $ cup ; $ cdown ; $ cleft ; $ cright ; $ final_x ; $ final_y ; $ cup = $ cdown = $ cleft = $ cright = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ command [ $ i ] == ' U ' ) $ cup ++ ; else if ( $ command [ $ i ] == ' D ' ) $ cdown ++ ; else if ( $ command [ $ i ] == ' L ' ) $ cleft ++ ; else if ( $ command [ $ i ] == ' R ' ) $ cright ++ ; } $ final_x = $ x + ( $ cright - $ cleft ) ; $ final_y = $ y + ( $ cdown - $ cup ) ; echo \\\" Final ▁ Position : ▁ \\\" . \\\" ( \\\" . $ final_x . \\\" , ▁ \\\" . $ final_y . \\\" ) \\\" ; } $ command = \\\" DDLRULL \\\" ; $ n = strlen ( $ command ) ; $ x = 3 ; $ y = 4 ; finalPos ( $ command , $ n , $ x , $ y ) ;\",\"language\":\"python\",\"split\":\"train\",\"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\\\"\\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\":\"\\\"Linear Search | PHP code for linearly search x in arr [ ] . If x is present then return its location , otherwise return - 1 ; Driver Code ; Function call\\\"\\nSolution in php:\",\"targets\":\"< ? php function search ( $ arr , $ x ) { $ n = sizeof ( $ arr ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] == $ x ) return $ i ; } return -1 ; } $ arr = array ( 2 , 3 , 4 , 10 , 40 ) ; $ x = 10 ; $ result = search ( $ arr , $ x ) ; if ( $ result == -1 ) echo \\\" Element ▁ is ▁ not ▁ present ▁ in ▁ array \\\" ; else echo \\\" Element ▁ is ▁ present ▁ at ▁ index ▁ \\\" , $ result ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"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 | 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\\\"\\nHow can the above be solved in JS?\",\"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\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Pascal 's Triangle | C ++ code for Pascal 's Triangle ; binomialCoeff ; Function to print first n lines of Pascal 's Triangle ; Iterate through every line and print entries in it ; Every line has number of integers equal to line number ; Driver program\\\"\\nSolution in C++:\",\"targets\":\"#include \\nint binomialCoeff ( int n , int k ) ; int 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 ; } void printPascal ( int n ) { for ( int line = 0 ; line < n ; line ++ ) { for ( int i = 0 ; i <= line ; i ++ ) printf ( \\\" % d ▁ \\\" , binomialCoeff ( line , i ) ) ; printf ( \\\" \\n \\\" ) ; } } int main ( ) { int n = 7 ; printPascal ( n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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\":\"\\\"Calculate square of a number without using * , \\/ and pow ( ) | PHP implementation to calculate square without using * and pow ( ) ; handle negative input ; Initialize result ; Add n to res n - 1 times ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function square ( $ n ) { if ( $ n < 0 ) $ n = - $ n ; $ res = $ n ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) $ res += $ n ; return $ res ; } for ( $ n = 1 ; $ n <= 5 ; $ n ++ ) echo \\\" n = \\\" , ▁ $ n , ▁ \\\" , \\\" , ▁ \\\" n ^ 2 = \\\" , square ( $ n ) , \\\" \\n ▁ \\\" ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Count minimum steps to get the given desired array | Returns count of minimum operations to convert a zero array to target array with increment and doubling operations . This function computes count by doing reverse steps , i . e . , convert target to zero array . ; Initialize result ( Count of minimum moves ) ; Keep looping while all elements of target don 't become 0. ; To store count of zeroes in current target array ; To find first odd element ; If odd number found ; If 0 , then increment zero_count ; All numbers are 0 ; All numbers are even ; Divide the whole array by 2 and increment result ; Make all odd numbers even by subtracting one and increment result . ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function countMinOperations ( $ target , $ n ) { $ result = 0 ; while ( 1 ) { $ zero_count = 0 ; $ i = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ target [ $ i ] & 1 ) break ; else if ( $ target [ $ i ] == 0 ) $ zero_count ++ ; } if ( $ zero_count == $ n ) return $ result ; if ( $ i == $ n ) { for ( $ j = 0 ; $ j < $ n ; $ j ++ ) $ target [ $ j ] = $ target [ $ j ] \\/ 2 ; $ result ++ ; } for ( $ j = $ i ; $ j < $ n ; $ j ++ ) { if ( $ target [ $ j ] & 1 ) { $ target [ $ j ] -- ; $ result ++ ; } } } } $ arr = array ( 16 , 16 , 16 ) ; $ n = sizeof ( $ arr ) ; echo \\\" Minimum ▁ number ▁ of ▁ steps ▁ required ▁ to ▁ \\n \\\" . \\\" get ▁ the ▁ given ▁ target ▁ array ▁ is ▁ \\\" . countMinOperations ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Kth smallest or largest element in unsorted Array | Set 4 | Function to find the Kth smallest element in Unsorted Array ; Initialize the max Element as 0 ; Iterate arr [ ] and find the maximum element in it ; Frequency array to store the frequencies ; Counter variable ; Counting the frequencies ; Iterate through the freq [ ] ; Check if num is present in the array ; Increment the counter with the frequency of num ; Checking if we have reached the Kth smallest element ; Return the Kth smallest element ; Given array ; Function call\\\"\\nSolution in Javascript:\",\"targets\":\"function findKthSmallest ( arr , n , k ) { let max = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > max ) max = arr [ i ] ; } let counter = Array . from ( { length : max + 1 } , ( _ , i ) => 0 ) ; let smallest = 0 ; for ( let i = 0 ; i < n ; i ++ ) { counter [ arr [ i ] ] ++ ; } for ( let num = 1 ; num <= max ; num ++ ) { if ( counter [ num ] > 0 ) { smallest += counter [ num ] ; } if ( smallest >= k ) { return num ; } } return - 1 ; } let arr = [ 7 , 1 , 4 , 4 , 20 , 15 , 8 ] ; let N = arr . length ; let K = 5 ; document . write ( findKthSmallest ( arr , N , K ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if LCM of array elements is divisible by a prime number or not | Function to check any number of array is divisible by k or not ; If any array element is divisible by k , then LCM of whole array should also be divisible . ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function func ( $ a , $ k , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( $ a [ $ i ] % $ k == 0 ) return true ; return false ; } $ a = array ( 14 , 27 , 38 , 76 , 84 ) ; $ k = 19 ; $ res = func ( $ a , $ k , 5 ) ; if ( $ res ) echo \\\" true \\\" ; else echo \\\" false \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Sum of prime numbers in range [ L , R ] from given Array for Q queries | Java program for the above approach ; Function to find the prime numbers ; Create a boolean array prime [ ] and initialize all entries it as true A value in prime [ i ] will finally be false if i is Not a prime ; Check 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 numbers which are multiple of p and are less than p ^ 2 are already been marked ; Function to get the middle index from corner indexes ; Function to get the sum of values in the given range of the array ; If segment of this node is a part of given range , then return the sum of the segment ; If segment of this node is outside the given range ; If a part of this segment overlaps with the given range ; Function to update the nodes which have the given index in their range ; If the input index lies outside the range of this segment ; If the input index is in range of this node , then update the value of the node and its children ; Function to update a value in input array and segment tree ; Check for erroneous input index ; Get the difference between new value and old value ; Update the value in array ; Update the values of nodes in segment tree only if either previous value or new value or both are prime ; If only new value is prime ; If only new value is prime ; If both are prime ; Return sum of elements in range from index qs ( query start ) to qe ( query end ) . It mainly uses getSumUtil ( ) ; Check for erroneous input values ; Function that constructs Segment Tree ; If there is one element in array , store it in current node of segment tree and return ; Only add those elements in segment tree which are prime ; If there are more than one elements , then recur for left and right subtrees and store the sum of values in this node ; Function to construct segment tree from given array ; Height of segment tree ; Maximum size of segment tree ; Allocate memory ; Fill the allocated memory st ; Return the...\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { static int MAX = 1000001 ; static int prime [ ] = new int [ MAX ] ; static void SieveOfEratosthenes ( ) { Arrays . fill ( prime , 1 ) ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == 1 ) { for ( int i = p * p ; i <= MAX - 1 ; i += p ) prime [ i ] = 0 ; } } } static int getMid ( int s , int e ) { return s + ( e - s ) \\/ 2 ; } static int getSumUtil ( int [ ] st , int ss , int se , int qs , int qe , int si ) { if ( qs <= ss && qe >= se ) return st [ si ] ; if ( se < qs ss > qe ) return 0 ; int mid = getMid ( ss , se ) ; return getSumUtil ( st , ss , mid , qs , qe , 2 * si + 1 ) + getSumUtil ( st , mid + 1 , se , qs , qe , 2 * si + 2 ) ; } static void updateValueUtil ( int [ ] st , int ss , int se , int i , int diff , int si ) { if ( i < ss i > se ) return ; st [ si ] = st [ si ] + diff ; if ( se != ss ) { int mid = getMid ( ss , se ) ; updateValueUtil ( st , ss , mid , i , diff , 2 * si + 1 ) ; updateValueUtil ( st , mid + 1 , se , i , diff , 2 * si + 2 ) ; } } static void updateValue ( int arr [ ] , int [ ] st , int n , int i , int new_val ) { if ( i < 0 i > n - 1 ) { System . out . print ( \\\" - 1\\\" ) ; return ; } int diff = new_val - arr [ i ] ; int prev_val = arr [ i ] ; arr [ i ] = new_val ; if ( ( prime [ new_val ] prime [ prev_val ] ) != 0 ) { if ( prime [ prev_val ] == 0 ) updateValueUtil ( st , 0 , n - 1 , i , new_val , 0 ) ; else if ( prime [ new_val ] == 0 ) updateValueUtil ( st , 0 , n - 1 , i , - prev_val , 0 ) ; else updateValueUtil ( st , 0 , n - 1 , i , diff , 0 ) ; } } static int getSum ( int [ ] st , int n , int qs , int qe ) { if ( qs < 0 qe > n - 1 qs > qe ) { System . out . println ( \\\" - 1\\\" ) ; return - 1 ; } return getSumUtil ( st , 0 , n - 1 , qs , qe , 0 ) ; } static int constructSTUtil ( int arr [ ] , int ss , int se , int [ ] st , int si ) { if ( ss == se ) { if ( prime [ arr [ ss ] ] != 0 ) st [ si ] = arr [ ss ] ; else st [ si ] = 0 ; return st [ si ] ; } int mid = getMid ( ss , se ) ; st [ si ] = constructSTUtil (...\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Construct a matrix with sum equal to the sum of diagonal elements | Function to construct matrix with diagonal sum equal to matrix sum ; If diagonal position ; Positive element ; Negative element ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function constructmatrix ( N ) { let check = true ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { if ( i == j ) { document . write ( \\\" \\\" ) ; } else if ( check ) { document . write ( \\\" \\\" ) ; check = false ; } else { document . write ( \\\" \\\" ) ; check = true ; } } document . write ( \\\" \\\" ) ; } } let N = 5 ; constructmatrix ( 5 ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Write a program to calculate pow ( x , n ) | javascript program for the above approach ; If x ^ 0 return 1 ; If we need to find of 0 ^ y ; For all other cases ; Driver Code\\\"\\nSolution in Javascript:\",\"targets\":\"function power ( x , y ) { if ( y == 0 ) return 1 ; if ( x == 0 ) return 0 ; return x * power ( x , y - 1 ) ; } var x = 2 ; var y = 3 ; document . write ( power ( x , y ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find the number of elements greater than k in a sorted array | Function to return the count of elements from the array which are greater than k ; Stores the index of the left most element from the array which is greater than k ; Finds number of elements greater than k ; If mid element is greater than k update leftGreater and r ; If mid element is less than or equal to k update l ; Return the count of elements greater than k ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def countGreater ( arr , n , k ) :\\n\\tl = 0\\n\\tr = n - 1\\n\\tleftGreater = n\\n\\twhile ( l <= r ) :\\n\\t\\tm = int ( l + ( r - l ) \\/ 2 )\\n\\t\\tif ( arr [ m ] > k ) :\\n\\t\\t\\tleftGreater = m\\n\\t\\t\\tr = m - 1\\n\\t\\telse :\\n\\t\\t\\tl = m + 1\\n\\treturn ( n - leftGreater )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ 3 , 3 , 4 , 7 , 7 , 7 , 11 , 13 , 13 ]\\n\\tn = len ( arr )\\n\\tk = 7\\n\\tprint ( countGreater ( arr , n , k ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Find the maximum repeating number in O ( n ) time and O ( 1 ) extra space | C ++ program to find the maximum repeating number ; Returns maximum repeating element in arr [ 0. . n - 1 ] . The array elements are in range from 0 to k - 1 ; Iterate though input array , for every element arr [ i ] , increment arr [ arr [ i ] % k ] by k ; Find index of the maximum repeating element ; Return index of the maximum element ; Driver program to test above function\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int maxRepeating ( int * arr , int n , int k ) { for ( int i = 0 ; i < n ; i ++ ) arr [ arr [ i ] % k ] += k ; int max = arr [ 0 ] , result = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > max ) { max = arr [ i ] ; result = i ; } } return result ; } int main ( ) { int arr [ ] = { 2 , 3 , 3 , 5 , 3 , 4 , 1 , 7 } ; int n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; int k = 8 ; cout << \\\" The ▁ maximum ▁ repeating ▁ number ▁ is ▁ \\\" << maxRepeating ( arr , n , k ) << endl ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Probability that a random pair chosen from an array ( a [ i ] , a [ j ] ) has the maximum sum | C ++ implementation of the approach ; Function to return the probability of getting the maximum pair sum when a random pair is chosen from the given array ; Initialize the maximum sum , its count and the count of total pairs ; For every single pair ; Get the sum of the current pair ; If the sum is equal to the current maximum sum so far ; Increment its count ; If the sum is greater than the current maximum ; Update the current maximum and re - initialize the count to 1 ; Find the required probability ; Driver code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; float findProb ( int arr [ ] , int n ) { long maxSum = INT_MIN , maxCount = 0 , totalPairs = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int sum = arr [ i ] + arr [ j ] ; if ( sum == maxSum ) { maxCount ++ ; } else if ( sum > maxSum ) { maxSum = sum ; maxCount = 1 ; } totalPairs ++ ; } } float prob = ( float ) maxCount \\/ ( float ) totalPairs ; return prob ; } int main ( ) { int arr [ ] = { 1 , 1 , 1 , 2 , 2 , 2 } ; int n = sizeof ( arr ) \\/ sizeof ( int ) ; cout << findProb ( arr , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Position of n among the numbers made of 2 , 3 , 5 & 7 | Program position of n among the numbers made of 2 , 3 , 5 & 7 ; If number is 2 then it is on the position pos * 2 + 1 ; If number is 3 then it is on the position pos * 2 + 2 ; If number is 5 then it is on the position pos * 2 + 3 ; If number is 7 then it is on the position pos * 2 + 4 ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findpos ( n ) :\\n\\tpos = 0\\n\\tfor i in n :\\n\\t\\tif i == '2' :\\n\\t\\t\\tpos = pos * 4 + 1\\n\\t\\telif i == '3' :\\n\\t\\t\\tpos = pos * 4 + 2\\n\\t\\telif i == '5' :\\n\\t\\t\\tpos = pos * 4 + 3\\n\\t\\telif i == '7' :\\n\\t\\t\\tpos = pos * 4 + 4\\n\\treturn pos\\nn = \\\"777\\\"\\nprint ( findpos ( n ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sorting element of an array by frequency in decreasing order | Function that return the index upto all the array elements are updated . ; Initialise maxE = - 1 ; Find the maximum element of arr [ ] ; Create frequency array freq [ ] ; Update the frequency array as per the occurrence of element in arr [ ] ; Initialise cnt to 0 ; Traversing freq [ ] ; If freq of an element is greater than 0 update the value of arr [ ] at index cnt & increment cnt ; Return cnt ; Function that print array arr [ ] elements in sorted order ; Traversing arr [ ] till index cnt ; Find frequency of elements ; Find value at index i ; Traversing till frequency to print value at index i ; Driver code ; Size of array arr [ ] ; Function call to get cnt ; Sort the arr [ ] in decreasing order ; Function that prints elements in decreasing order\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function sortByFreq ( arr , n ) { var maxE = - 1 ; for ( var i = 0 ; i < n ; i ++ ) { maxE = Math . max ( maxE , arr [ i ] ) ; } var freq = new Array ( maxE + 1 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { freq [ arr [ i ] ] ++ ; } var cnt = 0 ; for ( var i = 0 ; i <= maxE ; i ++ ) { if ( freq [ i ] > 0 ) { var value = 100000 - i ; arr [ cnt ] = 100000 * freq [ i ] + value ; cnt ++ ; } } return cnt ; } function printSortedArray ( arr , cnt ) { for ( var i = 0 ; i < cnt ; i ++ ) { var frequency = parseInt ( arr [ i ] \\/ 100000 ) ; var value = 100000 - ( arr [ i ] % 100000 ) ; for ( var j = 0 ; j < frequency ; j ++ ) { document . write ( value + \\\" \\\" ) ; } } } var arr = [ 4 , 4 , 5 , 6 , 4 , 2 , 2 , 8 , 5 ] ; var n = arr . length ; var cnt = sortByFreq ( arr , n ) ; arr . sort ( ( a , b ) => b - a ) ; printSortedArray ( arr , cnt ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\\\"\\nSolution 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\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Extract ' k ' bits from a given position in a number . | Function to extract k bits from p position and returns the extracted value as integer ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function bitExtracted ( number , k , p ) { return ( ( ( 1 << k ) - 1 ) & ( number >> ( p - 1 ) ) ) ; } let number = 171 , k = 5 , p = 2 ; document . write ( \\\" \\\" , bitExtracted ( number , k , p ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if two circles intersect such that the third circle passes through their points of intersections and centers | Java approach for the above approach ; Structure of the circle ; Utility function to check if given circles satisfy required criteria ; Stores the distance between the centres of C1 and C2 ; Stores the status if the given given criteria is satisfied or not ; If C1C2 is less than the sum of the radii of the first 2 circles ; If C3 is the midpoint of the centres at C1 and C2 ; Mark flag true ; Return flag ; Function to check if the given circles satisfy required criteria ; Check for the current combination of circles ; Check for the next combination ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static class circle { double x ; double y ; double r ; public circle ( int x , int y , int r ) { this . x = x ; this . y = y ; this . r = r ; } } static boolean check ( circle C [ ] ) { double C1C2 = Math . sqrt ( ( C [ 1 ] . x - C [ 0 ] . x ) * ( C [ 1 ] . x - C [ 0 ] . x ) + ( C [ 1 ] . y - C [ 0 ] . y ) * ( C [ 1 ] . y - C [ 0 ] . y ) ) ; boolean flag = false ; if ( C1C2 < ( C [ 0 ] . r + C [ 1 ] . r ) ) { if ( ( C [ 0 ] . x + C [ 1 ] . x ) == 2 * C [ 2 ] . x && ( C [ 0 ] . y + C [ 1 ] . y ) == 2 * C [ 2 ] . y ) { flag = true ; } } return flag ; } static boolean IsFairTriplet ( circle c [ ] ) { boolean f = false ; f |= check ( c ) ; for ( int i = 0 ; i < 2 ; i ++ ) { swap ( c [ 0 ] , c [ 2 ] ) ; f |= check ( c ) ; } return f ; } static void swap ( circle circle1 , circle circle2 ) { circle temp = circle1 ; circle1 = circle2 ; circle2 = temp ; } public static void main ( String [ ] args ) { circle C [ ] = new circle [ 3 ] ; C [ 0 ] = new circle ( 0 , 0 , 8 ) ; C [ 1 ] = new circle ( 0 , 10 , 6 ) ; C [ 2 ] = new circle ( 0 , 5 , 5 ) ; if ( IsFairTriplet ( C ) ) 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\":\"\\\"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 ▁ number ▁ after ▁ unsetting ▁ the \\\" , end = \\\" \\\" ) ;\\n\\tprint ( \\\" ▁ rightmost ▁ set ▁ bit : ▁ \\\" , FlipBits ( N ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count of permutations such that sum of K numbers from given range is even | C ++ program for the above approach ; Function to return the number of all permutations such that sum of K numbers in range is even ; Find total count of even and odd number in given range ; Iterate loop k times and update even_sum & odd_sum using previous values ; Update the prev_even and odd_sum ; Even sum ; Odd sum ; Return even_sum ; Driver Code ; Given ranges ; Length of permutation ; Function call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int countEvenSum ( int low , int high , int k ) { int even_count = high \\/ 2 - ( low - 1 ) \\/ 2 ; int odd_count = ( high + 1 ) \\/ 2 - low \\/ 2 ; long even_sum = 1 ; long odd_sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) { long prev_even = even_sum ; long prev_odd = odd_sum ; even_sum = ( prev_even * even_count ) + ( prev_odd * odd_count ) ; odd_sum = ( prev_even * odd_count ) + ( prev_odd * even_count ) ; } cout << ( even_sum ) ; } int main ( ) { int low = 4 ; int high = 5 ; int K = 3 ; countEvenSum ( low , high , K ) ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Find the point where maximum intervals overlap | ; Finding maximum starting time ; Finding maximum ending time ; reating an auxiliary array ; Lazy addition ; Lazily Calculating value at index i ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; import java . util . * ; import java . text . * ; import java . math . * ; import java . util . regex . * ; class GFG { public static void maxOverlap ( int [ ] start , int [ ] end , int n ) { int maxa = Arrays . stream ( start ) . max ( ) . getAsInt ( ) ; int maxb = Arrays . stream ( end ) . max ( ) . getAsInt ( ) ; int maxc = Math . max ( maxa , maxb ) ; int [ ] x = new int [ maxc + 2 ] ; Arrays . fill ( x , 0 ) ; int cur = 0 , idx = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ++ x [ start [ i ] ] ; -- x [ end [ i ] + 1 ] ; } int maxy = Integer . MIN_VALUE ; for ( int i = 0 ; i <= maxc ; i ++ ) { cur += x [ i ] ; if ( maxy < cur ) { maxy = cur ; idx = i ; } } System . out . println ( \\\" Maximum ▁ value ▁ is : \\\" + maxy + \\\" ▁ at ▁ position : ▁ \\\" + idx + \\\" \\\" ) ; } public static void main ( String [ ] args ) { int [ ] start = new int [ ] { 13 , 28 , 29 , 14 , 40 , 17 , 3 } ; int [ ] end = new int [ ] { 107 , 95 , 111 , 105 , 70 , 127 , 74 } ; int n = start . length ; maxOverlap ( start , end , n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count nodes having highest value in the path from root to itself in a Binary Tree | C # program for the above approach ; Stores the count of nodes which are maximum in the path from root to the current node ; Binary Tree Node ; Function that performs Inorder Traversal on the Binary Tree ; If root does not exist ; Check if the node satisfies the condition ; Update the maximum value and recursively traverse left and right subtree ; Function that counts the good nodes in the given Binary Tree ; Perform inorder Traversal ; Return the readonly count ; Function that add the new node in the Binary Tree ; Return the node ; Driver Code ; A Binary Tree 3 \\/ \\\\ 2 5 \\/ \\\\ 4 6 ; Function Call ; Print the count of good nodes\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GfG { static int count = 0 ; public class Node { public int val ; public Node left , right ; } static void find ( Node root , int max ) { if ( root == null ) return ; if ( root . val >= max ) count ++ ; find ( root . left , Math . Max ( max , root . val ) ) ; find ( root . right , Math . Max ( max , root . val ) ) ; } static int NodesMaxInPath ( Node root ) { find ( root , int . MinValue ) ; return count ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . val = data ; temp . left = null ; temp . right = null ; return temp ; } public static void Main ( String [ ] args ) { Node root = null ; root = newNode ( 3 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 4 ) ; root . right . right = newNode ( 7 ) ; int answer = NodesMaxInPath ( root ) ; Console . WriteLine ( answer ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Largest smaller number possible using only one swap operation | Java program to find the largest smaller number by swapping one digit . ; Returns largest possible number with one swap such that the number is smaller than str . It is assumed that there are leading 0 s . ; Traverse from right until we find a digit which is greater than its next digit . For example , in 34125 , our index is 4. ; We can also use binary search here as digits after index are sorted in increasing order . Find the biggest digit in the right of arr [ index ] which is smaller than arr [ index ] ; If index is - 1 i . e . digits are in increasing order . ; Swap both values ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static String prevNum ( String str ) { int len = str . length ( ) ; int index = - 1 ; for ( int i = len - 2 ; i >= 0 ; i -- ) { if ( str . charAt ( i ) > str . charAt ( i + 1 ) ) { index = i ; break ; } } int smallGreatDgt = - 1 ; for ( int i = len - 1 ; i > index ; i -- ) { if ( str . charAt ( i ) < str . charAt ( index ) ) { if ( smallGreatDgt == - 1 ) { smallGreatDgt = i ; } else if ( str . charAt ( i ) >= str . charAt ( smallGreatDgt ) ) { smallGreatDgt = i ; } } } if ( index == - 1 ) { return \\\" - 1\\\" ; } if ( smallGreatDgt != - 1 ) { str = swap ( str , index , smallGreatDgt ) ; return str ; } return \\\" - 1\\\" ; } static String swap ( String str , int i , int j ) { char ch [ ] = str . toCharArray ( ) ; char temp = ch [ i ] ; ch [ i ] = ch [ j ] ; ch [ j ] = temp ; return String . valueOf ( ch ) ; } public static void main ( String [ ] args ) { String str = \\\"34125\\\" ; System . out . println ( prevNum ( str ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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 code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int 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 ; } public static void Main ( ) { int [ ] arr = { - 10 , - 1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 } ; int n = arr . Length ; Console . Write ( \\\" Fixed ▁ Point ▁ is ▁ \\\" + binarySearch ( arr , 0 , n - 1 ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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\":\"\\\"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\\\"\\nSolution in Python:\",\"targets\":\"def firstDigit ( n ) :\\n\\twhile n >= 10 :\\n\\t\\tn = n \\/ 10 ;\\n\\treturn int ( n )\\ndef lastDigit ( n ) :\\n\\treturn ( n % 10 )\\nn = 98562 ;\\nprint ( firstDigit ( n ) , end = \\\" ▁ \\\" )\\nprint ( lastDigit ( n ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Count intervals that intersects with a given meeting time | C # implementation of the above approach ; Function to convert a time in 24 hour format to an equivalent integer ; Removes \\\" : \\\" at 3 rd position ; Calculate hours ; Stores the time in 24 hours format ; If time is in \\\" AM \\\" ; If hh is equal to 12 ; If time is in \\\" PM \\\" ; If hh is equal to 12 ; Return time ; Function to count number of intervals in which p lies ; Stores the count ; Stores the integer value of 24 hours time format of P ; Traverse the array ; Stores the integer value of 24 hours time format of arr [ i , 0 ] ; Stores the integer value of 24 hours time format of arr [ i , 1 ] ; If M lies within the [ L , R ] ; Increment ans by 1 ; Return ans ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int convert ( String str ) { str = str . Substring ( 0 , 2 ) + str . Substring ( 3 ) ; int h1 = ( int ) str [ 1 ] - '0' ; int h2 = ( int ) str [ 0 ] - '0' ; int hh = ( h2 * 10 + h1 % 10 ) ; int time = 0 ; if ( str [ 5 ] == ' A ' ) { if ( hh == 12 ) time += Int32 . Parse ( str . Substring ( 2 , 2 ) ) ; else { time += Int32 . Parse ( str . Substring ( 0 , 2 ) ) ; } } else { if ( hh == 12 ) { time += Int32 . Parse ( str . Substring ( 0 , 4 ) ) ; } else { time += Int32 . Parse ( str . Substring ( 0 , 4 ) ) ; time += 1200 ; } } return time ; } static int countOverlap ( String [ , ] arr , int n , String p ) { int ans = 0 ; int M = convert ( p ) ; for ( int i = 0 ; i < n ; i ++ ) { int L = convert ( arr [ i , 0 ] ) ; int R = convert ( arr [ i , 1 ] ) ; if ( ( L <= M && M <= R ) || ( M >= R && M <= L ) ) ans ++ ; } return ans ; } public static void Main ( String [ ] args ) { String [ , ] arr = new String [ , ] { { \\\"12:00 : AM \\\" , \\\"11:55 : PM \\\" } , { \\\"12:01 : AM \\\" , \\\"11:50 : AM \\\" } , { \\\"12:30 : AM \\\" , \\\"12:00 : PM \\\" } , { \\\"11:57 : AM \\\" , \\\"11:59 : PM \\\" } } ; String P = \\\"12:01 : PM \\\" ; int N = arr . GetLength ( 0 ) ; Console . WriteLine ( countOverlap ( arr , N , P ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of palindromic subsequences to be removed to empty a binary string | A function to check if a string str is palindrome ; Start from leftmost and rightmost corners of str ; Keep comparing characters while they are same ; Returns count of minimum palindromic subseuqnces to be removed to make string empty ; If string is empty ; If string is palindrome ; If string is not palindrome ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function isPalindrome ( str ) { let l = 0 ; let h = str . length - 1 ; while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false ; return true ; } function minRemovals ( str ) { if ( str [ 0 ] == ' ' ) return 0 ; if ( isPalindrome ( str ) ) return 1 ; return 2 ; } document . write ( minRemovals ( \\\" \\\" ) + \\\" \\\" ) ; document . write ( minRemovals ( \\\" \\\" ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find the Nth term of the series 1 + 2 + 6 + 15 + 31 + 56 + ... | calculate Nth term of given series ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function Nth_Term ( n ) { return ( 2 * Math . pow ( n , 3 ) - 3 * Math . pow ( n , 2 ) + n + 6 ) \\/ 6 ; } let N = 8 ; document . write ( Nth_Term ( N ) ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Print leftmost and rightmost nodes of a Binary Tree | C # program to print corner node at each level in a binary tree ; A binary tree node has key , pointer to left child and a pointer to right child ; Function to print corner node at each level ; star node is for keeping track of levels ; pushing root node and star node ; Do level order traversal of Binary Tree ; n is the no of nodes in current Level ; If it is leftmost corner value or rightmost corner value then print it ; push the left and right children of the temp node ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; public class Node { public int key ; public Node left , right ; public Node ( int key ) { this . key = key ; left = right = null ; } } public class BinaryTree { Node root ; void printCorner ( Node root ) { Queue < Node > q = new Queue < Node > ( ) ; q . Enqueue ( root ) ; while ( q . Count != 0 ) { int n = q . Count ; for ( int i = 0 ; i < n ; i ++ ) { Node temp = q . Peek ( ) ; q . Dequeue ( ) ; if ( i == 0 i == n - 1 ) Console . Write ( temp . key + \\\" ▁ \\\" ) ; if ( temp . left != null ) q . Enqueue ( temp . left ) ; if ( temp . right != null ) q . Enqueue ( temp . right ) ; } } } public static void Main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 15 ) ; tree . root . left = new Node ( 10 ) ; tree . root . right = new Node ( 20 ) ; tree . root . left . left = new Node ( 8 ) ; tree . root . left . right = new Node ( 12 ) ; tree . root . right . left = new Node ( 16 ) ; tree . root . right . right = new Node ( 25 ) ; tree . printCorner ( tree . root ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check if the given string is shuffled substring of another string | This function returns true if contents of arr1 [ ] and arr2 [ ] are same , otherwise false . ; This function search for all permutations of pat [ ] in txt [ ] ; countP [ ] : Store count of all characters of pattern countTW [ ] : Store count of current window of text ; Traverse through remaining characters of pattern ; Compare counts of current window of text with counts of pattern [ ] ; Add current character to current window ; Remove the first character of previous window ; Check for the last window in text ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function compare ( arr1 , arr2 ) { for ( let i = 0 ; i < 256 ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ; return true ; } function search ( pat , txt ) { let M = pat . length ; let N = txt . length ; let countP = new Array ( 256 ) ; let countTW = new Array ( 256 ) ; for ( let i = 0 ; i < 256 ; i ++ ) { countP [ i ] = 0 ; countTW [ i ] = 0 ; } for ( let i = 0 ; i < 256 ; i ++ ) { countP [ i ] = 0 ; countTW [ i ] = 0 ; } for ( let i = 0 ; i < M ; i ++ ) { ( countP [ pat [ i ] . charCodeAt ( 0 ) ] ) ++ ; ( countTW [ txt [ i ] . charCodeAt ( 0 ) ] ) ++ ; } for ( let i = M ; i < N ; i ++ ) { if ( compare ( countP , countTW ) ) return true ; ( countTW [ txt [ i ] . charCodeAt ( 0 ) ] ) ++ ; countTW [ txt [ i - M ] . charCodeAt ( 0 ) ] -- ; } if ( compare ( countP , countTW ) ) return true ; return false ; } let txt = \\\" \\\" ; let pat = \\\" \\\" ; if ( search ( pat , txt ) ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"Activity Selection Problem | Greedy Algo | C program for activity selection problem . The following implementation assumes that the activities are already sorted according to their finish time ; Prints a maximum set of activities that can be done by a single person , one at a time . n -- > Total number of activities s [ ] -- > An array that contains start time of all activities f [ ] -- > An array that contains finish time of all activities ; The first activity always gets selected ; Consider rest of the activities ; If this activity has start time greater than or equal to the finish time of previously selected activity , then select it ; driver program to test above function\\nHow can the above be solved in C?\",\"targets\":\"#include \\nvoid printMaxActivities ( int s [ ] , int f [ ] , int n ) { int i , j ; printf ( \\\" Following ▁ activities ▁ are ▁ selected ▁ n \\\" ) ; i = 0 ; printf ( \\\" % d ▁ \\\" , i ) ; for ( j = 1 ; j < n ; j ++ ) { if ( s [ j ] >= f [ i ] ) { printf ( \\\" % d ▁ \\\" , j ) ; i = j ; } } } int main ( ) { int s [ ] = { 1 , 3 , 0 , 5 , 8 , 5 } ; int f [ ] = { 2 , 4 , 6 , 7 , 9 , 9 } ; int n = sizeof ( s ) \\/ sizeof ( s [ 0 ] ) ; printMaxActivities ( s , f , 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 with every character appearing even number of times | Function to find length of the longest substring with each element occurring even number of times ; Initialize unordered_map ; Stores the length of the longest required substring ; Traverse the string ; Stores the value of the digit present at current index ; Bitwise XOR of the mask with 1 left - shifted by val ; Check if the value of mask is already present in ind or not ; Update the final answer ; Otherwise ; Return the answer ; Given string ; Length of the given string ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function lenOfLongestReqSubstr ( s , N ) { var ind = new Map ( ) ; var mask = 0 ; ind [ 0 ] = - 1 ; var ans = 0 ; for ( var i = 0 ; i < N ; i ++ ) { var val = s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; mask ^= ( 1 << val ) ; if ( ind . has ( mask ) ) { ans = Math . max ( ans , i - ind . get ( mask ) ) ; } else ind . set ( mask , i ) ; } return ans ; } var s = \\\" \\\" ; var N = s . length ; document . write ( lenOfLongestReqSubstr ( s , N ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Coin Change | DP | Dynamic Programming PHP implementation of Coin Change problem ; table [ i ] will be storing the number of solutions for value i . We need n + 1 rows as the table is constructed in bottom up manner using the base case ( n = 0 ) ; Base case ( If given value is 0 ) ; Pick all coins one by one and update the table [ ] values after the index greater than or equal to the value of the picked coin ; Driver Code\\\"\\nSolution in php:\",\"targets\":\"< ? php function count_1 ( & $ S , $ m , $ n ) { $ table = array_fill ( 0 , $ n + 1 , NULl ) ; $ table [ 0 ] = 1 ; for ( $ i = 0 ; $ i < $ m ; $ i ++ ) for ( $ j = $ S [ $ i ] ; $ j <= $ n ; $ j ++ ) $ table [ $ j ] += $ table [ $ j - $ S [ $ i ] ] ; return $ table [ $ n ] ; } $ arr = array ( 1 , 2 , 3 ) ; $ m = sizeof ( $ arr ) ; $ n = 4 ; $ x = count_1 ( $ arr , $ m , $ n ) ; echo $ x ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Find two numbers from their sum and XOR | Set 2 | C ++ program for the above approach ; Function to find the value of A and B whose sum is X and xor is Y ; Initialize the two numbers ; Case 1 : X < Y ; Case 2 : X - Y is odd ; Case 3 : If both Sum and XOR are equal ; Case 4 : If above cases fails ; Update the value of A ; Check if A & Y value is 0 ; If true , update B ; Otherwise assign - 1 to A , - 1 to B ; Print the numbers A and B ; Driver Code ; Given Sum and XOR of 2 numbers ; Function Call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; void findNums ( int X , int Y ) { int A , B ; if ( X < Y ) { A = -1 ; B = -1 ; } else if ( abs ( X - Y ) & 1 ) { A = -1 ; B = -1 ; } else if ( X == Y ) { A = 0 ; B = Y ; } else { A = ( X - Y ) \\/ 2 ; if ( ( A & Y ) == 0 ) { B = ( A + Y ) ; } else { A = -1 ; B = -1 ; } } cout << A << \\\" ▁ \\\" << B ; } int main ( ) { int X = 17 , Y = 13 ; findNums ( X , Y ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Minimize the sum of the array according the given condition | C # implementation of the above approach ; Function to return the minimum sum ; sort the array to find the minimum element ; finding the number to divide ; Checking to what instance the sum has decreased ; getting the max difference ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void findMin ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; Array . Sort ( arr ) ; int min = arr [ 0 ] ; int max = 0 ; for ( int i = n - 1 ; i >= 1 ; i -- ) { int num = arr [ i ] ; int total = num + min ; int j ; for ( j = 2 ; j <= num ; j ++ ) { if ( num % j == 0 ) { int d = j ; int now = ( num \\/ d ) + ( min * d ) ; int reduce = total - now ; if ( reduce > max ) max = reduce ; } } } Console . WriteLine ( sum - max ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . Length ; findMin ( arr , n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Program to print Arithmetic Progression series | PHP Program to print an arithmetic progression series ; Printing AP by simply adding d to previous term . ; starting number ; Common difference ; N th term to be find\\\"\\nSolution in php:\",\"targets\":\"< ? php function printAP ( $ a , $ d , $ n ) { $ curr_term ; $ curr_term = a ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { echo ( $ curr_term . \\\" \\\" ) ; $ curr_term += $ d ; } } $ a = 2 ; $ d = 1 ; $ n = 5 ; printAP ( $ a , $ d , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Subtract two numbers without using arithmetic operators | C # Program to subtract two Number without using arithmetic operator Recursive implementation . ; Driver program\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int subtract ( int x , int y ) { if ( y == 0 ) return x ; return subtract ( x ^ y , ( ~ x & y ) << 1 ) ; } public static void Main ( ) { int x = 29 , y = 13 ; Console . WriteLine ( \\\" x ▁ - ▁ y ▁ is ▁ \\\" + subtract ( x , y ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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\\nHow can the above be solved 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\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of substrings with each character occurring even times | C # program for the above approach ; Function to count substrings having even frequency of each character ; Stores the total count of substrings ; Traverse the range [ 0 , N ] : ; Traverse the range [ i + 1 , N ] ; Stores the substring over the range of indices [ i , len ] ; Stores the frequency of characters ; Count frequency of each character ; Traverse the dictionary ; If any of the keys have odd count ; Otherwise ; Return count ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; public class GFG { static int subString ( string s , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int len = i + 1 ; len <= n ; len ++ ) { string test_str = s . Substring ( i , len - i ) ; Dictionary < char , int > res = new Dictionary < char , int > ( ) ; foreach ( char keys in test_str . ToCharArray ( ) ) { if ( ! res . ContainsKey ( keys ) ) res . Add ( keys , 0 ) ; res [ keys ] ++ ; } int flag = 0 ; foreach ( KeyValuePair < char , int > keys in res ) { if ( keys . Value % 2 != 0 ) { flag = 1 ; break ; } } if ( flag == 0 ) count += 1 ; } } return count ; } static public void Main ( ) { string S = \\\" abbaa \\\" ; int N = S . Length ; Console . WriteLine ( subString ( S , N ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count subarrays having a single distinct element that can be obtained from a given array | Java program for the above approach ; Function to count subarrays of single distinct element into which given array can be split ; Stores the count ; Stores frequency of array elements ; Traverse the array ; Traverse the map ; Increase count of subarrays by ( frequency - 1 ) ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { static void divisionalArrays ( int arr [ ] , int N ) { int sum = N ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } for ( Map . Entry x : mp . entrySet ( ) ) { if ( ( int ) x . getValue ( ) > 1 ) { sum += ( int ) x . getValue ( ) - 1 ; } } System . out . println ( sum ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 3 } ; int N = arr . length ; divisionalArrays ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Sorted order printing of a given array that represents a BST | C Code for Sorted order printing of a given array that represents a BST ; print left subtree ; print root ; print right subtree ; driver program to test above function\\\"\\nSolution in C:\",\"targets\":\"#include \\nvoid printSorted ( int arr [ ] , int start , int end ) { if ( start > end ) return ; printSorted ( arr , start * 2 + 1 , end ) ; printf ( \\\" % d ▁ \\\" , arr [ start ] ) ; printSorted ( arr , start * 2 + 2 , end ) ; } int main ( ) { int arr [ ] = { 4 , 2 , 5 , 1 , 3 } ; int arr_size = sizeof ( arr ) \\/ sizeof ( int ) ; printSorted ( arr , 0 , arr_size - 1 ) ; getchar ( ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Hexacontatetragon numbers | Function to find the nth Hexacontatetragon number ; Driver code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function HexacontatetragonNum ( n ) { return ( 62 * n * n - 60 * n ) \\/ 2 ; } let n = 3 ; document . write ( HexacontatetragonNum ( n ) ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Print prime numbers from 1 to N in reverse order | Javascript program to print all primes between 1 to N in reverse order 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 ; Print all prime numbers in reverse order ; static input ; to display\\\"\\nSolution in Javascript:\",\"targets\":\"function Reverseorder ( n ) { let prime = new Array ( n + 1 ) ; for ( let i = 0 ; i < n ; i ++ ) prime [ i ] = true ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } for ( let p = n ; p >= 2 ; p -- ) if ( prime [ p ] ) document . write ( p + \\\" \\\" ) ; } let N = 25 ; document . write ( \\\" \\\" + \\\" \\\" ) ; if ( N == 1 ) document . write ( \\\" \\\" ) ; else\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Ways to Remove Edges from a Complete Graph to make Odd Edges | C # implementation of the approach ; Function to return the number of ways to remove edges from the graph so that odd number of edges are left in the graph ; Total number of edges ; Driver code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; public class GFG { static int countWays ( int N ) { int E = ( N * ( N - 1 ) ) \\/ 2 ; if ( N == 1 ) return 0 ; return ( int ) Math . Pow ( 2 , E - 1 ) ; } static public void Main ( ) { int N = 4 ; Console . WriteLine ( countWays ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-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\\\"\\nSolution 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\":\"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 | 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\":\"using System ; class GFG { static int key ( int N ) { String num = \\\" \\\" + 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 ) Math . Floor ( Math . Log10 ( add ) + 1 ) ; ans *= ( int ) ( Math . 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 ) Math . Floor ( Math . Log10 ( add ) + 1 ) ; ans *= ( int ) ( Math . Pow ( 10 , digit ) ) ; ans += add ; } i = j ; } } if ( j + 1 >= num . Length ) { return ans ; } else { return ans += num [ num . Length - 1 ] - 48 ; } } public static void Main ( String [ ] args ) { int N = 1667848271 ; Console . Write ( key ( N ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Min steps to convert N | C # program for the above problem ; Adjacency list for numbers till 100001 ; Visited array ; To store distance of every vertex from A ; Function to check if number is a prime ; Function to check if numbers differ by only a single - digit ; Check the last digit of both numbers and increase count if different ; Generate all N digit primes ; For every prime number i check if an edge can be made . ; For every prime number i check if an edge can be made from i to j . ; If edge is possible then insert in the adjacency list ; Function to count distance ; If unvisited push onto queue and mark visited as 1 and add the distance of curr + 1. ; Driver code ; Call bfs traversal with root as node A ; Indicates not possible\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static List < List < int > > lis = new List < List < int > > ( ) ; static List < int > primes = new List < int > ( ) ; static int [ ] vis = new int [ 100001 ] ; static int [ ] dis = new int [ 100001 ] ; static bool isPrime ( int n ) { int i = 2 ; while ( i * i <= n ) { if ( n % i == 0 ) return false ; i += 1 ; } return true ; } static bool valid ( int a , int b ) { int c = 0 ; while ( a > 0 ) { if ( ( a % 10 ) != ( b % 10 ) ) c += 1 ; a = a \\/ 10 ; b = b \\/ 10 ; } if ( c == 1 ) return true ; else return false ; } static void makePrimes ( int N ) { int L = ( int ) Math . Pow ( 10 , N - 1 ) ; int R = ( int ) Math . Pow ( 10 , N ) - 1 ; for ( int i = L ; i < R + 1 ; i ++ ) { if ( isPrime ( i ) ) primes . Add ( i ) ; } for ( int i = 0 ; i < primes . Count ; i ++ ) { for ( int j = i + 1 ; j < primes . Count ; j ++ ) { int a = primes [ i ] ; int b = primes [ j ] ; if ( valid ( a , b ) ) { lis [ a ] . Add ( b ) ; lis [ b ] . Add ( a ) ; } } } } static void bfs ( int src ) { List < int > q = new List < int > ( ) ; q . Add ( src ) ; vis [ src ] = 1 ; dis [ src ] = 0 ; while ( q . Count != 0 ) { int curr = q [ 0 ] ; q . RemoveAt ( 0 ) ; foreach ( int x in lis [ curr ] ) { if ( vis [ x ] == 0 ) { vis [ x ] = 1 ; q . Add ( x ) ; dis [ x ] = dis [ curr ] + 1 ; } } } } static void Main ( ) { for ( int i = 0 ; i < 100001 ; i ++ ) { lis . Add ( new List < int > ( ) ) ; } int N = 4 ; makePrimes ( N ) ; int A = 1033 ; int B = 8179 ; bfs ( A ) ; if ( dis [ B ] == - 1 ) { Console . Write ( - 1 ) ; } else { Console . Write ( dis [ B ] ) ; } } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Check whether the given string is a valid identifier | Function that returns true if str1 is a valid identifier ; If first character is invalid ; Traverse the for the rest of the characters ; is a valid identifier ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"def isValid ( str1 , n ) :\\n\\tif ( ( ( ord ( str1 [ 0 ] ) >= ord ( ' a ' ) and ord ( str1 [ 0 ] ) <= ord ( ' z ' ) ) or ( ord ( str1 [ 0 ] ) >= ord ( ' A ' ) and ord ( str1 [ 0 ] ) <= ord ( ' Z ' ) ) or ord ( str1 [ 0 ] ) == ord ( ' _ ' ) ) == False ) :\\n\\t\\treturn False\\n\\tfor i in range ( 1 , len ( str1 ) ) :\\n\\t\\tif ( ( ( ord ( str1 [ i ] ) >= ord ( ' a ' ) and ord ( str1 [ i ] ) <= ord ( ' z ' ) ) or ( ord ( str1 [ i ] ) >= ord ( ' A ' ) and ord ( str1 [ i ] ) <= ord ( ' Z ' ) ) or ( ord ( str1 [ i ] ) >= ord ( '0' ) and ord ( str1 [ i ] ) <= ord ( '9' ) ) or ord ( str1 [ i ] ) == ord ( ' _ ' ) ) == False ) :\\n\\t\\t\\treturn False\\n\\treturn True\\nstr1 = \\\" _ geeks123\\\"\\nn = len ( str1 )\\nif ( isValid ( str1 , n ) ) :\\n\\tprint ( \\\" Valid \\\" )\\nelse :\\n\\tprint ( \\\" Invalid \\\" )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Maximum Sum possible by selecting X elements from a Matrix based on given conditions | C # program to implement the above approach ; Function to calculate the maximum possible sum by selecting X elements from the Matrix ; Generate prefix sum of the matrix ; Initialize [ , ] dp ; Maximum possible sum by selecting 0 elements from the first i rows ; If a single row is present ; If elements from the current row is not selected ; Iterate over all possible selections from current row ; Return maximum possible sum ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static int n , m , X ; public static int maxSum ( int [ , ] grid ) { int [ , ] prefsum = new int [ n , m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int x = 0 ; x < m ; x ++ ) { if ( x == 0 ) prefsum [ i , x ] = grid [ i , x ] ; else prefsum [ i , x ] = prefsum [ i , x - 1 ] + grid [ i , x ] ; } } int [ , ] dp = new int [ n , X + 1 ] ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 1 ; j <= X ; ++ j ) dp [ i , j ] = int . MinValue ; for ( int i = 0 ; i < n ; i ++ ) dp [ i , 0 ] = 0 ; for ( int i = 1 ; i <= Math . Min ( m , X ) ; ++ i ) { dp [ 0 , i ] = dp [ 0 , i - 1 ] + grid [ 0 , i - 1 ] ; } for ( int i = 1 ; i < n ; ++ i ) { for ( int j = 1 ; j <= X ; ++ j ) { dp [ i , j ] = dp [ i - 1 , j ] ; for ( int x = 1 ; x <= Math . Min ( j , m ) ; x ++ ) { dp [ i , j ] = Math . Max ( dp [ i , j ] , dp [ i - 1 , j - x ] + prefsum [ i , x - 1 ] ) ; } } } return dp [ n - 1 , X ] ; } public static void Main ( String [ ] args ) { n = 4 ; m = 4 ; X = 6 ; int [ , ] grid = { { 3 , 2 , 6 , 1 } , { 1 , 9 , 2 , 4 } , { 4 , 1 , 3 , 9 } , { 3 , 8 , 2 , 1 } } ; int ans = maxSum ( grid ) ; Console . WriteLine ( ans ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Position of rightmost set bit | Python 3 implementation of above approach ; counting the position of first set bit ; Driver code\\\"\\nSolution in Python:\",\"targets\":\"INT_SIZE = 32\\ndef Right_most_setbit ( num ) :\\n\\tpos = 1\\n\\tfor i in range ( INT_SIZE ) :\\n\\t\\tif not ( num & ( 1 << i ) ) :\\n\\t\\t\\tpos += 1\\n\\t\\telse :\\n\\t\\t\\tbreak\\n\\treturn pos\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\tnum = 18\\n\\tpos = Right_most_setbit ( num )\\n\\tprint ( pos )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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 ▁ character ▁ array ▁ is ▁ % sn \\\" , arr ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Number of subsets with a given OR value | Java implementation of the approach ; To store states of DP ; Function to return the required count ; Base case ; If the state has been solved before return the value of the state ; Setting the state as solved ; Recurrence relation ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"import java . util . * ; class GFG { static int maxN = 20 ; static int maxM = 64 ; static int [ ] [ ] dp = new int [ maxN ] [ maxM ] ; static boolean [ ] [ ] v = new boolean [ maxN ] [ maxM ] ; static int findCnt ( int [ ] arr , int i , int curr , int n , int m ) { if ( i == n ) { return ( curr == m ? 1 : 0 ) ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = true ; dp [ i ] [ curr ] = findCnt ( arr , i + 1 , curr , n , m ) + findCnt ( arr , i + 1 , ( curr arr [ i ] ) , n , m ) ; return dp [ i ] [ curr ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 2 } ; int n = arr . length ; int m = 3 ; System . out . println ( findCnt ( arr , 0 , 0 , n , m ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number of bracket reversals needed to make an expression balanced | Set | Returns count of minimum reversals for making expr balanced . Returns - 1 if expr cannot be balanced . ; length of expression must be even to make it balanced by using reversals . ; To store number of reversals required . ; To store number of unbalanced opening brackets . ; To store number of unbalanced closing brackets . ; If current bracket is open then increment open count . ; If current bracket is close , check if it balances opening bracket . If yes then decrement count of unbalanced opening bracket else increment count of closing bracket . ; For the case : \\\" \\\" or when one closing and one opening bracket remains for pairing , then both need to be reversed . ; Driver Code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def countMinReversals ( expr ) :\\n\\tlength = len ( expr )\\n\\tif length % 2 :\\n\\t\\treturn - 1\\n\\tans = 0\\n\\topen = 0\\n\\tclose = 0\\n\\tfor i in range ( 0 , length ) :\\n\\t\\tif expr [ i ] == \\\" \\\" :\\n\\t\\t\\topen += 1\\n\\t\\telse :\\n\\t\\t\\tif not open :\\n\\t\\t\\t\\tclose += 1\\n\\t\\t\\telse :\\n\\t\\t\\t\\topen -= 1\\n\\tans = ( close \\/\\/ 2 ) + ( open \\/\\/ 2 )\\n\\tclose %= 2\\n\\topen %= 2\\n\\tif close > 0 :\\n\\t\\tans += 2\\n\\treturn ans\\nif __name__ == \\\" _ _ main _ _ \\\" :\\n\\texpr = \\\" } } { { \\\"\\n\\tprint ( countMinReversals ( expr ) )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Maximum width of an N | C # program to implement the above approach ; Function to find the maximum width of the tree using level order traversal ; Store the edges of the tree ; Stores maximum width of the tree ; Stores the nodes of each level ; Insert root node ; Perform level order traversal on the tree ; Stores the size of the queue ; Update maximum width ; Push the nodes of the next level and pop the elements of the current level ; Get element from the front the Queue ; Push all nodes of the next level . ; Return the result . ; Driver Code ; Constructed tree is : 1 \\/ | \\\\ 2 - 1 3 \\/ \\\\ \\\\ 4 5 8 \\/ \\/ | \\\\ 2 6 12 7\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static int maxWidth ( int N , int M , List < int > cost , List < List < int > > s ) { List < List < int > > adj = new List < List < int > > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { adj . Add ( new List < int > ( ) ) ; } for ( int i = 0 ; i < M ; i ++ ) { adj [ s [ i ] [ 0 ] ] . Add ( s [ i ] [ 1 ] ) ; } int result = 0 ; Queue < int > q = new Queue < int > ( ) ; q . Enqueue ( 0 ) ; while ( q . Count != 0 ) { int count = q . Count ; result = Math . Max ( count , result ) ; while ( count -- > 0 ) { int temp = q . Dequeue ( ) ; for ( int i = 0 ; i < adj [ temp ] . Count ; i ++ ) { q . Enqueue ( adj [ temp ] [ i ] ) ; } } } return result ; } static public void Main ( ) { int N = 11 , M = 10 ; List < List < int > > edges = new List < List < int > > ( ) ; edges . Add ( new List < int > ( ) { 0 , 1 } ) ; edges . Add ( new List < int > ( ) { 0 , 2 } ) ; edges . Add ( new List < int > ( ) { 0 , 3 } ) ; edges . Add ( new List < int > ( ) { 1 , 4 } ) ; edges . Add ( new List < int > ( ) { 1 , 5 } ) ; edges . Add ( new List < int > ( ) { 3 , 6 } ) ; edges . Add ( new List < int > ( ) { 4 , 7 } ) ; edges . Add ( new List < int > ( ) { 6 , 10 } ) ; edges . Add ( new List < int > ( ) { 6 , 8 } ) ; edges . Add ( new List < int > ( ) { 6 , 9 } ) ; List < int > cost = new List < int > ( ) { 1 , 2 , - 1 , 3 , 4 , 5 , 8 , 2 , 6 , 12 , 7 } ; Console . WriteLine ( maxWidth ( N , M , cost , edges ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Print modified array after executing the commands of addition and subtraction | Update function for every command ; If q == 0 , add ' k ' and ' - k ' to ' l - 1' and ' r ' index ; If q == 1 , add ' - k ' and ' k ' to ' l - 1' and ' r ' index ; Function to generate the final array after executing all commands ; Generate final array with the help of DP concept ; Driver code ; Generate final array ; Printing the final modified array\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function updateQuery ( arr , n , q , l , r , k ) { if ( q == 0 ) { arr [ l - 1 ] += k ; arr [ r ] += - k ; } else { arr [ l - 1 ] += - k ; arr [ r ] += k ; } return ; } function generateArray ( arr , n ) { for ( i = 1 ; i < n ; ++ i ) arr [ i ] += arr [ i - 1 ] ; } var n = 5 ; var arr = Array ( n + 1 ) . fill ( 0 ) ; var q = 0 , l = 1 , r = 3 , k = 2 ; updateQuery ( arr , n , q , l , r , k ) ; q = 1 ; l = 3 ; r = 5 ; k = 3 ; updateQuery ( arr , n , q , l , r , k ) ; q = 0 ; l = 2 ; r = 5 ; k = 1 ; updateQuery ( arr , n , q , l , r , k ) ; generateArray ( arr , n ) ; for ( i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Find the Kth position element of the given sequence | Java implementation of the approach ; Function to return the kth number from the required sequence ; Count of odd integers in the sequence ; kth number is even ; It is odd ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static int kthNum ( int n , int k ) { int a = ( n + 1 ) \\/ 2 ; if ( k > a ) return ( 2 * ( k - a ) ) ; return ( 2 * k - 1 ) ; } public static void main ( String [ ] args ) { int n = 7 , k = 7 ; System . out . println ( kthNum ( n , k ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Minimum cost of purchasing at least X chocolates | 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 answer\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def findMinCost ( arr , X , n , i = 0 ) :\\n\\tif ( X <= 0 ) :\\n\\t\\treturn 0\\n\\tif ( i >= n ) :\\n\\t\\treturn 10 ** 8\\n\\tinc = findMinCost ( arr , X - arr [ i ] [ 0 ] , n , i + 1 )\\n\\tif ( inc != 10 ** 8 ) :\\n\\t\\tinc += arr [ i ] [ 1 ]\\n\\texc = findMinCost ( arr , X , n , i + 1 )\\n\\treturn min ( inc , exc )\\nif __name__ == ' _ _ main _ _ ' :\\n\\tarr = [ [ 4 , 3 ] , [ 3 , 2 ] , [ 2 , 4 ] , [ 1 , 3 ] , [ 4 , 2 ] ]\\n\\tX = 7\\n\\tn = len ( arr )\\n\\tans = findMinCost ( arr , X , n )\\n\\tif ( ans != 10 ** 8 ) :\\n\\t\\tprint ( ans )\\n\\telse :\\n\\t\\tprint ( - 1 )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Majority Element | Set | ; function to print the majority Number ; Driver code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; #define ll long long int\\nint majorityNumber ( int arr [ ] , int n ) { int ans = -1 ; unordered_map < int , int > freq ; for ( int i = 0 ; i < n ; i ++ ) { freq [ arr [ i ] ] ++ ; if ( freq [ arr [ i ] ] > n \\/ 2 ) ans = arr [ i ] ; } return ans ; } int main ( ) { int a [ ] = { 2 , 2 , 1 , 1 , 1 , 2 , 2 } ; int n = sizeof ( a ) \\/ sizeof ( int ) ; cout << majorityNumber ( a , n ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Maximum in an array that can make another array sorted | C # program to make array sorted ; Function to check whether there is any swappable element present to make the first array sorted ; wrongIdx is the index of the element which is making the first array unsorted ; Find the maximum element which satisfies the above mentioned neighboring conditions ; if res is true then swap the element and make the first array sorted ; Function to print the sorted array if elements are swapped . ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static bool swapElement ( int [ ] arr1 , int [ ] arr2 , int n ) { int wrongIdx = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr1 [ i ] < arr1 [ i - 1 ] ) { wrongIdx = i ; } } int maximum = int . MinValue ; int maxIdx = - 1 ; bool res = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr2 [ i ] > maximum && arr2 [ i ] >= arr1 [ wrongIdx - 1 ] ) { if ( wrongIdx + 1 <= n - 1 && arr2 [ i ] <= arr1 [ wrongIdx + 1 ] ) { maximum = arr2 [ i ] ; maxIdx = i ; res = true ; } } } if ( res ) { swap ( arr1 , wrongIdx , arr2 , maxIdx ) ; } return res ; } static void swap ( int [ ] a , int wrongIdx , int [ ] b , int maxIdx ) { int c = a [ wrongIdx ] ; a [ wrongIdx ] = b [ maxIdx ] ; b [ maxIdx ] = c ; } static void getSortedArray ( int [ ] arr1 , int [ ] arr2 , int n ) { if ( swapElement ( arr1 , arr2 , n ) ) { for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( arr1 [ i ] + \\\" ▁ \\\" ) ; } } else { Console . Write ( \\\" Not ▁ Possible \\\" ) ; } } public static void Main ( ) { int [ ] arr1 = { 1 , 3 , 7 , 4 , 10 } ; int [ ] arr2 = { 2 , 1 , 6 , 8 , 9 } ; int n = arr1 . Length ; getSortedArray ( arr1 , arr2 , n ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"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\\\"\\nSolution in php:\",\"targets\":\"< ? php function __gcd ( $ a , $ b ) { if ( $ a == 0 ) return $ b ; return __gcd ( $ b % $ a , $ a ) ; } function minimumMoves ( $ A , $ N ) { $ one = 0 ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) if ( $ A [ $ i ] == 1 ) $ one ++ ; if ( $ one != 0 ) return $ N - $ one ; $ minimum = PHP_INT_MAX ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) { $ g = $ A [ $ i ] ; for ( $ j = $ i + 1 ; $ j < $ N ; $ j ++ ) { $ g = __gcd ( $ A [ $ j ] , $ g ) ; if ( $ g == 1 ) { $ minimum = min ( $ minimum , $ j - $ i ) ; break ; } } } if ( $ minimum == PHP_INT_MAX ) return -1 ; else return $ N + $ minimum - 1 ; } $ A = array ( 2 , 4 , 3 , 9 ) ; $ N = sizeof ( $ A ) ; echo ( minimumMoves ( $ A , $ N ) ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program to print binomial expansion 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 ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function series ( $ A , $ X , $ n ) { $ term = pow ( $ A , $ n ) ; echo $ term , \\\" \\\" ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ term = $ term * $ X * ( $ n - $ i + 1 ) \\/ ( $ i * $ A ) ; echo $ term , \\\" \\\" ; } } $ A = 3 ; $ X = 4 ; $ n = 5 ; series ( $ A , $ X , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Smallest N digit number divisible by all possible prime digits | C # implementation of the above approach ; Function to find the minimum number of n digits divisible by all prime digits ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void minNum ( int n ) { if ( n < 3 ) Console . WriteLine ( - 1 ) ; else Console . WriteLine ( 210 * ( ( int ) ( Math . Pow ( 10 , n - 1 ) \\/ 210 ) + 1 ) ) ; } public static void Main ( String [ ] args ) { int n = 5 ; minNum ( n ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Find all divisors of a natural number | Set 2 | A O ( sqrt ( n ) ) java program that prints all divisors in sorted order ; Method to print the divisors ; List to store half of the divisors ; Check if divisors are equal ; Otherwise print both ; The list will be printed in reverse ; Driver method\\\"\\nHow can the above be solved in Python?\",\"targets\":\"import math\\ndef printDivisors ( n ) :\\n\\tlist = [ ]\\n\\tfor i in range ( 1 , int ( math . sqrt ( n ) + 1 ) ) :\\n\\t\\tif ( n % i == 0 ) :\\n\\t\\t\\tif ( n \\/ i == i ) :\\n\\t\\t\\t\\tprint ( i , end = \\\" ▁ \\\" )\\n\\t\\t\\telse :\\n\\t\\t\\t\\tprint ( i , end = \\\" ▁ \\\" )\\n\\t\\t\\t\\tlist . append ( int ( n \\/ i ) )\\n\\tfor i in list [ : : - 1 ] :\\n\\t\\tprint ( i , end = \\\" ▁ \\\" )\\nprint ( \\\" The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ \\\" )\\nprintDivisors ( 100 )\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Minimum increment and decrement by K of each pair elements required to make all array elements equal | C # program for the above approach ; Function to check if its possible to make all array elements equal or not ; Stores the sum of the array ; Traverse the array ; If sum is divisible by N ; Otherwise , not possible to make all array elements equal ; Driver Code ; Given array ; Size of the array\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; public class GFG { static void arrayElementEqual ( int [ ] arr , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } if ( sum % N == 0 ) { Console . WriteLine ( \\\" Yes \\\" ) ; } else { Console . Write ( \\\" No \\\" + \\\" \\n \\\" ) ; } } static public void Main ( ) { int [ ] arr = { 1 , 5 , 6 , 4 } ; int N = arr . Length ; arrayElementEqual ( arr , N ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count numbers from a given range that are not divisible by any of the array elements | Java program for the above approach ; Function to find the non - multiples till k ; Stores all unique multiples ; Iterate the array ; For finding duplicates only once ; Inserting all multiples into the set ; Returning only the count of numbers that are not divisible by any of the array elements ; Function to count the total values in the range [ L , R ] ; Count all values in the range using exclusion principle ; Driver code ; Function Call\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . io . * ; import java . util . * ; class GFG { public static int findNonMultiples ( int [ ] arr , int n , int k ) { Set < Integer > multiples = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( ! multiples . contains ( arr [ i ] ) ) { for ( int j = 1 ; j <= k \\/ arr [ i ] ; j ++ ) { multiples . add ( arr [ i ] * j ) ; } } } return k - multiples . size ( ) ; } public static int countValues ( int [ ] arr , int N , int L , int R ) { return findNonMultiples ( arr , N , R ) - findNonMultiples ( arr , N , L - 1 ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 4 , 5 , 6 } ; int N = arr . length ; int L = 1 ; int R = 20 ; System . out . println ( countValues ( arr , N , L , R ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Check whether triangle is valid or not if sides are given | function to check if three sider form a triangle or not ; check condition ; Driver Code ; function calling and print output\\\"\\nSolution in php:\",\"targets\":\"< ? php function checkValidity ( $ a , $ b , $ c ) { if ( $ a + $ b <= $ c $ a + $ c <= $ b $ b + $ c <= $ a ) return false ; else return true ; } $ a = 7 ; $ b = 10 ; $ c = 5 ; if ( checkValidity ( $ a , $ b , $ c ) ) echo \\\" Valid \\\" ; else echo \\\" Invalid \\\" ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Reduce N to 1 with minimum number of given operations | Java implementation of the approach ; Function to return the minimum number of given operations required to reduce n to 1 ; To store the count of operations ; To store the digit ; If n is already then no operation is required ; Extract all the digits except the first digit ; Store the maximum of that digits ; for each digit ; First digit ; Add the value to count ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { static long minOperations ( long n ) { long count = 0 ; long d = 0 ; if ( n == 1 ) return 0 ; while ( n > 9 ) { d = Math . max ( n % 10 , d ) ; n \\/= 10 ; count += 10 ; } d = Math . max ( d , n - 1 ) ; count += Math . abs ( d ) ; return count - 1 ; } public static void main ( String [ ] args ) { long n = 240 ; System . out . println ( minOperations ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-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\\\"\\nHow can the above be solved 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\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Naive algorithm for Pattern Searching | PHP program for Naive Pattern Searching algorithm ; A loop to slide pat [ ] one by one ; For current index i , check for pattern match ; if pat [ 0. . . M - 1 ] = txt [ i , i + 1 , ... i + M - 1 ] ; Driver Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function search ( $ pat , $ txt ) { $ M = strlen ( $ pat ) ; $ N = strlen ( $ txt ) ; for ( $ i = 0 ; $ i <= $ N - $ M ; $ i ++ ) { for ( $ j = 0 ; $ j < $ M ; $ j ++ ) if ( $ txt [ $ i + $ j ] != $ pat [ $ j ] ) break ; if ( $ j == $ M ) echo \\\" Pattern ▁ found ▁ at ▁ index ▁ \\\" , $ i . \\\" \\n \\\" ; } } $ txt = \\\" AABAACAADAABAAABAA \\\" ; $ pat = \\\" AABA \\\" ; search ( $ pat , $ txt ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum steps to reduce N to 0 by given operations | C ++ program for the above approach ; 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 ; Driver Code ; Given number N ; Function call\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int count ( int n ) { map < int , int > dp ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; if ( ( dp . find ( n ) == dp . end ( ) ) ) dp [ n ] = 1 + min ( n % 2 + count ( n \\/ 2 ) , n % 3 + count ( n \\/ 3 ) ) ; return dp [ n ] ; } int main ( ) { int N = 6 ; cout << count ( N ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Level order traversal with direction change after every two levels | A Binary Tree Node ; Function to prthe level order of given binary tree . Direction of printing level order traversal of binary tree changes after every two levels ; For null root ; Maintain a queue for normal level order traversal ; Maintain a stack for printing nodes in reverse order after they are popped out from queue . ; sz is used for storing the count of nodes in a level ; Used for changing the direction of level order traversal ; Used for changing the direction of level order traversal ; Push root node to the queue ; Run this while loop till queue got empty ; Do a normal level order traversal ; For printing nodes from left to right , simply prthe nodes in the order in which they are being popped out from the queue . ; For printing nodes from right to left , push the nodes to stack instead of printing them . ; for printing the nodes in order from right to left ; Change the direction of printing nodes after every two levels . ; Driver program to test above functions ; Let us create binary tree\\\"\\nHow can the above be solved in Python?\",\"targets\":\"from collections import deque\\nclass Node :\\n\\tdef __init__ ( self , x ) :\\n\\t\\tself . data = x\\n\\t\\tself . left = None\\n\\t\\tself . right = None\\ndef modifiedLevelOrder ( node ) :\\n\\tif ( node == None ) :\\n\\t\\treturn\\n\\tif ( node . left == None and node . right == None ) :\\n\\t\\tprint ( node . data , end = \\\" ▁ \\\" )\\n\\t\\treturn\\n\\tmyQueue = deque ( )\\n\\tmyStack = [ ]\\n\\ttemp = None\\n\\tsz = 0\\n\\tct = 0\\n\\trightToLeft = False\\n\\tmyQueue . append ( node )\\n\\twhile ( len ( myQueue ) > 0 ) :\\n\\t\\tct += 1\\n\\t\\tsz = len ( myQueue )\\n\\t\\tfor i in range ( sz ) :\\n\\t\\t\\ttemp = myQueue . popleft ( )\\n\\t\\t\\tif ( rightToLeft == False ) :\\n\\t\\t\\t\\tprint ( temp . data , end = \\\" ▁ \\\" )\\n\\t\\t\\telse :\\n\\t\\t\\t\\tmyStack . append ( temp )\\n\\t\\t\\tif ( temp . left ) :\\n\\t\\t\\t\\tmyQueue . append ( temp . left )\\n\\t\\t\\tif ( temp . right ) :\\n\\t\\t\\t\\tmyQueue . append ( temp . right )\\n\\t\\tif ( rightToLeft == True ) :\\n\\t\\t\\twhile ( len ( myStack ) > 0 ) :\\n\\t\\t\\t\\ttemp = myStack [ - 1 ]\\n\\t\\t\\t\\tdel myStack [ - 1 ]\\n\\t\\t\\t\\tprint ( temp . data , end = \\\" ▁ \\\" )\\n\\t\\tif ( ct == 2 ) :\\n\\t\\t\\trightToLeft = not rightToLeft\\n\\t\\t\\tct = 0\\n\\t\\tprint ( )\\nif __name__ == ' _ _ main _ _ ' :\\n\\troot = Node ( 1 )\\n\\troot . left = Node ( 2 )\\n\\troot . right = Node ( 3 )\\n\\troot . left . left = Node ( 4 )\\n\\troot . left . right = Node ( 5 )\\n\\troot . right . left = Node ( 6 )\\n\\troot . right . right = Node ( 7 )\\n\\troot . left . left . left = Node ( 8 )\\n\\troot . left . left . right = Node ( 9 )\\n\\troot . left . right . left = Node ( 3 )\\n\\troot . left . right . right = Node ( 1 )\\n\\troot . right . left . left = Node ( 4 )\\n\\troot . right . left . right = Node ( 2 )\\n\\troot . right . right . left = Node ( 7 )\\n\\troot . right . right . right = Node ( 2 )\\n\\troot . left . right . left . left = Node ( 16 )\\n\\troot . left . right . left . right = Node ( 17 )\\n\\troot . right . left . right . left = Node ( 18 )\\n\\troot . right . right . left . right = Node ( 19 )\\n\\tmodifiedLevelOrder ( root )\",\"language\":\"python\",\"split\":\"train\",\"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\\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 ▁ missing ▁ element ▁ is ▁ % 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\":\"\\\"Count of valid arrays of size P with elements in range [ 1 , N ] having duplicates at least M distance apart | Java program for the above approach ; Function to calculate the total number of arrays ; If the size of the array is P ; Check if all elements are used atlease once ; Check if this state is already calculated ; Initialize the result ; Use a number from the list of unused numbers ; There are ' unused ' number of favourable choices ; Use a number from already present number atlease M distance back ; There are ' used ▁ - ▁ M ' number of favourable choices ; Store the result ; Function to solve the problem ; Initialize DP table : dp [ i ] [ j ] [ j ] i : current position \\/ index j : number of used elements k : number of unused elements ; Driver Code\\\"\\nSolution in Java:\",\"targets\":\"import java . io . * ; class GFG { static int calculate ( int position , int used , int unused , int P , int M , int dp [ ] [ ] [ ] ) { if ( position == P ) { return unused == 0 ? 1 : 0 ; } if ( dp [ position ] [ used ] [ unused ] != - 1 ) return dp [ position ] [ used ] [ unused ] ; int result = 0 ; if ( unused > 0 ) { result += calculate ( position + 1 , used + 1 , unused - 1 , P , M , dp ) * unused ; } if ( used > M ) { result += calculate ( position + 1 , used , unused , P , M , dp ) * ( used - M ) ; } return dp [ position ] [ used ] [ unused ] = result ; } static int solve ( int N , int P , int M ) { int [ ] [ ] [ ] dp = new int [ 101 ] [ 101 ] [ 101 ] ; for ( int i = 0 ; i < 101 ; i ++ ) { for ( int j = 0 ; j < 101 ; j ++ ) for ( int k = 0 ; k < 101 ; k ++ ) dp [ i ] [ j ] [ k ] = - 1 ; } return calculate ( 0 , 0 , N , P , M , dp ) ; } public static void main ( String [ ] args ) { int N = 2 , M = 0 , P = 3 ; System . out . println ( solve ( N , P , M ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Find Nth item distributed from infinite items of infinite types based on given conditions | C ++ program for the above approach ; 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 C++?\",\"targets\":\"#include \\nusing namespace std ; int itemType ( int n ) { int count = 0 ; for ( int day = 1 ; ; day ++ ) { for ( int type = day ; type > 0 ; type -- ) { count += type ; if ( count >= n ) return type ; } } } int main ( ) { int N = 10 ; cout << itemType ( N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"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 + 1 \\/ 3 ^ 3 + â €¦ . . + 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\":\"\\\"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 JS?\",\"targets\":\"function isPowerOfTwo ( n ) { if ( n == 0 ) return false ; return parseInt ( ( Math . ceil ( ( Math . log ( n ) \\/ Math . log ( 2 ) ) ) ) ) == parseInt ( ( Math . floor ( ( ( Math . log ( n ) \\/ Math . log ( 2 ) ) ) ) ) ) ; } if ( isPowerOfTwo ( 31 ) ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ; if ( isPowerOfTwo ( 64 ) ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Check if a given integer is the product of K consecutive integers | Function to check if N can be expressed as the product of K consecutive integers ; Stores the K - th root of N ; Stores the product of K consecutive integers ; Traverse over the range [ 1 , K ] ; Update the product ; If product is N , then return \\\" Yes \\\" ; Otherwise , traverse over the range [ 2 , Kthroot ] ; Update the value of product ; If product is equal to N ; Otherwise , return \\\" No \\\" ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def checkPro ( n , k ) :\\n\\tKthRoot = int ( n ** ( 1 \\/ k ) )\\n\\tproduct = 1\\n\\tfor i in range ( 1 , k + 1 ) :\\n\\t\\tproduct = product * i\\n\\tprint ( product )\\n\\tif ( product == N ) :\\n\\t\\treturn ( \\\" Yes \\\" )\\n\\tfor i in range ( 2 , KthRoot + 1 ) :\\n\\t\\tproduct = product * ( i + k - 1 )\\n\\t\\tproduct = product \\/ ( i - 1 )\\n\\t\\tprint ( product )\\n\\t\\tif ( product == N ) :\\n\\t\\t\\treturn ( \\\" Yes \\\" )\\n\\treturn ( \\\" No \\\" )\\nN = 210\\nK = 3\\nprint ( checkPro ( N , K ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; 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 = max ( ans , right - left + 1 ) ; } return ans ; } int maxConsecutiveSegment ( string S , int K ) { int N = S . length ( ) ; return max ( maxLength ( S , N , '0' , K ) , maxLength ( S , N , '1' , K ) ) ; } int main ( ) { string S = \\\"1001\\\" ; int K = 1 ; cout << maxConsecutiveSegment ( S , K ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"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\\\"\\nSolution in php:\",\"targets\":\"< ? php function printTetraRec ( $ 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 ) ; } function printTetra ( $ n ) { echo printTetraRec ( $ n ) . \\\" \\\" ; } $ n = 10 ; printTetra ( $ n ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Write a program to calculate pow ( x , n ) | C # program for the above approach ; If x ^ 0 return 1 ; If we need to find of 0 ^ y ; For all other cases ; Driver Code\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { public static int power ( int x , int y ) { if ( y == 0 ) return 1 ; if ( x == 0 ) return 0 ; return x * power ( x , y - 1 ) ; } public static void Main ( String [ ] args ) { int x = 2 ; int y = 3 ; Console . WriteLine ( power ( x , y ) ) ; } }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"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 php:\",\"targets\":\"< ? php function permutationCoeff ( $ n , $ k ) { $ P = array ( array ( ) ) ; for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) { for ( $ j = 0 ; $ j <= 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 ] ; } $ n = 10 ; $ k = 2 ; echo \\\" Value ▁ of ▁ P ( \\\" , $ n , \\\" ▁ , \\\" , $ k , \\\" ) ▁ is ▁ \\\" , permutationCoeff ( $ n , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Recursive Program to print multiplication table of a number | C ++ program to print table of a number using recursion ; Function that print the table of a given number using recursion ; Base Case ; Print the table for current iteration ; Recursive call to next iteration ; Driver Code ; Input number whose table is to print ; Function call to print the table\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void mul_table ( int N , int i ) { if ( i > 10 ) return ; cout << N << \\\" ▁ * ▁ \\\" << i << \\\" ▁ = ▁ \\\" << N * i << endl ; return mul_table ( N , i + 1 ) ; } int main ( ) { int N = 8 ; mul_table ( N , 1 ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Count of total subarrays whose sum is a Fibonacci Numbers | Function to check whether a number is perfect square or not ; Function to check whether a number is fibonacci number or not ; If 5 * n * n + 4 or 5 * n * n - 5 is a perfect square , then the number is Fibonacci ; Function to count the subarray with sum fibonacci number ; Traverse the array arr [ ] to find the sum of each subarray ; To store the sum ; Check whether sum of subarray between [ i , j ] is fibonacci or not ; Driver Code ; Function Call\\\"\\nSolution in Javascript:\",\"targets\":\"function isPerfectSquare ( x ) { var s = parseInt ( Math . sqrt ( x ) ) ; return ( s * s == x ) ; } function isFibonacci ( n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } function fibonacciSubarrays ( arr , n ) { var count = 0 ; for ( var i = 0 ; i < n ; ++ i ) { var sum = 0 ; for ( var j = i ; j < n ; ++ j ) { sum += arr [ j ] ; if ( isFibonacci ( sum ) ) { ++ count ; } } } document . write ( count ) ; } var arr = [ 6 , 7 , 8 , 9 ] ; var n = arr . length ; fibonacciSubarrays ( arr , n ) ;\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-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\":\"\\\"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\\\"\\nHow can the above be solved 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\":\"abovecpp\",\"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\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; bool 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 ) { cout << \\\" Pair ▁ Found : ▁ ( \\\" << arr [ i ] << \\\" , ▁ \\\" << arr [ j ] << \\\" ) \\\" ; return true ; } else if ( arr [ j ] - arr [ i ] < n ) j ++ ; else i ++ ; } cout << \\\" No ▁ such ▁ 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\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Check whether given string can be generated after concatenating given strings | 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 JS?\",\"targets\":\"function startsWith ( str , pre ) { let strLen = str . length ; let preLen = pre . length ; let i = 0 , j = 0 ; while ( i < strLen && j < preLen ) { if ( str [ i ] != pre [ j ] ) return false ; i ++ ; j ++ ; } return true ; } function endsWith ( str , suff ) { let i = str . length - 1 ; let j = suff . length - 1 ; while ( i >= 0 && j >= 0 ) { if ( str [ i ] != suff [ j ] ) return false ; i -- ; j -- ; } return true ; } function checkString ( str , a , 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 ; } let str = \\\" \\\" ; let a = \\\" \\\" ; let b = \\\" \\\" ; if ( checkString ( str , a , b ) ) document . write ( \\\" \\\" ) ; else document . write ( \\\" \\\" ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Search , insert and delete in a sorted array | C program to implement binary search in sorted array ; function to implement binary search ; low + ( high - low ) \\/ 2 ; ; Driver Code Let us search 3 in below array\\\"\\nSolution in C:\",\"targets\":\"#include \\nint binarySearch ( int arr [ ] , int low , int high , int key ) { if ( high < low ) return -1 ; int mid = ( low + high ) \\/ 2 ; if ( key == arr [ mid ] ) return mid ; if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ; return binarySearch ( arr , low , ( mid - 1 ) , key ) ; } int main ( ) { int arr [ ] = { 5 , 6 , 7 , 8 , 9 , 10 } ; int n , key ; n = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; key = 10 ; printf ( \\\" Index : ▁ % d \\n \\\" , binarySearch ( arr , 0 , n - 1 , key ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Queries to find the minimum array sum possible by removing elements from either end | C # program for the above approach ; Function to find the minimum sum for each query after removing elements from either ends ; Traverse the query array ; Traverse the array from the front ; If element equals val , then break out of loop ; Traverse the array from rear ; If element equals val , break ; Print the minimum of the two as the answer ; Driver Code ; Function Call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; class GFG { static void minSum ( int [ ] arr , int N , int [ ] Q , int M ) { for ( int i = 0 ; i < M ; i ++ ) { int val = Q [ i ] ; int front = 0 , rear = 0 ; for ( int j = 0 ; j < N ; j ++ ) { front += arr [ j ] ; if ( arr [ j ] == val ) { break ; } } for ( int j = N - 1 ; j >= 0 ; j -- ) { rear += arr [ j ] ; if ( arr [ j ] == val ) { break ; } } Console . Write ( Math . Min ( front , rear ) + \\\" ▁ \\\" ) ; } } static public void Main ( ) { int [ ] arr = { 2 , 3 , 6 , 7 , 4 , 5 , 1 } ; int N = arr . Length ; int [ ] Q = { 7 , 6 } ; int M = Q . Length ; minSum ( arr , N , Q , M ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Number of paths with exactly k coins | A Dynamic Programming based C ++ program to count paths with exactly ' k ' coins ; Base cases ; If this subproblem is already solved ; ( m , n ) can be reached either through ( m - 1 , n ) or through ( m , n - 1 ) ; This function mainly initializes dp [ ] [ ] [ ] and calls pathCountDPRecDP ( ) ; Driver Program to test above functions\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\n#define R 3\\n#define C 3\\n#define MAX_K 1000\\nusing namespace std ; int dp [ R ] [ C ] [ MAX_K ] ; int pathCountDPRecDP ( int mat [ ] [ C ] , int m , int n , int k ) { if ( m < 0 n < 0 ) return 0 ; if ( m == 0 && n == 0 ) return ( k == mat [ m ] [ n ] ) ; if ( dp [ m ] [ n ] [ k ] != -1 ) return dp [ m ] [ n ] [ k ] ; dp [ m ] [ n ] [ k ] = pathCountDPRecDP ( mat , m - 1 , n , k - mat [ m ] [ n ] ) + pathCountDPRecDP ( mat , m , n - 1 , k - mat [ m ] [ n ] ) ; return dp [ m ] [ n ] [ k ] ; } int pathCountDP ( int mat [ ] [ C ] , int k ) { memset ( dp , -1 , sizeof dp ) ; return pathCountDPRecDP ( mat , R - 1 , C - 1 , k ) ; } int main ( ) { int k = 12 ; int mat [ R ] [ C ] = { { 1 , 2 , 3 } , { 4 , 6 , 5 } , { 3 , 2 , 1 } } ; cout << pathCountDP ( mat , k ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovecpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-program-level\"}\n" "{\"inputs\":\"\\\"Number of coloured 0 's in an N | Java implementation of the approach ; Function to return the count of coloured 0 s in an n - level hexagon ; Driver code\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static int count ( int n ) { return n * ( 3 * n - 1 ) \\/ 2 ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( count ( n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Count prime numbers up to N that can be represented as a sum of two prime numbers | C # program for the above approach ; Function to store all prime numbers up to N using Sieve of Eratosthenes ; Set 0 and 1 as non - prime ; If p is prime ; Set all multiples of p as non - prime ; Function to count prime numbers up to N that can be represented as the sum of two prime numbers ; Stores all the prime numbers ; Update the prime array ; Create a dp array of size n + 1 ; Update dp [ 1 ] = 0 ; Iterate over the range [ 2 , N ] ; Add the previous count value ; Increment dp [ i ] by 1 if i and ( i - 2 ) are both prime ; Print the result ; Driver code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class GFG { static void SieveOfEratosthenes ( int n , bool [ ] prime ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) { prime [ i ] = false ; } } } } static void countPrime ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < prime . Length ; i ++ ) { prime [ i ] = true ; } SieveOfEratosthenes ( n , prime ) ; int [ ] dp = new int [ n + 1 ] ; for ( int i = 0 ; i < dp . Length ; i ++ ) { dp [ i ] = 0 ; } dp [ 1 ] = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { dp [ i ] += dp [ i - 1 ] ; if ( prime [ i ] == true && prime [ i - 2 ] == true ) { dp [ i ] ++ ; } } Console . Write ( dp [ n ] ) ; } static void Main ( ) { int N = 6 ; countPrime ( N ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Count all unique outcomes possible by performing S flips on N coins | Function to recursively count the number of unique outcomes possible S flips are performed on N coins ; Base Cases ; Recursive Calls ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function numberOfUniqueOutcomes ( N , S ) { if ( S < N ) return 0 ; if ( N == 1 N == S ) return 1 ; return ( numberOfUniqueOutcomes ( N - 1 , S - 1 ) + numberOfUniqueOutcomes ( N - 1 , S - 2 ) ) ; } let N = 3 , S = 4 ; document . write ( numberOfUniqueOutcomes ( N , S ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Given two strings check which string makes a palindrome first | C # program to check which string makes palindrome first . ; returns winner of two strings ; Count frequencies of characters in both given strings ; Check if there is a character that appears more than once in A and does not appear in B ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; class First_Palin { static int MAX_CHAR = 26 ; static char stringPalindrome ( string A , string B ) { int [ ] countA = new int [ MAX_CHAR ] ; int [ ] countB = new int [ MAX_CHAR ] ; int l1 = A . Length ; int l2 = B . Length ; for ( int i = 0 ; i < l1 ; i ++ ) countA [ A [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < l2 ; i ++ ) countB [ B [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) if ( ( countA [ i ] > 1 && countB [ i ] == 0 ) ) return ' A ' ; return ' B ' ; } public static void Main ( ) { string a = \\\" abcdea \\\" ; string b = \\\" bcdesg \\\" ; Console . WriteLine ( stringPalindrome ( a , b ) ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Smallest element in an array that is repeated exactly ' k ' times . | PHP program to find smallest number in array that is repeated exactly ' k ' times . ; Computing frequencies of all elements ; Finding the smallest element with frequency as k ; If frequency of any of the number is equal to k starting from 0 then return the number ; Driver code\\\"\\nSolution in php:\",\"targets\":\"< ? php $ MAX = 1000 ; function findDuplicate ( $ arr , $ n , $ k ) { global $ MAX ; $ freq = array_fill ( 0 , $ MAX , 0 ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] < 1 && $ arr [ $ i ] > $ MAX ) { echo \\\" Out ▁ of ▁ range \\\" ; return -1 ; } $ freq [ $ arr [ $ i ] ] += 1 ; } for ( $ i = 0 ; $ i < $ MAX ; $ i ++ ) { if ( $ freq [ $ i ] == $ k ) return $ i ; } return -1 ; } $ arr = array ( 2 , 2 , 1 , 3 , 1 ) ; $ k = 2 ; $ n = count ( $ arr ) ; echo findDuplicate ( $ arr , $ n , $ k ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Minimum number with digits as 4 and 7 only and given sum | Prints minimum number with given digit sum and only allowed digits as 4 and 7. ; Cases where all remaining digits are 4 or 7 ( Remaining sum of digits should be multiple of 4 or 7 ) ; If both 4 s and 7 s are there in digit sum , we subtract a 4. ; Driver code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function findMin ( $ sum ) { $ a = 0 ; $ b = 0 ; while ( $ sum > 0 ) { if ( $ sum % 7 == 0 ) { $ b ++ ; $ sum -= 7 ; } else if ( $ sum % 4 == 0 ) { $ a ++ ; $ sum -= 4 ; } else { $ a ++ ; $ sum -= 4 ; } } if ( $ sum < 0 ) { echo ( \\\" - 1n \\\" ) ; return ; } for ( $ i = 0 ; $ i < $ a ; $ i ++ ) echo ( \\\"4\\\" ) ; for ( $ i = 0 ; $ i < $ b ; $ i ++ ) echo ( \\\"7\\\" ) ; echo ( \\\" \\n \\\" ) ; } findMin ( 15 ) ; ? >\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Split a Binary String such that count of 0 s and 1 s in left and right substrings is maximum | C ++ program to implement the above approach ; Function to find the maximum sum of count of 0 s in the left substring and count of 1 s in the right substring by splitting the string ; Stores count of 1 s the in binary string ; Traverse the binary string ; If current character is '1' ; Update cntOne ; Stores count of 0 s ; Stores count of 1 s ; Stores maximum sum of count of 0 s and 1 s by splitting the string ; Traverse the binary string ; If current character is '0' ; Update zero ; If current character is '1' ; Update one ; Update res ; Driver Code\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; int maxSumbySplittingstring ( string str , int N ) { int cntOne = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == '1' ) { cntOne ++ ; } } int zero = 0 ; int one = 0 ; int res = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( str [ i ] == '0' ) { zero ++ ; } else { one ++ ; } res = max ( res , zero + cntOne - one ) ; } return res ; } int main ( ) { string str = \\\"00111\\\" ; int N = str . length ( ) ; cout << maxSumbySplittingstring ( str , N ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"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 .\\nHow can the above be solved in C?\",\"targets\":\"#include \\n#include \\nint isPowerOf2 ( char * str ) { int len_str = strlen ( str ) ; 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 ; for ( int i = 0 , j = 0 ; i < len_str ; i ++ ) { num = num * 10 + str [ i ] - '0' ; if ( num < 2 ) { if ( i != 0 ) str [ j ++ ] = '0' ; continue ; } str [ j ++ ] = ( int ) ( num \\/ 2 ) + '0' ; num = ( num ) - ( num \\/ 2 ) * 2 ; } str [ j ] = ' \\\\0' ; len_str = j ; } return 1 ; } int main ( ) { char str1 [ ] = \\\"12468462246684202468024\\\" \\\"6842024662202000002\\\" ; char str2 [ ] = \\\"1\\\" ; char str3 [ ] = \\\"128\\\" ; printf ( \\\" % d % d % d \\\" , isPowerOf2 ( str1 ) , isPowerOf2 ( str2 ) , isPowerOf2 ( str3 ) ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Maximum frequency of a remainder modulo 2 i | C ++ implementation of the approach ; 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\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; const string bin [ ] = { \\\"000\\\" , \\\"001\\\" , \\\"010\\\" , \\\"011\\\" , \\\"100\\\" , \\\"101\\\" , \\\"110\\\" , \\\"111\\\" } ; int maxFreq ( string s ) { string binary = \\\" \\\" ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { binary += bin [ s [ i ] - '0' ] ; } binary = binary . substr ( 0 , binary . length ( ) - 1 ) ; int count = 1 , prev = -1 , i , j = 0 ; for ( i = binary . length ( ) - 1 ; i >= 0 ; i -- , j ++ ) if ( binary [ i ] == '1' ) { count = max ( count , j - prev ) ; prev = j ; } return count ; } int main ( ) { string octal = \\\"13\\\" ; cout << maxFreq ( octal ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solcpp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C++-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 Dynamic Programming approach ; Function to find the maximum subset sum ; sum of all elements ; bottom up lookup table ; ; initialising dp table with INT_MIN where , INT_MIN means no solution ; Case when diff is 0 ; Putting ith element in g0 ; Putting ith element in g1 ; Ignoring ith element ; Driver code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"class GFG { final static int INT_MIN = Integer . MIN_VALUE ; static int maxSum ( int a [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; int limit = 2 * sum + 1 ; int dp [ ] [ ] = new int [ n + 1 ] [ limit ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < limit ; j ++ ) dp [ i ] [ j ] = INT_MIN ; } dp [ 0 ] [ sum ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 0 ; j < limit ; j ++ ) { if ( ( j - a [ i - 1 ] ) >= 0 && dp [ i - 1 ] [ j - a [ i - 1 ] ] != INT_MIN ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j - a [ i - 1 ] ] + a [ i - 1 ] ) ; if ( ( j + a [ i - 1 ] ) < limit && dp [ i - 1 ] [ j + a [ i - 1 ] ] != INT_MIN ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j + a [ i - 1 ] ] ) ; if ( dp [ i - 1 ] [ j ] != INT_MIN ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j ] ) ; } } return dp [ n ] [ sum ] ; } public static void main ( String [ ] args ) { int n = 4 ; int [ ] a = { 1 , 2 , 3 , 6 } ; System . out . println ( maxSum ( a , n ) ) ; } }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"k | 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 Code\\\"\\nHow can the above be solved in PHP?\",\"targets\":\"< ? php function kPrimeFactor ( $ n , $ k ) { while ( $ n % 2 == 0 ) { $ k -- ; $ n = $ n \\/ 2 ; if ( $ k == 0 ) return 2 ; } for ( $ i = 3 ; $ i <= sqrt ( $ n ) ; $ i = $ i + 2 ) { while ( $ n % $ i == 0 ) { if ( $ k == 1 ) return $ i ; $ k -- ; $ n = $ n \\/ $ i ; } } if ( $ n > 2 && $ k == 1 ) return $ n ; return -1 ; } { $ n = 12 ; $ k = 3 ; echo kPrimeFactor ( $ n , $ k ) , \\\" \\n \\\" ; $ n = 14 ; $ k = 3 ; echo kPrimeFactor ( $ n , $ k ) ; return 0 ; } ? >\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovephp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Program for addition of two matrices | ; This function adds A [ ] [ ] and B [ ] [ ] , and stores the result in C [ ] [ ] ; Driver code\\\"\\nSolution in C:\",\"targets\":\"#include \\n#define N 4\\nvoid add ( 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 ; add ( A , B , C ) ; printf ( \\\" Result ▁ matrix ▁ is ▁ \\n \\\" ) ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) printf ( \\\" % d ▁ \\\" , 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\":\"\\\"Rearrange and update array elements as specified by the given queries | C ++ program to implement the above approach ; Function to perform the given operations ; Dequeue to store the array elements ; Insert all element of the array into the dequeue ; Stores the size of the queue ; Traverse each query ; Query for left shift . ; Extract the element at the front of the queue ; Pop the element at the front of the queue ; Push the element at the back of the queue ; Query for right shift ; Extract the element at the back of the queue ; Pop the element at the back of the queue ; Push the element at the front of the queue ; Query for update ; Query to get the value ; Driver Code ; All possible Queries\\\"\\nSolution in C++:\",\"targets\":\"#include \\nusing namespace std ; void Queries ( int arr [ ] , int N , vector < vector < int > > & Q ) { deque < int > dq ; for ( int i = 0 ; i < N ; i ++ ) { dq . push_back ( arr [ i ] ) ; } int sz = Q . size ( ) ; for ( int i = 0 ; i < sz ; i ++ ) { if ( Q [ i ] [ 0 ] == 0 ) { int front = dq [ 0 ] ; dq . pop_front ( ) ; dq . push_back ( front ) ; } else if ( Q [ i ] [ 0 ] == 1 ) { int back = dq [ N - 1 ] ; dq . pop_back ( ) ; dq . push_front ( back ) ; } else if ( Q [ i ] [ 0 ] == 2 ) { dq [ Q [ i ] [ 1 ] ] = Q [ i ] [ 2 ] ; } else { cout << dq [ Q [ i ] [ 1 ] ] << \\\" ▁ \\\" ; } } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int N = sizeof ( arr ) \\/ sizeof ( arr [ 0 ] ) ; vector < vector < int > > Q ; Q = { { 0 } , { 1 } , { 3 , 1 } , { 2 , 2 , 54 } , { 3 , 2 } } ; Queries ( arr , N , Q ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcpp\",\"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 ▁ for ▁ Geeks \\\" ; reverse ( a ) ; return 0 ; }\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solc\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Add two numbers without using arithmetic operators | PHP 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 PHP?\",\"targets\":\"< ? php function Add ( $ x , $ y ) { while ( $ y != 0 ) { $ carry = $ x & $ y ; $ x = $ x ^ $ y ; $ y = $ carry << 1 ; } return $ x ; } echo Add ( 15 , 32 ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"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\\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 ▁ of ▁ % d ▁ is ▁ % d \\n \\\" , key , p ) ; key = 50 ; p = ternarySearch ( l , r , key , ar ) ; printf ( \\\" Index ▁ of ▁ % d ▁ is ▁ % d \\\" , key , p ) ; }\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-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\\\"\\nSolution 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 = \\\" , ▁ $ A , ▁ \\\" B = \\\" } $ arr = array ( 1 , 2 , 2 , 3 , 4 ) ; $ n = sizeof ( $ arr ) ; findNumbers ( $ arr , $ n ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Counting pairs when a person can form pair with at most one | Python program to find Number of ways in which participant can take part . ; Driver code\\\"\\nHow can the above be solved in Python?\",\"targets\":\"def numberOfWays ( x ) :\\n\\tdp = [ ]\\n\\tdp . append ( 1 )\\n\\tdp . append ( 1 )\\n\\tfor i in range ( 2 , x + 1 ) :\\n\\t\\tdp . append ( dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] )\\n\\treturn ( dp [ x ] )\\nx = 3\\nprint ( numberOfWays ( x ) )\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovepy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Sentinel Linear Search | Python3 implementation of the approach Function to search key in the given array ; 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 Python:\",\"targets\":\"def sentinelSearch ( arr , n , key ) :\\ndef sentinelSearch ( arr , n , key ) :\\n\\tlast = arr [ n - 1 ]\\n\\tarr [ n - 1 ] = key\\n\\ti = 0\\n\\twhile ( arr [ i ] != key ) :\\n\\t\\ti += 1\\n\\tarr [ n - 1 ] = last\\n\\tif ( ( i < n - 1 ) or ( arr [ n - 1 ] == key ) ) :\\n\\t\\tprint ( key , \\\" is ▁ present ▁ at ▁ index \\\" , i )\\n\\telse :\\n\\t\\tprint ( \\\" Element ▁ Not ▁ found \\\" )\\narr = [ 10 , 20 , 180 , 30 , 60 , 50 , 110 , 100 , 70 ]\\nn = len ( arr )\\nkey = 180\\nsentinelSearch ( arr , n , key )\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-program-level\"}\n" "{\"inputs\":\"\\\"Queries to find the minimum array sum possible by removing elements from either end | C # program for the above approach ; Function to find the minimum sum for each query after removing element from either ends till each value Q [ i ] ; Stores the prefix sum from both the ends of the array ; Traverse the array from front ; Insert it into the map m1 ; Traverse the array in reverse ; Insert it into the map m2 ; Traverse the query array ; Print the minimum of the two values as the answer ; Driver Code ; Function Call\\\"\\nHow can the above be solved in C-Sharp?\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static void minOperations ( int [ ] arr , int N , int [ ] Q , int M ) { Dictionary < int , int > m1 = new Dictionary < int , int > ( ) ; Dictionary < int , int > m2 = new Dictionary < int , int > ( ) ; int front = 0 , rear = 0 ; for ( int i = 0 ; i < N ; i ++ ) { front += arr [ i ] ; m1 [ arr [ i ] ] = front ; } for ( int i = N - 1 ; i >= 0 ; i -- ) { rear += arr [ i ] ; m2 [ arr [ i ] ] = rear ; } for ( int i = 0 ; i < M ; i ++ ) { Console . Write ( Math . Min ( m1 [ Q [ i ] ] , m2 [ Q [ i ] ] ) + \\\" ▁ \\\" ) ; } } public static void Main ( ) { int [ ] arr = { 2 , 3 , 6 , 7 , 4 , 5 , 1 } ; int N = arr . Length ; int [ ] Q = { 7 , 6 } ; int M = Q . Length ; minOperations ( arr , N , Q , M ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovecsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Sieve of Sundaram to print all primes smaller than n | Prints all prime numbers smaller ; In general Sieve of Sundaram , produces primes smaller than ( 2 * x + 2 ) for a number given number x . Since we want primes smaller than n , we reduce n to half ; This array is used to separate numbers of the form i + j + 2 ij from others where 1 <= i <= j Initialize all elements as not marked ; Main logic of Sundaram . Mark all numbers of the form i + j + 2 ij as true where 1 <= i <= j ; Since 2 is a prime number ; Print other primes . Remaining primes are of the form 2 * i + 1 such that marked [ i ] is false . ; Driver Code\\\"\\nSolution in Python:\",\"targets\":\"def SieveOfSundaram ( n ) :\\n\\tnNew = int ( ( n - 1 ) \\/ 2 ) ;\\n\\tmarked = [ 0 ] * ( nNew + 1 ) ;\\n\\tfor i in range ( 1 , nNew + 1 ) :\\n\\t\\tj = i ;\\n\\t\\twhile ( ( i + j + 2 * i * j ) <= nNew ) :\\n\\t\\t\\tmarked [ i + j + 2 * i * j ] = 1 ;\\n\\t\\t\\tj += 1 ;\\n\\tif ( n > 2 ) :\\n\\t\\tprint ( 2 , end = \\\" ▁ \\\" ) ;\\n\\tfor i in range ( 1 , nNew + 1 ) :\\n\\t\\tif ( marked [ i ] == 0 ) :\\n\\t\\t\\tprint ( ( 2 * i + 1 ) , end = \\\" ▁ \\\" ) ;\\nn = 20 ;\\nSieveOfSundaram ( n ) ;\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solpy\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Python-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\\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\":\"validation\",\"template\":\"abovec\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"C-program-level\"}\n" "{\"inputs\":\"\\\"Ordered Prime Signature | C # to find total number of divisors of a number , using ordered prime signature ; 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 ; Finding ordered prime signature of the number ; Map to store prime factors and the related exponents ; Declaring an iterator for map ; Finding prime factorization of the number ; Storing the prime factor and its exponent in map ; Storing the exponent in a List ; Sorting the stored exponents ; Printing the prime signature ; Finding total number of divisors of the number ; Adding one to each element present ; in ordered prime signature ; Multiplying the elements ; Driver Code\\\"\\nSolution in C#:\",\"targets\":\"using System ; using System . Collections . Generic ; class GFG { static List < int > primes ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) prime [ i ] = true ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( prime [ i ] == true ) { for ( int j = i * 2 ; j <= n ; j += i ) prime [ j ] = false ; } } List < int > arr = new List < int > ( ) ; for ( int i = 2 ; i <= n ; i ++ ) { if ( prime [ i ] ) arr . Add ( i ) ; } return arr ; } static List < int > signature ( int n ) { List < int > r = primes ( n ) ; var factor = new Dictionary < int , int > ( ) ; List < int > sort_exp = new List < int > ( ) ; int k , t = n ; for ( int i = 0 ; i < r . Count ; i ++ ) { if ( n % r [ i ] == 0 ) { k = 0 ; while ( n % r [ i ] == 0 ) { n = n \\/ r [ i ] ; k ++ ; } factor . Add ( r [ i ] , k ) ; sort_exp . Add ( k ) ; } } sort_exp . Sort ( ) ; Console . Write ( \\\" ▁ The ▁ Ordered ▁ Prime ▁ Signature ▁ of ▁ \\\" + t + \\\" ▁ is ▁ : ▁ \\n { ▁ \\\" ) ; for ( int i = 0 ; i < sort_exp . Count ; i ++ ) { if ( i != sort_exp . Count - 1 ) Console . Write ( sort_exp [ i ] + \\\" , ▁ \\\" ) ; else Console . Write ( sort_exp [ i ] + \\\" ▁ } \\n \\\" ) ; } return sort_exp ; } static void divisors ( int n ) { int f = 1 , l ; List < int > div = signature ( n ) ; l = div . Count ; for ( int i = 0 ; i < l ; i ++ ) { div [ i ] += 1 ; f *= div [ i ] ; } Console . Write ( \\\" The ▁ total ▁ number ▁ of ▁ divisors ▁ of ▁ \\\" + n + \\\" ▁ is ▁ \\\" + f + \\\" \\n \\\" ) ; } static void Main ( ) { int n = 13 ; divisors ( n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"solcsharp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Csharp-program-level\"}\n" "{\"inputs\":\"\\\"Maximum sum in circular array such that no two elements are adjacent | CPP program to find maximum sum in a circular array such that no elements are adjacent in the sum . ; Function to calculate the sum from 0 th position to ( n - 2 ) th position ; copy the element of original array to dp [ ] ; find the maximum element in the array ; start from 2 nd to n - 1 th pos ; traverse for all pairs bottom - up approach ; dp - condition ; find maximum sum ; return the maximum ; Function to find the maximum sum from 1 st position to n - 1 - th position ; Traverse from third to n - th pos ; bootom - up approach ; dp condition ; find max sum ; return max ; Driver Code\\\"\\nHow can the above be solved in C++?\",\"targets\":\"#include \\nusing namespace std ; int maxSum1 ( int arr [ ] , int n ) { int dp [ n ] ; int maxi = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { dp [ i ] = arr [ i ] ; if ( maxi < arr [ i ] ) maxi = arr [ i ] ; } for ( int i = 2 ; i < n - 1 ; i ++ ) { for ( int j = 0 ; j < i - 1 ; j ++ ) { if ( dp [ i ] < dp [ j ] + arr [ i ] ) { dp [ i ] = dp [ j ] + arr [ i ] ; if ( maxi < dp [ i ] ) maxi = dp [ i ] ; } } } return maxi ; } int maxSum2 ( int arr [ ] , int n ) { int dp [ n ] ; int maxi = 0 ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] = arr [ i ] ; if ( maxi < arr [ i ] ) maxi = arr [ i ] ; } for ( int i = 3 ; i < n ; i ++ ) { for ( int j = 1 ; j < i - 1 ; j ++ ) { if ( dp [ i ] < arr [ i ] + dp [ j ] ) { dp [ i ] = arr [ i ] + dp [ j ] ; if ( maxi < dp [ i ] ) maxi = dp [ i ] ; } } } return maxi ; } int findMaxSum ( int arr [ ] , int n ) { return max ( maxSum1 ( arr , n ) , maxSum2 ( arr , n ) ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 1 } ; 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\":\"\\\"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\":\"\\\"Check if permutation of first N natural numbers exists having Bitwise AND of adjacent elements non | Java Program to implement the above approach ; Function to check if a permutation of first N natural numbers exist with Bitwise AND of adjacent elements not equal to 0 ; If n is a power of 2 ; Driver Code\\\"\\nHow can the above be solved in Java?\",\"targets\":\"import java . util . * ; class solution { static void check ( int n ) { if ( ( n & n - 1 ) != 0 ) System . out . println ( \\\" YES \\\" ) ; else System . out . println ( \\\" NO \\\" ) ; } public static void main ( String args [ ] ) { int n = 5 ; check ( n ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"abovejava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n" "{\"inputs\":\"\\\"Side of a regular n | Function to calculate the side of the polygon circumscribed in a circle ; Total sides of the polygon ; Radius of the circumscribing circle\\\"\\nSolution in php:\",\"targets\":\"< ? php function calculateSide ( $ n , $ r ) { $ theta ; $ theta_in_radians ; $ theta = 360 \\/ $ n ; $ theta_in_radians = $ theta * 3.14 \\/ 180 ; return 2 * $ r * sin ( $ theta_in_radians \\/ 2 ) ; } $ n = 3 ; $ r = 5 ; echo calculateSide ( $ n , $ r ) ; ? >\",\"language\":\"python\",\"split\":\"test\",\"template\":\"solphp\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"PHP-program-level\"}\n" "{\"inputs\":\"\\\"Maximum number of operations required such that no pairs from a Matrix overlap | Function to find maximum count of operations ; Initialize count by 0 ; Iterate over remaining pairs ; Check if first operation is applicable ; Check if 2 nd operation is applicable ; Otherwise ; Return the count of operations ; Driver Code\\\"\\nHow can the above be solved in JS?\",\"targets\":\"function find_max ( v , n ) { let count = 0 ; if ( n >= 2 ) count = 2 ; else count = 1 ; for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( v [ i - 1 ] [ 0 ] < ( v [ i ] [ 0 ] - v [ i ] [ 1 ] ) ) count ++ ; else if ( v [ i + 1 ] [ 0 ] > ( v [ i ] [ 0 ] + v [ i ] [ 1 ] ) ) { count ++ ; v [ i ] [ 0 ] = v [ i ] [ 0 ] + v [ i ] [ 1 ] ; } else continue ; } return count ; } let n = 3 ; let v = [ [ 10 , 20 ] , [ 15 , 10 ] , [ 20 , 16 ] ] ; document . write ( find_max ( v , n ) ) ;\",\"language\":\"python\",\"split\":\"validation\",\"template\":\"abovejs\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Javascript-program-level\"}\n" "{\"inputs\":\"\\\"Program To Check whether a Triangle is Equilateral , Isosceles or Scalene | Java program for the above approach ; Function to check if the triangle is equilateral or isosceles or scalene ; Check for equilateral triangle ; Check for isosceles triangle ; Otherwise scalene triangle ; Driver Code ; Given sides of triangle ; Function call\\\"\\nSolution in Java:\",\"targets\":\"class GFG { static void checkTriangle ( int x , int y , int z ) { if ( x == y && y == z ) System . out . println ( \\\" Equilateral ▁ Triangle \\\" ) ; else if ( x == y y == z z == x ) System . out . println ( \\\" Isosceles ▁ Triangle \\\" ) ; else System . out . println ( \\\" Scalene ▁ Triangle \\\" ) ; } public static void main ( String [ ] args ) { int x = 8 , y = 7 , z = 9 ; checkTriangle ( x , y , z ) ; } }\",\"language\":\"python\",\"split\":\"train\",\"template\":\"soljava\",\"dataset\":\"codeparrot\\/xlcost-text-to-code\",\"config\":\"Java-program-level\"}\n"